@fabriktor/client 0.0.12 → 0.0.14
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/dist/src/core/auth.d.ts +2 -0
- package/dist/src/core/auth.js +15 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/users/tmp_phones.d.ts +7 -6
- package/dist/src/users/tmp_phones.js +11 -2
- package/dist/src/users/tmp_usernames.d.ts +6 -3
- package/dist/src/users/tmp_usernames.js +8 -1
- package/dist/src/users/users.d.ts +16 -21
- package/dist/src/users/users.js +32 -18
- package/package.json +2 -2
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright (C) Fabriktor, Inc. 2025-present.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
4
|
+
// not use this file except in compliance with the License. You may obtain
|
|
5
|
+
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
export async function requiredToken(getToken) {
|
|
7
|
+
if (!getToken) {
|
|
8
|
+
throw new Error("Authenticated client method requires a token provider.");
|
|
9
|
+
}
|
|
10
|
+
const out = await getToken();
|
|
11
|
+
if (!out) {
|
|
12
|
+
throw new Error("Authenticated client method received an empty token.");
|
|
13
|
+
}
|
|
14
|
+
return out;
|
|
15
|
+
}
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import type { PLUsersSendCode, PLUsersVerifyCode } from "@fabriktor/schema";
|
|
2
|
+
import type { TokenProvider } from "../core/auth.js";
|
|
2
3
|
import type { HTTPDoer } from "../core/http.js";
|
|
3
|
-
export type SendPhoneVerificationOptions =
|
|
4
|
-
|
|
5
|
-
} & PLUsersSendCode;
|
|
6
|
-
export type VerifyPhoneOptions = {
|
|
7
|
-
base_url: string;
|
|
8
|
-
} & PLUsersVerifyCode;
|
|
4
|
+
export type SendPhoneVerificationOptions = PLUsersSendCode;
|
|
5
|
+
export type VerifyPhoneOptions = PLUsersVerifyCode;
|
|
9
6
|
export interface TmpPhonesOperator {
|
|
10
7
|
send(opts: SendPhoneVerificationOptions): Promise<void>;
|
|
11
8
|
verify(opts: VerifyPhoneOptions): Promise<void>;
|
|
12
9
|
}
|
|
13
10
|
export type TmpPhonesClientOptions = {
|
|
14
11
|
http: HTTPDoer;
|
|
12
|
+
base_url: string;
|
|
13
|
+
get_token?: TokenProvider;
|
|
15
14
|
};
|
|
16
15
|
export declare class TmpPhonesClient implements TmpPhonesOperator {
|
|
17
16
|
private http;
|
|
17
|
+
private base_url;
|
|
18
|
+
private get_token?;
|
|
18
19
|
constructor(opts: TmpPhonesClientOptions);
|
|
19
20
|
send(opts: SendPhoneVerificationOptions): Promise<void>;
|
|
20
21
|
verify(opts: VerifyPhoneOptions): Promise<void>;
|
|
@@ -4,27 +4,36 @@
|
|
|
4
4
|
// not use this file except in compliance with the License. You may obtain
|
|
5
5
|
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
6
|
import { ColUsersTmpPhones, HTTPMethodPost, PathUsersSend, PathUsersVerify, SvcUsers, } from "@fabriktor/schema";
|
|
7
|
+
import { requiredToken } from "../core/auth.js";
|
|
7
8
|
import { buildPath } from "../core/path.js";
|
|
8
9
|
export class TmpPhonesClient {
|
|
9
10
|
http;
|
|
11
|
+
base_url;
|
|
12
|
+
get_token;
|
|
10
13
|
constructor(opts) {
|
|
11
14
|
this.http = opts.http;
|
|
15
|
+
this.base_url = opts.base_url;
|
|
16
|
+
this.get_token = opts.get_token;
|
|
12
17
|
}
|
|
13
18
|
async send(opts) {
|
|
19
|
+
const token = await requiredToken(this.get_token);
|
|
14
20
|
return await this.http.do({
|
|
15
|
-
base_url:
|
|
21
|
+
base_url: this.base_url,
|
|
16
22
|
path: tmpPhonePath(PathUsersSend),
|
|
17
23
|
method: HTTPMethodPost,
|
|
24
|
+
token,
|
|
18
25
|
body: {
|
|
19
26
|
phone: opts.phone,
|
|
20
27
|
},
|
|
21
28
|
});
|
|
22
29
|
}
|
|
23
30
|
async verify(opts) {
|
|
31
|
+
const token = await requiredToken(this.get_token);
|
|
24
32
|
return await this.http.do({
|
|
25
|
-
base_url:
|
|
33
|
+
base_url: this.base_url,
|
|
26
34
|
path: tmpPhonePath(PathUsersVerify),
|
|
27
35
|
method: HTTPMethodPost,
|
|
36
|
+
token,
|
|
28
37
|
body: {
|
|
29
38
|
phone: opts.phone,
|
|
30
39
|
code: opts.code,
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { PLUsersUsername } from "@fabriktor/schema";
|
|
2
|
+
import type { TokenProvider } from "../core/auth.js";
|
|
2
3
|
import type { HTTPDoer, Op } from "../core/http.js";
|
|
3
|
-
export type VerifyUsernameOptions =
|
|
4
|
-
base_url: string;
|
|
5
|
-
} & PLUsersUsername;
|
|
4
|
+
export type VerifyUsernameOptions = PLUsersUsername;
|
|
6
5
|
export type UsernameVerification = {
|
|
7
6
|
username: string;
|
|
8
7
|
suggestions: string[];
|
|
@@ -12,9 +11,13 @@ export interface TmpUsernamesOperator {
|
|
|
12
11
|
}
|
|
13
12
|
export type TmpUsernamesClientOptions = {
|
|
14
13
|
http: HTTPDoer;
|
|
14
|
+
base_url: string;
|
|
15
|
+
get_token?: TokenProvider;
|
|
15
16
|
};
|
|
16
17
|
export declare class TmpUsernamesClient implements TmpUsernamesOperator {
|
|
17
18
|
private http;
|
|
19
|
+
private base_url;
|
|
20
|
+
private get_token?;
|
|
18
21
|
constructor(opts: TmpUsernamesClientOptions);
|
|
19
22
|
verify(opts: VerifyUsernameOptions): Promise<Op<UsernameVerification>>;
|
|
20
23
|
}
|
|
@@ -4,17 +4,24 @@
|
|
|
4
4
|
// not use this file except in compliance with the License. You may obtain
|
|
5
5
|
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
6
|
import { ColUsersTmpUsernames, HTTPMethodPost, PathUsersVerify, SvcUsers, } from "@fabriktor/schema";
|
|
7
|
+
import { requiredToken } from "../core/auth.js";
|
|
7
8
|
import { buildPath } from "../core/path.js";
|
|
8
9
|
export class TmpUsernamesClient {
|
|
9
10
|
http;
|
|
11
|
+
base_url;
|
|
12
|
+
get_token;
|
|
10
13
|
constructor(opts) {
|
|
11
14
|
this.http = opts.http;
|
|
15
|
+
this.base_url = opts.base_url;
|
|
16
|
+
this.get_token = opts.get_token;
|
|
12
17
|
}
|
|
13
18
|
async verify(opts) {
|
|
19
|
+
const token = await requiredToken(this.get_token);
|
|
14
20
|
return await this.http.do({
|
|
15
|
-
base_url:
|
|
21
|
+
base_url: this.base_url,
|
|
16
22
|
path: tmpUsernamePath(PathUsersVerify),
|
|
17
23
|
method: HTTPMethodPost,
|
|
24
|
+
token,
|
|
18
25
|
body: {
|
|
19
26
|
words: opts.words,
|
|
20
27
|
to_validate: opts.to_validate,
|
|
@@ -1,36 +1,27 @@
|
|
|
1
1
|
import type { InUser, OperationResult, PLUsersContactList, PLUsersForgotPassword, PLUsersResolveUsername, PLUsersSignInLink, UpsertResult, User } from "@fabriktor/schema";
|
|
2
|
+
import type { TokenProvider } from "../core/auth.js";
|
|
2
3
|
import type { HTTPDoer, Op } from "../core/http.js";
|
|
3
|
-
export type
|
|
4
|
-
base_url: string;
|
|
5
|
-
token: string;
|
|
6
|
-
};
|
|
7
|
-
export type BootstrapOptions = AuthOptions & {
|
|
4
|
+
export type BootstrapOptions = {
|
|
8
5
|
in: InUser;
|
|
9
6
|
};
|
|
10
|
-
export type ResolveUsernameOptions =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export type
|
|
14
|
-
base_url: string;
|
|
15
|
-
} & PLUsersForgotPassword;
|
|
16
|
-
export type SendSignInLinkOptions = {
|
|
17
|
-
base_url: string;
|
|
18
|
-
} & PLUsersSignInLink;
|
|
19
|
-
export type MatchOptions = AuthOptions & PLUsersContactList;
|
|
7
|
+
export type ResolveUsernameOptions = PLUsersResolveUsername;
|
|
8
|
+
export type ForgotPasswordOptions = PLUsersForgotPassword;
|
|
9
|
+
export type SendSignInLinkOptions = PLUsersSignInLink;
|
|
10
|
+
export type MatchOptions = PLUsersContactList;
|
|
20
11
|
export type MatchResult = {
|
|
21
12
|
users: User[];
|
|
22
13
|
};
|
|
23
|
-
export type SearchOptions =
|
|
14
|
+
export type SearchOptions = {
|
|
24
15
|
q: string;
|
|
25
16
|
limit?: number;
|
|
26
17
|
};
|
|
27
|
-
export type GetByUIDOptions =
|
|
18
|
+
export type GetByUIDOptions = {
|
|
28
19
|
uid: string;
|
|
29
20
|
};
|
|
30
21
|
export interface UsersOperator {
|
|
31
22
|
bootstrap(opts: BootstrapOptions): Promise<Op<UpsertResult>>;
|
|
32
|
-
sync(
|
|
33
|
-
sendEmailVerification(
|
|
23
|
+
sync(): Promise<OperationResult>;
|
|
24
|
+
sendEmailVerification(): Promise<void>;
|
|
34
25
|
forgotPassword(opts: ForgotPasswordOptions): Promise<void>;
|
|
35
26
|
sendSignInLink(opts: SendSignInLinkOptions): Promise<void>;
|
|
36
27
|
resolveUsername(opts: ResolveUsernameOptions): Promise<Op<string>>;
|
|
@@ -40,13 +31,17 @@ export interface UsersOperator {
|
|
|
40
31
|
}
|
|
41
32
|
export type UsersClientOptions = {
|
|
42
33
|
http: HTTPDoer;
|
|
34
|
+
base_url: string;
|
|
35
|
+
get_token?: TokenProvider;
|
|
43
36
|
};
|
|
44
37
|
export declare class UsersClient implements UsersOperator {
|
|
45
38
|
private http;
|
|
39
|
+
private base_url;
|
|
40
|
+
private get_token?;
|
|
46
41
|
constructor(opts: UsersClientOptions);
|
|
47
42
|
bootstrap(opts: BootstrapOptions): Promise<Op<UpsertResult>>;
|
|
48
|
-
sync(
|
|
49
|
-
sendEmailVerification(
|
|
43
|
+
sync(): Promise<OperationResult>;
|
|
44
|
+
sendEmailVerification(): Promise<void>;
|
|
50
45
|
forgotPassword(opts: ForgotPasswordOptions): Promise<void>;
|
|
51
46
|
sendSignInLink(opts: SendSignInLinkOptions): Promise<void>;
|
|
52
47
|
resolveUsername(opts: ResolveUsernameOptions): Promise<Op<string>>;
|
package/dist/src/users/users.js
CHANGED
|
@@ -4,40 +4,48 @@
|
|
|
4
4
|
// not use this file except in compliance with the License. You may obtain
|
|
5
5
|
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
6
|
import { ColUsersUsers, HTTPMethodGet, HTTPMethodPost, PathSearch, PathUsersBootstrap, PathUsersForgotPassword, PathUsersMatch, PathUsersResolveUsername, PathUsersSendEmailVerification, PathUsersSendSignInLink, PathUsersSync, SvcUsers, } from "@fabriktor/schema";
|
|
7
|
+
import { requiredToken } from "../core/auth.js";
|
|
7
8
|
import { buildPath } from "../core/path.js";
|
|
8
9
|
export class UsersClient {
|
|
9
10
|
http;
|
|
11
|
+
base_url;
|
|
12
|
+
get_token;
|
|
10
13
|
constructor(opts) {
|
|
11
14
|
this.http = opts.http;
|
|
15
|
+
this.base_url = opts.base_url;
|
|
16
|
+
this.get_token = opts.get_token;
|
|
12
17
|
}
|
|
13
18
|
async bootstrap(opts) {
|
|
19
|
+
const token = await requiredToken(this.get_token);
|
|
14
20
|
return await this.http.do({
|
|
15
|
-
base_url:
|
|
21
|
+
base_url: this.base_url,
|
|
16
22
|
path: userPath(PathUsersBootstrap),
|
|
17
23
|
method: HTTPMethodPost,
|
|
18
|
-
token
|
|
24
|
+
token,
|
|
19
25
|
body: opts.in,
|
|
20
26
|
});
|
|
21
27
|
}
|
|
22
|
-
async sync(
|
|
28
|
+
async sync() {
|
|
29
|
+
const token = await requiredToken(this.get_token);
|
|
23
30
|
return await this.http.do({
|
|
24
|
-
base_url:
|
|
31
|
+
base_url: this.base_url,
|
|
25
32
|
path: userPath(PathUsersSync),
|
|
26
33
|
method: HTTPMethodPost,
|
|
27
|
-
token
|
|
34
|
+
token,
|
|
28
35
|
});
|
|
29
36
|
}
|
|
30
|
-
async sendEmailVerification(
|
|
37
|
+
async sendEmailVerification() {
|
|
38
|
+
const token = await requiredToken(this.get_token);
|
|
31
39
|
return await this.http.do({
|
|
32
|
-
base_url:
|
|
40
|
+
base_url: this.base_url,
|
|
33
41
|
path: userPath(PathUsersSendEmailVerification),
|
|
34
42
|
method: HTTPMethodPost,
|
|
35
|
-
token
|
|
43
|
+
token,
|
|
36
44
|
});
|
|
37
45
|
}
|
|
38
46
|
async forgotPassword(opts) {
|
|
39
47
|
return await this.http.do({
|
|
40
|
-
base_url:
|
|
48
|
+
base_url: this.base_url,
|
|
41
49
|
path: userPath(PathUsersForgotPassword),
|
|
42
50
|
method: HTTPMethodPost,
|
|
43
51
|
body: {
|
|
@@ -47,7 +55,7 @@ export class UsersClient {
|
|
|
47
55
|
}
|
|
48
56
|
async sendSignInLink(opts) {
|
|
49
57
|
return await this.http.do({
|
|
50
|
-
base_url:
|
|
58
|
+
base_url: this.base_url,
|
|
51
59
|
path: userPath(PathUsersSendSignInLink),
|
|
52
60
|
method: HTTPMethodPost,
|
|
53
61
|
body: {
|
|
@@ -57,7 +65,7 @@ export class UsersClient {
|
|
|
57
65
|
}
|
|
58
66
|
async resolveUsername(opts) {
|
|
59
67
|
return await this.http.do({
|
|
60
|
-
base_url:
|
|
68
|
+
base_url: this.base_url,
|
|
61
69
|
path: userPath(PathUsersResolveUsername),
|
|
62
70
|
method: HTTPMethodPost,
|
|
63
71
|
body: {
|
|
@@ -66,31 +74,37 @@ export class UsersClient {
|
|
|
66
74
|
});
|
|
67
75
|
}
|
|
68
76
|
async match(opts) {
|
|
77
|
+
const token = await requiredToken(this.get_token);
|
|
69
78
|
return await this.http.do({
|
|
70
|
-
base_url:
|
|
79
|
+
base_url: this.base_url,
|
|
71
80
|
path: userPath(PathUsersMatch),
|
|
72
81
|
method: HTTPMethodPost,
|
|
73
|
-
token
|
|
82
|
+
token,
|
|
74
83
|
body: {
|
|
75
84
|
contacts: opts.contacts,
|
|
76
85
|
},
|
|
77
86
|
});
|
|
78
87
|
}
|
|
79
88
|
async search(opts) {
|
|
89
|
+
const token = await requiredToken(this.get_token);
|
|
80
90
|
return await this.http.do({
|
|
81
|
-
base_url:
|
|
91
|
+
base_url: this.base_url,
|
|
82
92
|
path: userPath(PathSearch),
|
|
83
93
|
method: HTTPMethodPost,
|
|
84
|
-
token
|
|
85
|
-
body:
|
|
94
|
+
token,
|
|
95
|
+
body: {
|
|
96
|
+
q: opts.q,
|
|
97
|
+
limit: opts.limit,
|
|
98
|
+
},
|
|
86
99
|
});
|
|
87
100
|
}
|
|
88
101
|
async getByUID(opts) {
|
|
102
|
+
const token = await requiredToken(this.get_token);
|
|
89
103
|
return await this.http.do({
|
|
90
|
-
base_url:
|
|
104
|
+
base_url: this.base_url,
|
|
91
105
|
path: `${collectionPath()}?uid=${encodeURIComponent(opts.uid)}`,
|
|
92
106
|
method: HTTPMethodGet,
|
|
93
|
-
token
|
|
107
|
+
token,
|
|
94
108
|
});
|
|
95
109
|
}
|
|
96
110
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabriktor/client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -17,6 +17,6 @@
|
|
|
17
17
|
"typescript": "^6.0.3"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@fabriktor/schema": "^0.0.
|
|
20
|
+
"@fabriktor/schema": "^0.0.12"
|
|
21
21
|
}
|
|
22
22
|
}
|