@passlock/client 0.9.23 → 0.9.24
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 +10 -5
- package/README.template.md +130 -0
- package/dist/authentication/authenticate.d.ts +2 -2
- package/dist/authentication/authenticate.fixture.d.ts +1 -1
- package/dist/authentication/authenticate.fixture.js +2 -2
- package/dist/authentication/authenticate.fixture.js.map +1 -1
- package/dist/authentication/authenticate.js +1 -1
- package/dist/authentication/authenticate.js.map +1 -1
- package/dist/capabilities/capabilities.d.ts +1 -1
- package/dist/capabilities/capabilities.js +1 -1
- package/dist/capabilities/capabilities.js.map +1 -1
- package/dist/connection/connection.fixture.d.ts +1 -1
- package/dist/connection/connection.fixture.js +1 -1
- package/dist/connection/connection.fixture.js.map +1 -1
- package/dist/connection/connection.js.map +1 -1
- package/dist/effect.d.ts +3 -3
- package/dist/effect.js +6 -6
- package/dist/effect.js.map +1 -1
- package/dist/email/email.d.ts +5 -2
- package/dist/email/email.fixture.d.ts +1 -1
- package/dist/email/email.fixture.js +2 -2
- package/dist/email/email.fixture.js.map +1 -1
- package/dist/email/email.js +1 -1
- package/dist/email/email.js.map +1 -1
- package/dist/event/event.d.ts +1 -1
- package/dist/event/event.js +1 -1
- package/dist/event/event.js.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/logging/eventLogger.js +1 -1
- package/dist/logging/eventLogger.js.map +1 -1
- package/dist/registration/register.d.ts +2 -2
- package/dist/registration/register.fixture.d.ts +1 -1
- package/dist/registration/register.fixture.js +2 -2
- package/dist/registration/register.fixture.js.map +1 -1
- package/dist/registration/register.js +2 -2
- package/dist/registration/register.js.map +1 -1
- package/dist/rpc/authentication.d.ts +1 -1
- package/dist/rpc/authentication.js +1 -1
- package/dist/rpc/authentication.js.map +1 -1
- package/dist/rpc/client.d.ts +1 -1
- package/dist/rpc/client.js +3 -4
- package/dist/rpc/client.js.map +1 -1
- package/dist/rpc/connection.d.ts +1 -1
- package/dist/rpc/connection.js +1 -1
- package/dist/rpc/connection.js.map +1 -1
- package/dist/rpc/registration.d.ts +1 -1
- package/dist/rpc/registration.js +1 -1
- package/dist/rpc/registration.js.map +1 -1
- package/dist/rpc/social.d.ts +1 -1
- package/dist/rpc/social.js +1 -1
- package/dist/rpc/social.js.map +1 -1
- package/dist/rpc/user.d.ts +1 -1
- package/dist/rpc/user.js +1 -1
- package/dist/rpc/user.js.map +1 -1
- package/dist/social/social.d.ts +2 -2
- package/dist/social/social.fixture.d.ts +1 -1
- package/dist/social/social.fixture.js +2 -2
- package/dist/social/social.fixture.js.map +1 -1
- package/dist/social/social.js +2 -2
- package/dist/social/social.js.map +1 -1
- package/dist/storage/storage.d.ts +1 -1
- package/dist/storage/storage.fixture.js.map +1 -1
- package/dist/storage/storage.js +4 -0
- package/dist/storage/storage.js.map +1 -1
- package/dist/test/fixtures.d.ts +1 -1
- package/dist/test/fixtures.js +2 -2
- package/dist/test/fixtures.js.map +1 -1
- package/dist/user/user.d.ts +1 -1
- package/dist/user/user.fixture.d.ts +1 -1
- package/dist/user/user.fixture.js +2 -2
- package/dist/user/user.fixture.js.map +1 -1
- package/dist/user/user.js +4 -1
- package/dist/user/user.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +20 -16
- package/src/authentication/authenticate.fixture.ts +4 -2
- package/src/authentication/authenticate.test.ts +2 -1
- package/src/authentication/authenticate.ts +3 -1
- package/src/capabilities/capabilities.ts +2 -1
- package/src/connection/connection.fixture.ts +3 -1
- package/src/connection/connection.test.ts +2 -1
- package/src/connection/connection.ts +1 -0
- package/src/effect.ts +12 -18
- package/src/email/email.fixture.ts +4 -2
- package/src/email/email.test.ts +2 -1
- package/src/email/email.ts +3 -1
- package/src/event/event.node.test.ts +1 -0
- package/src/event/event.test.ts +1 -0
- package/src/event/event.ts +2 -1
- package/src/index.ts +39 -33
- package/src/logging/eventLogger.test.ts +1 -0
- package/src/logging/eventLogger.ts +1 -1
- package/src/registration/register.fixture.ts +4 -2
- package/src/registration/register.test.ts +4 -2
- package/src/registration/register.ts +4 -5
- package/src/rpc/authentication.ts +14 -2
- package/src/rpc/client.ts +5 -4
- package/src/rpc/connection.ts +8 -2
- package/src/rpc/registration.ts +12 -2
- package/src/rpc/social.ts +11 -2
- package/src/rpc/user.ts +16 -1
- package/src/social/social.fixture.ts +4 -2
- package/src/social/social.test.ts +4 -2
- package/src/social/social.ts +4 -2
- package/src/storage/storage.fixture.ts +1 -0
- package/src/storage/storage.test.ts +1 -0
- package/src/storage/storage.ts +4 -3
- package/src/test/fixtures.ts +4 -2
- package/src/user/user.fixture.ts +4 -2
- package/src/user/user.test.ts +2 -1
- package/src/user/user.ts +3 -1
- package/src/version.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@passlock/client",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.24",
|
|
4
4
|
"description": "Passkey authentication and social login for web apps (Typescript). Framework agnostic",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"passkey",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"homepage": "https://passlock.dev",
|
|
25
25
|
"repository": {
|
|
26
26
|
"type": "git",
|
|
27
|
-
"url": "git+https://github.com/passlock-dev/ts-clients.git"
|
|
27
|
+
"url": "git+https://github.com/passlock-dev/ts-clients.git",
|
|
28
|
+
"directory": "packages/client"
|
|
28
29
|
},
|
|
29
30
|
"bugs": {
|
|
30
31
|
"url": "https://github.com/passlock-dev/ts-clients/issues",
|
|
@@ -44,30 +45,32 @@
|
|
|
44
45
|
"!dist/**/*.spec.*"
|
|
45
46
|
],
|
|
46
47
|
"dependencies": {
|
|
47
|
-
"@effect/schema": "0.
|
|
48
|
+
"@effect/schema": "0.71.0",
|
|
48
49
|
"@github/webauthn-json": "^2.1.1",
|
|
49
|
-
"effect": "3.6.
|
|
50
|
-
"@passlock/shared": "0.9.
|
|
50
|
+
"effect": "3.6.4",
|
|
51
|
+
"@passlock/shared": "0.9.24"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
54
|
"@qetza/replacetokens": "^1.7.0",
|
|
54
55
|
"@total-typescript/tsconfig": "^1.0.4",
|
|
55
56
|
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
|
|
56
57
|
"@tsconfig/node20": "^20.1.4",
|
|
57
|
-
"@types/node": "^22.
|
|
58
|
-
"@typescript-eslint/eslint-plugin": "^8.0
|
|
59
|
-
"@typescript-eslint/parser": "^8.0
|
|
58
|
+
"@types/node": "^22.4.0",
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "^8.1.0",
|
|
60
|
+
"@typescript-eslint/parser": "^8.1.0",
|
|
60
61
|
"@vitest/coverage-v8": "^2.0.5",
|
|
61
62
|
"@vitest/ui": "^2.0.5",
|
|
62
63
|
"eslint": "^9.9.0",
|
|
63
64
|
"eslint-config-prettier": "^9.1.0",
|
|
65
|
+
"globals": "^15.9.0",
|
|
64
66
|
"jsdom": "^24.1.1",
|
|
65
67
|
"prettier": "^3.3.3",
|
|
66
|
-
"publint": "^0.2.
|
|
68
|
+
"publint": "^0.2.10",
|
|
67
69
|
"rimraf": "^6.0.1",
|
|
68
70
|
"tslib": "^2.6.3",
|
|
71
|
+
"tsx": "^4.17.0",
|
|
69
72
|
"typescript": "^5.5.4",
|
|
70
|
-
"vite": "^5.4.
|
|
73
|
+
"vite": "^5.4.1",
|
|
71
74
|
"vitest": "^2.0.5",
|
|
72
75
|
"vitest-mock-extended": "^2.0.0"
|
|
73
76
|
},
|
|
@@ -78,13 +81,14 @@
|
|
|
78
81
|
"test:watch": "vitest dev",
|
|
79
82
|
"test:ui": "vitest --coverage.enabled=true --ui",
|
|
80
83
|
"test:coverage": "vitest run --coverage",
|
|
81
|
-
"
|
|
82
|
-
"build": "tsc --build && pnpm run replaceTokens && publint",
|
|
84
|
+
"build": "tsc --build",
|
|
83
85
|
"build:clean": "pnpm run clean && pnpm run build",
|
|
84
|
-
"build:
|
|
85
|
-
"
|
|
86
|
-
"
|
|
86
|
+
"build:readme": "LATEST=${npm_package_version} tsx ../shared/scripts/replace-readme-tokens.ts ./packages/client",
|
|
87
|
+
"replaceTokens": "LATEST=${npm_package_version} tsx ../shared/scripts/replace-tokens.ts ./packages/client",
|
|
88
|
+
"build:production": "pnpm run build:clean && pnpm run replaceTokens && echo '' && publint",
|
|
89
|
+
"format": "prettier --write \"(src|scripts)/**/*.+(js|ts|json)\"",
|
|
90
|
+
"lint": "eslint ./src",
|
|
87
91
|
"lint:fix": "pnpm run lint --fix",
|
|
88
|
-
"upgrade:deps": "ncu --peer -x effect -x @effect/* -u"
|
|
92
|
+
"upgrade:deps": "ncu --peer -x effect -x @effect/* -i -u"
|
|
89
93
|
}
|
|
90
94
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Effect as E, Layer as L, Option as O } from 'effect'
|
|
2
|
+
|
|
1
3
|
import {
|
|
2
4
|
OptionsRes,
|
|
3
5
|
VerificationReq,
|
|
@@ -5,9 +7,9 @@ import {
|
|
|
5
7
|
} from '@passlock/shared/dist/rpc/authentication.js'
|
|
6
8
|
import { IsExistingUserRes, VerifyEmailRes } from '@passlock/shared/dist/rpc/user.js'
|
|
7
9
|
import type { AuthenticationCredential } from '@passlock/shared/dist/schema/passkey.js'
|
|
8
|
-
|
|
9
|
-
import { AuthenticationClient } from '../rpc/authentication.js'
|
|
10
|
+
|
|
10
11
|
import * as Fixtures from '../test/fixtures.js'
|
|
12
|
+
import { AuthenticationClient } from '../rpc/authentication.js'
|
|
11
13
|
import { type AuthenticationRequest, GetCredential } from './authenticate.js'
|
|
12
14
|
|
|
13
15
|
export const session = 'session'
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Effect as E, Layer as L, Layer, LogLevel, Logger, Option as O, pipe } from 'effect'
|
|
2
2
|
import { describe, expect, test, vi } from 'vitest'
|
|
3
3
|
import { mock } from 'vitest-mock-extended'
|
|
4
|
+
|
|
5
|
+
import * as Fixture from './authenticate.fixture.js'
|
|
4
6
|
import { AuthenticationClient } from '../rpc/authentication.js'
|
|
5
7
|
import { StorageService } from '../storage/storage.js'
|
|
6
|
-
import * as Fixture from './authenticate.fixture.js'
|
|
7
8
|
import { AuthenticateServiceLive, AuthenticationService, GetCredential } from './authenticate.js'
|
|
8
9
|
|
|
9
10
|
describe('authenticate should', () => {
|
|
@@ -5,6 +5,8 @@ import {
|
|
|
5
5
|
type CredentialRequestOptionsJSON,
|
|
6
6
|
parseRequestOptionsFromJSON,
|
|
7
7
|
} from '@github/webauthn-json/browser-ponyfill'
|
|
8
|
+
import { Context, Effect as E, Layer, flow, pipe } from 'effect'
|
|
9
|
+
|
|
8
10
|
import { InternalBrowserError, type NotSupported } from '@passlock/shared/dist/error/error.js'
|
|
9
11
|
import {
|
|
10
12
|
type OptionsErrors,
|
|
@@ -14,7 +16,7 @@ import {
|
|
|
14
16
|
} from '@passlock/shared/dist/rpc/authentication.js'
|
|
15
17
|
import type { AuthenticationCredential } from '@passlock/shared/dist/schema/passkey.js'
|
|
16
18
|
import type { Principal } from '@passlock/shared/dist/schema/principal.js'
|
|
17
|
-
|
|
19
|
+
|
|
18
20
|
import { Capabilities } from '../capabilities/capabilities.js'
|
|
19
21
|
import { AuthenticationClient } from '../rpc/authentication.js'
|
|
20
22
|
import { StorageService } from '../storage/storage.js'
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Test if the browser supports passkeys, conditional UI etc
|
|
3
3
|
*/
|
|
4
|
-
import { NotSupported } from '@passlock/shared/dist/error/error.js'
|
|
5
4
|
import { Context, Effect as E, Layer, identity, pipe } from 'effect'
|
|
6
5
|
|
|
6
|
+
import { NotSupported } from '@passlock/shared/dist/error/error.js'
|
|
7
|
+
|
|
7
8
|
/* Service */
|
|
8
9
|
|
|
9
10
|
export class Capabilities extends Context.Tag('@services/Capabilities')<
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { ConnectRes } from '@passlock/shared/dist/rpc/connection.js'
|
|
2
1
|
import { Effect as E, Layer as L } from 'effect'
|
|
2
|
+
|
|
3
|
+
import { ConnectRes } from '@passlock/shared/dist/rpc/connection.js'
|
|
4
|
+
|
|
3
5
|
import { ConnectionClient } from '../rpc/connection.js'
|
|
4
6
|
|
|
5
7
|
export const preConnectRes = new ConnectRes({ warmed: true })
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Effect as E, Layer as L, Layer, LogLevel, Logger, pipe } from 'effect'
|
|
2
2
|
import { describe, expect, test } from 'vitest'
|
|
3
3
|
import { mock } from 'vitest-mock-extended'
|
|
4
|
+
|
|
5
|
+
import * as Fixture from './connection.fixture.js'
|
|
4
6
|
import { Dispatcher } from '../rpc/client.js'
|
|
5
7
|
import { RpcConfig } from '../rpc/config.js'
|
|
6
8
|
import { ConnectionClient } from '../rpc/connection.js'
|
|
7
|
-
import * as Fixture from './connection.fixture.js'
|
|
8
9
|
import { ConnectionService, ConnectionServiceLive } from './connection.js'
|
|
9
10
|
|
|
10
11
|
describe('preConnect should', () => {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Hits the rpc endpoint to warm up a lambda
|
|
3
3
|
*/
|
|
4
4
|
import { Context, Effect as E, Layer, flow, pipe } from 'effect'
|
|
5
|
+
|
|
5
6
|
import { Dispatcher } from '../rpc/client.js'
|
|
6
7
|
import type { RpcConfig } from '../rpc/config.js'
|
|
7
8
|
import { ConnectionClient } from '../rpc/connection.js'
|
package/src/effect.ts
CHANGED
|
@@ -1,25 +1,14 @@
|
|
|
1
1
|
import { create, get as getCredential } from '@github/webauthn-json/browser-ponyfill'
|
|
2
|
+
import { Effect as E, Layer as L, Layer, Schedule, pipe } from 'effect'
|
|
3
|
+
import type { NoSuchElementException } from 'effect/Cause'
|
|
2
4
|
|
|
3
5
|
import {
|
|
4
6
|
type BadRequest,
|
|
5
7
|
Duplicate,
|
|
6
8
|
InternalBrowserError,
|
|
7
9
|
} from '@passlock/shared/dist/error/error.js'
|
|
8
|
-
|
|
9
|
-
import { AuthenticationClientLive } from './rpc/authentication.js'
|
|
10
|
-
import { DispatcherLive } from './rpc/client.js'
|
|
11
|
-
import type { RpcConfig } from './rpc/config.js'
|
|
12
|
-
import { RetrySchedule } from './rpc/config.js'
|
|
13
|
-
import { ConnectionClientLive } from './rpc/connection.js'
|
|
14
|
-
import { RegistrationClientLive } from './rpc/registration.js'
|
|
15
|
-
import { SocialClientLive } from './rpc/social.js'
|
|
16
|
-
import { UserClientLive } from './rpc/user.js'
|
|
17
|
-
|
|
18
10
|
import type { Principal } from '@passlock/shared/dist/schema/principal.js'
|
|
19
11
|
|
|
20
|
-
import { Effect as E, Layer as L, Layer, Schedule, pipe } from 'effect'
|
|
21
|
-
import type { NoSuchElementException } from 'effect/Cause'
|
|
22
|
-
|
|
23
12
|
import {
|
|
24
13
|
AuthenticateServiceLive,
|
|
25
14
|
type AuthenticationErrors,
|
|
@@ -27,7 +16,6 @@ import {
|
|
|
27
16
|
AuthenticationService,
|
|
28
17
|
GetCredential,
|
|
29
18
|
} from './authentication/authenticate.js'
|
|
30
|
-
|
|
31
19
|
import { Capabilities, capabilitiesLive } from './capabilities/capabilities.js'
|
|
32
20
|
import { ConnectionService, ConnectionServiceLive } from './connection/connection.js'
|
|
33
21
|
import {
|
|
@@ -37,7 +25,6 @@ import {
|
|
|
37
25
|
type VerifyEmailErrors,
|
|
38
26
|
type VerifyRequest,
|
|
39
27
|
} from './email/email.js'
|
|
40
|
-
|
|
41
28
|
import {
|
|
42
29
|
CreateCredential,
|
|
43
30
|
type RegistrationErrors,
|
|
@@ -45,7 +32,14 @@ import {
|
|
|
45
32
|
RegistrationService,
|
|
46
33
|
RegistrationServiceLive,
|
|
47
34
|
} from './registration/register.js'
|
|
48
|
-
|
|
35
|
+
import { AuthenticationClientLive } from './rpc/authentication.js'
|
|
36
|
+
import { DispatcherLive } from './rpc/client.js'
|
|
37
|
+
import type { RpcConfig } from './rpc/config.js'
|
|
38
|
+
import { RetrySchedule } from './rpc/config.js'
|
|
39
|
+
import { ConnectionClientLive } from './rpc/connection.js'
|
|
40
|
+
import { RegistrationClientLive } from './rpc/registration.js'
|
|
41
|
+
import { SocialClientLive } from './rpc/social.js'
|
|
42
|
+
import { UserClientLive } from './rpc/user.js'
|
|
49
43
|
import {
|
|
50
44
|
type AuthenticateOidcReq,
|
|
51
45
|
type AuthenticationErrors as OidcAuthenticationErrors,
|
|
@@ -61,7 +55,6 @@ import {
|
|
|
61
55
|
StorageServiceLive,
|
|
62
56
|
type StoredToken,
|
|
63
57
|
} from './storage/storage.js'
|
|
64
|
-
|
|
65
58
|
import {
|
|
66
59
|
type Email,
|
|
67
60
|
type ResendEmail,
|
|
@@ -216,7 +209,8 @@ export const registerPasskey = (
|
|
|
216
209
|
|
|
217
210
|
export const authenticatePasskey = (
|
|
218
211
|
request: AuthenticationRequest,
|
|
219
|
-
): E.Effect<Principal, AuthenticationErrors, RpcConfig> =>
|
|
212
|
+
): E.Effect<Principal, AuthenticationErrors, RpcConfig> =>
|
|
213
|
+
pipe(
|
|
220
214
|
AuthenticationService,
|
|
221
215
|
E.flatMap(service => service.authenticatePasskey(request)),
|
|
222
216
|
E.provide(authenticationServiceLive),
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { VerifyEmailReq, VerifyEmailRes } from '@passlock/shared/dist/rpc/user.js'
|
|
2
1
|
import { Effect as E, Layer as L, Option as O } from 'effect'
|
|
2
|
+
|
|
3
|
+
import { VerifyEmailReq, VerifyEmailRes } from '@passlock/shared/dist/rpc/user.js'
|
|
4
|
+
|
|
5
|
+
import * as Fixtures from '../test/fixtures.js'
|
|
3
6
|
import { AuthenticationService } from '../authentication/authenticate.js'
|
|
4
7
|
import { UserClient } from '../rpc/user.js'
|
|
5
|
-
import * as Fixtures from '../test/fixtures.js'
|
|
6
8
|
import { URLQueryString } from './email.js'
|
|
7
9
|
|
|
8
10
|
export const token = 'token'
|
package/src/email/email.test.ts
CHANGED
|
@@ -2,10 +2,11 @@ import { Effect as E, Layer as L, LogLevel, Logger, pipe } from 'effect'
|
|
|
2
2
|
import { NoSuchElementException } from 'effect/Cause'
|
|
3
3
|
import { describe, expect, test } from 'vitest'
|
|
4
4
|
import { mock } from 'vitest-mock-extended'
|
|
5
|
+
|
|
6
|
+
import * as Fixture from './email.fixture.js'
|
|
5
7
|
import { AuthenticationService } from '../authentication/authenticate.js'
|
|
6
8
|
import { UserClient } from '../rpc/user.js'
|
|
7
9
|
import { StorageService } from '../storage/storage.js'
|
|
8
|
-
import * as Fixture from './email.fixture.js'
|
|
9
10
|
import { EmailService, EmailServiceLive } from './email.js'
|
|
10
11
|
|
|
11
12
|
describe('verifyEmailCode should', () => {
|
package/src/email/email.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Email verification effects
|
|
3
3
|
*/
|
|
4
|
+
import { Context, Effect as E, Layer, Option as O, flow, identity, pipe } from 'effect'
|
|
5
|
+
|
|
4
6
|
import { BadRequest } from '@passlock/shared/dist/error/error.js'
|
|
5
7
|
import type { VerifyEmailErrors as RpcErrors } from '@passlock/shared/dist/rpc/user.js'
|
|
6
8
|
import { VerifyEmailReq } from '@passlock/shared/dist/rpc/user.js'
|
|
7
9
|
import type { Principal } from '@passlock/shared/dist/schema/principal.js'
|
|
8
|
-
|
|
10
|
+
|
|
9
11
|
import { type AuthenticationErrors, AuthenticationService } from '../authentication/authenticate.js'
|
|
10
12
|
import { UserClient } from '../rpc/user.js'
|
|
11
13
|
import { StorageService, type StoredToken } from '../storage/storage.js'
|
package/src/event/event.test.ts
CHANGED
package/src/event/event.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Fire DOM events
|
|
3
3
|
*/
|
|
4
|
-
import { InternalBrowserError } from '@passlock/shared/dist/error/error.js'
|
|
5
4
|
import { Effect } from 'effect'
|
|
6
5
|
|
|
6
|
+
import { InternalBrowserError } from '@passlock/shared/dist/error/error.js'
|
|
7
|
+
|
|
7
8
|
export const DebugMessage = 'PasslogDebugMessage'
|
|
8
9
|
|
|
9
10
|
export const fireEvent = (message: string) => {
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { Effect as E, Layer as L, Layer, Option as O, Runtime, Scope, pipe } from 'effect'
|
|
2
|
+
import { dual } from 'effect/Function'
|
|
3
|
+
|
|
1
4
|
import type {
|
|
2
5
|
BadRequest,
|
|
3
6
|
Disabled,
|
|
@@ -7,20 +10,14 @@ import type {
|
|
|
7
10
|
NotSupported,
|
|
8
11
|
Unauthorized,
|
|
9
12
|
} from '@passlock/shared/dist/error/error.js'
|
|
10
|
-
|
|
11
13
|
import { ErrorCode } from '@passlock/shared/dist/error/error.js'
|
|
12
14
|
import type { VerifyEmail } from '@passlock/shared/dist/schema/email.js'
|
|
13
15
|
import type { UserVerification } from '@passlock/shared/dist/schema/passkey.js'
|
|
14
16
|
import type { Principal, UserPrincipal } from '@passlock/shared/dist/schema/principal.js'
|
|
15
|
-
import { RpcConfig } from './rpc/config.js'
|
|
16
|
-
|
|
17
|
-
import { Effect as E, Layer as L, Layer, Option as O, Runtime, Scope, pipe } from 'effect'
|
|
18
17
|
|
|
19
18
|
import type { AuthenticationService } from './authentication/authenticate.js'
|
|
20
19
|
import type { Capabilities } from './capabilities/capabilities.js'
|
|
21
20
|
import type { ConnectionService } from './connection/connection.js'
|
|
22
|
-
|
|
23
|
-
import { dual } from 'effect/Function'
|
|
24
21
|
import {
|
|
25
22
|
allRequirements,
|
|
26
23
|
authenticateOidc,
|
|
@@ -38,6 +35,7 @@ import {
|
|
|
38
35
|
} from './effect.js'
|
|
39
36
|
import type { EmailService, VerifyRequest } from './email/email.js'
|
|
40
37
|
import type { RegistrationService } from './registration/register.js'
|
|
38
|
+
import { RpcConfig } from './rpc/config.js'
|
|
41
39
|
import type { Provider, SocialService } from './social/social.js'
|
|
42
40
|
import {
|
|
43
41
|
type AuthType,
|
|
@@ -193,7 +191,7 @@ const transformErrors = <A, R>(
|
|
|
193
191
|
},
|
|
194
192
|
|
|
195
193
|
Interrupt: () => {
|
|
196
|
-
console.error(
|
|
194
|
+
console.error('Interrupt')
|
|
197
195
|
return E.succeed(new PasslockError('Operation aborted', ErrorCode.InternalBrowserError))
|
|
198
196
|
},
|
|
199
197
|
|
|
@@ -207,7 +205,7 @@ const transformErrors = <A, R>(
|
|
|
207
205
|
|
|
208
206
|
Parallel: errors => {
|
|
209
207
|
console.error(errors)
|
|
210
|
-
|
|
208
|
+
|
|
211
209
|
return E.succeed(
|
|
212
210
|
new PasslockError('Sorry, something went wrong', ErrorCode.InternalServerError),
|
|
213
211
|
)
|
|
@@ -252,15 +250,24 @@ export class PasslockUnsafe {
|
|
|
252
250
|
}
|
|
253
251
|
|
|
254
252
|
private readonly runPromise: {
|
|
255
|
-
<A, R extends Requirements>(
|
|
256
|
-
|
|
253
|
+
<A, R extends Requirements>(
|
|
254
|
+
options: Options | undefined,
|
|
255
|
+
): (effect: E.Effect<A, PasslockErrors, R>) => Promise<A>
|
|
256
|
+
<A, R extends Requirements>(
|
|
257
|
+
effect: E.Effect<A, PasslockErrors, R>,
|
|
258
|
+
options: Options | undefined,
|
|
259
|
+
): Promise<A>
|
|
257
260
|
} = dual(
|
|
258
261
|
2,
|
|
259
|
-
<A, R extends Requirements>(
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
262
|
+
<A, R extends Requirements>(
|
|
263
|
+
effect: E.Effect<A, PasslockErrors, R>,
|
|
264
|
+
options: Options | undefined,
|
|
265
|
+
): Promise<A> =>
|
|
266
|
+
pipe(
|
|
267
|
+
transformErrors(effect),
|
|
268
|
+
E.flatMap(result => (PasslockError.isError(result) ? E.fail(result) : E.succeed(result))),
|
|
269
|
+
effect => Runtime.runPromise(this.runtime)(effect, options),
|
|
270
|
+
),
|
|
264
271
|
)
|
|
265
272
|
|
|
266
273
|
preConnect = (options?: Options): Promise<void> => pipe(preConnect(), this.runPromise(options))
|
|
@@ -316,7 +323,7 @@ export class Passlock {
|
|
|
316
323
|
const scope = E.runSync(Scope.make())
|
|
317
324
|
|
|
318
325
|
this.runtime = E.runSync(Layer.toRuntime(allLayers).pipe(Scope.extend(scope)))
|
|
319
|
-
|
|
326
|
+
|
|
320
327
|
E.runSync(E.logDebug(`Passlock version: ${PASSLOCK_CLIENT_VERSION}`))
|
|
321
328
|
}
|
|
322
329
|
|
|
@@ -330,22 +337,24 @@ export class Passlock {
|
|
|
330
337
|
}
|
|
331
338
|
|
|
332
339
|
private readonly runPromise: {
|
|
333
|
-
<A, R extends Requirements>(
|
|
334
|
-
|
|
340
|
+
<A, R extends Requirements>(
|
|
341
|
+
options: Options | undefined,
|
|
342
|
+
): (effect: E.Effect<A, PasslockErrors, R>) => Promise<A | PasslockError>
|
|
343
|
+
<A, R extends Requirements>(
|
|
344
|
+
effect: E.Effect<A, PasslockErrors, R>,
|
|
345
|
+
options: Options | undefined,
|
|
346
|
+
): Promise<A | PasslockError>
|
|
335
347
|
} = dual(
|
|
336
348
|
2,
|
|
337
|
-
<A, R extends Requirements>(
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
)
|
|
349
|
+
<A, R extends Requirements>(
|
|
350
|
+
effect: E.Effect<A, PasslockErrors, R>,
|
|
351
|
+
options: Options | undefined,
|
|
352
|
+
): Promise<A | PasslockError> =>
|
|
353
|
+
pipe(transformErrors(effect), effect => Runtime.runPromise(this.runtime)(effect, options)),
|
|
341
354
|
)
|
|
342
355
|
|
|
343
356
|
preConnect = async (options?: Options): Promise<boolean | PasslockError> => {
|
|
344
|
-
return pipe(
|
|
345
|
-
preConnect(),
|
|
346
|
-
E.as(true),
|
|
347
|
-
this.runPromise(options)
|
|
348
|
-
)
|
|
357
|
+
return pipe(preConnect(), E.as(true), this.runPromise(options))
|
|
349
358
|
}
|
|
350
359
|
|
|
351
360
|
isPasskeySupport = (): Promise<boolean> =>
|
|
@@ -363,13 +372,10 @@ export class Passlock {
|
|
|
363
372
|
authenticatePasskey = (
|
|
364
373
|
request: AuthenticationRequest = {},
|
|
365
374
|
options?: Options,
|
|
366
|
-
): Promise<Principal | PasslockError> =>
|
|
367
|
-
|
|
368
|
-
authenticatePasskey,
|
|
369
|
-
this.runPromise(options)
|
|
370
|
-
)
|
|
375
|
+
): Promise<Principal | PasslockError> =>
|
|
376
|
+
pipe(toRpcAuthenticationRequest(request), authenticatePasskey, this.runPromise(options))
|
|
371
377
|
|
|
372
|
-
registerOidc = (request: RegisterOidcReq, options?: Options) =>
|
|
378
|
+
registerOidc = (request: RegisterOidcReq, options?: Options) =>
|
|
373
379
|
pipe(registerOidc(toRpcRegisterOidcReq(request)), this.runPromise(options))
|
|
374
380
|
|
|
375
381
|
authenticateOidc = (request: AuthenticateOidcReq, options?: Options) =>
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Effect as E, Layer as L, Option as O } from 'effect'
|
|
2
|
+
|
|
1
3
|
import {
|
|
2
4
|
OptionsReq,
|
|
3
5
|
OptionsRes,
|
|
@@ -5,9 +7,9 @@ import {
|
|
|
5
7
|
VerificationRes,
|
|
6
8
|
} from '@passlock/shared/dist/rpc/registration.js'
|
|
7
9
|
import type { RegistrationCredential } from '@passlock/shared/dist/schema/passkey.js'
|
|
8
|
-
|
|
9
|
-
import { RegistrationClient } from '../rpc/registration.js'
|
|
10
|
+
|
|
10
11
|
import * as Fixtures from '../test/fixtures.js'
|
|
12
|
+
import { RegistrationClient } from '../rpc/registration.js'
|
|
11
13
|
import { UserService } from '../user/user.js'
|
|
12
14
|
import { CreateCredential, type RegistrationRequest } from './register.js'
|
|
13
15
|
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { Duplicate, InternalBrowserError } from '@passlock/shared/dist/error/error.js'
|
|
2
1
|
import { Effect as E, Layer as L, Layer, LogLevel, Logger, pipe } from 'effect'
|
|
3
2
|
import { describe, expect, test, vi } from 'vitest'
|
|
4
3
|
import { mock } from 'vitest-mock-extended'
|
|
5
|
-
|
|
4
|
+
|
|
5
|
+
import { Duplicate, InternalBrowserError } from '@passlock/shared/dist/error/error.js'
|
|
6
|
+
|
|
6
7
|
import * as Fixture from './register.fixture.js'
|
|
8
|
+
import { RegistrationClient } from '../rpc/registration.js'
|
|
7
9
|
import { CreateCredential, RegistrationService, RegistrationServiceLive } from './register.js'
|
|
8
10
|
|
|
9
11
|
describe('register should', () => {
|
|
@@ -5,16 +5,15 @@ import {
|
|
|
5
5
|
type CredentialCreationOptionsJSON,
|
|
6
6
|
parseCreationOptionsFromJSON,
|
|
7
7
|
} from '@github/webauthn-json/browser-ponyfill'
|
|
8
|
+
import { Context, Effect as E, Layer, flow, pipe } from 'effect'
|
|
9
|
+
|
|
8
10
|
import type { Duplicate, NotSupported } from '@passlock/shared/dist/error/error.js'
|
|
9
11
|
import { InternalBrowserError } from '@passlock/shared/dist/error/error.js'
|
|
10
12
|
import type { OptionsErrors, VerificationErrors } from '@passlock/shared/dist/rpc/registration.js'
|
|
11
|
-
import {
|
|
12
|
-
OptionsReq,
|
|
13
|
-
VerificationReq,
|
|
14
|
-
} from '@passlock/shared/dist/rpc/registration.js'
|
|
13
|
+
import { OptionsReq, VerificationReq } from '@passlock/shared/dist/rpc/registration.js'
|
|
15
14
|
import type { RegistrationCredential } from '@passlock/shared/dist/schema/passkey.js'
|
|
16
15
|
import type { Principal } from '@passlock/shared/dist/schema/principal.js'
|
|
17
|
-
|
|
16
|
+
|
|
18
17
|
import { Capabilities } from '../capabilities/capabilities.js'
|
|
19
18
|
import { RegistrationClient } from '../rpc/registration.js'
|
|
20
19
|
import { StorageService } from '../storage/storage.js'
|
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
import { OPTIONS_ENDPOINT, OptionsErrors, OptionsReq, OptionsRes, VerificationErrors, VerificationReq, VerificationRes, VERIFY_ENDPOINT, type AuthenticationService } from '@passlock/shared/dist/rpc/authentication.js'
|
|
2
1
|
import { Context, Effect as E, Layer } from 'effect'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type AuthenticationService,
|
|
5
|
+
OPTIONS_ENDPOINT,
|
|
6
|
+
OptionsErrors,
|
|
7
|
+
OptionsReq,
|
|
8
|
+
OptionsRes,
|
|
9
|
+
VERIFY_ENDPOINT,
|
|
10
|
+
VerificationErrors,
|
|
11
|
+
VerificationReq,
|
|
12
|
+
VerificationRes,
|
|
13
|
+
} from '@passlock/shared/dist/rpc/authentication.js'
|
|
14
|
+
|
|
3
15
|
import { Dispatcher, makePostRequest } from './client.js'
|
|
4
16
|
|
|
5
17
|
/* Client */
|
|
@@ -28,4 +40,4 @@ export const AuthenticationClientLive = Layer.effect(
|
|
|
28
40
|
verifyAuthenticationCredential: req => verifyResolver(VERIFY_ENDPOINT, req),
|
|
29
41
|
}
|
|
30
42
|
}),
|
|
31
|
-
)
|
|
43
|
+
)
|
package/src/rpc/client.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as S from '@effect/schema/Schema'
|
|
2
|
-
import { NetworkError } from '@passlock/shared/dist/error/error.js'
|
|
3
2
|
import { Context, Effect as E, Layer, pipe } from 'effect'
|
|
3
|
+
|
|
4
|
+
import { NetworkError } from '@passlock/shared/dist/error/error.js'
|
|
5
|
+
|
|
4
6
|
import { PASSLOCK_CLIENT_VERSION } from '../version.js'
|
|
5
7
|
import { RetrySchedule, RpcConfig } from './config.js'
|
|
6
8
|
|
|
@@ -27,7 +29,6 @@ export const DispatcherLive = Layer.effect(
|
|
|
27
29
|
const { schedule } = yield* _(RetrySchedule)
|
|
28
30
|
const { tenancyId, clientId, endpoint: maybeEndpoint } = yield* _(RpcConfig)
|
|
29
31
|
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
31
32
|
const parseJson = (res: Response, url: string) =>
|
|
32
33
|
E.tryPromise({
|
|
33
34
|
try: () => res.json() as Promise<unknown>,
|
|
@@ -73,7 +74,7 @@ export const DispatcherLive = Layer.effect(
|
|
|
73
74
|
const headers = {
|
|
74
75
|
'Accept': 'application/json',
|
|
75
76
|
'X-CLIENT-ID': clientId,
|
|
76
|
-
'X-PASSLOCK-CLIENT-VERSION': PASSLOCK_CLIENT_VERSION
|
|
77
|
+
'X-PASSLOCK-CLIENT-VERSION': PASSLOCK_CLIENT_VERSION,
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
const url = buildUrl(path)
|
|
@@ -102,7 +103,7 @@ export const DispatcherLive = Layer.effect(
|
|
|
102
103
|
'Content-Type': 'application/json',
|
|
103
104
|
'Accept': 'application/json',
|
|
104
105
|
'X-CLIENT-ID': clientId,
|
|
105
|
-
'X-PASSLOCK-CLIENT-VERSION': PASSLOCK_CLIENT_VERSION
|
|
106
|
+
'X-PASSLOCK-CLIENT-VERSION': PASSLOCK_CLIENT_VERSION,
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
// drop leading /
|
package/src/rpc/connection.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import * as S from '@effect/schema/Schema'
|
|
2
|
-
import { CONNECT_ENDPOINT, ConnectRes, type ConnectionService } from '@passlock/shared/dist/rpc/connection.js'
|
|
3
2
|
import { Context, Effect as E, Layer } from 'effect'
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
CONNECT_ENDPOINT,
|
|
6
|
+
ConnectRes,
|
|
7
|
+
type ConnectionService,
|
|
8
|
+
} from '@passlock/shared/dist/rpc/connection.js'
|
|
9
|
+
|
|
4
10
|
import { Dispatcher, makeGetRequest } from './client.js'
|
|
5
11
|
|
|
6
12
|
/* Client */
|
|
@@ -21,4 +27,4 @@ export const ConnectionClientLive = Layer.effect(
|
|
|
21
27
|
preConnect: () => preConnectResolver(CONNECT_ENDPOINT),
|
|
22
28
|
}
|
|
23
29
|
}),
|
|
24
|
-
)
|
|
30
|
+
)
|
package/src/rpc/registration.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
import { OptionsErrors, OptionsReq, OptionsRes, VerificationErrors, VerificationReq, VerificationRes, type RegistrationService } from '@passlock/shared/dist/rpc/registration.js'
|
|
2
1
|
import { Context, Effect as E, Layer } from 'effect'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
OptionsErrors,
|
|
5
|
+
OptionsReq,
|
|
6
|
+
OptionsRes,
|
|
7
|
+
type RegistrationService,
|
|
8
|
+
VerificationErrors,
|
|
9
|
+
VerificationReq,
|
|
10
|
+
VerificationRes,
|
|
11
|
+
} from '@passlock/shared/dist/rpc/registration.js'
|
|
12
|
+
|
|
3
13
|
import { Dispatcher, makePostRequest } from './client.js'
|
|
4
14
|
|
|
5
15
|
/* Client */
|
|
@@ -28,4 +38,4 @@ export const RegistrationClientLive = Layer.effect(
|
|
|
28
38
|
verifyRegistrationCredential: req => verifyResolver('/passkey/register/verify', req),
|
|
29
39
|
}
|
|
30
40
|
}),
|
|
31
|
-
)
|
|
41
|
+
)
|