@fabriktor/client 0.0.13 → 0.0.15
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 +16 -0
- package/dist/src/core/err.d.ts +28 -5
- package/dist/src/core/err.js +84 -6
- package/dist/src/core/http.js +32 -12
- 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 +18 -26
- package/dist/src/users/users.js +32 -18
- package/package.json +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
import { errAuthTokenEmpty, errAuthTokenProviderMissing } from "./err.js";
|
|
7
|
+
export async function requiredToken(getToken) {
|
|
8
|
+
if (!getToken) {
|
|
9
|
+
throw errAuthTokenProviderMissing();
|
|
10
|
+
}
|
|
11
|
+
const out = await getToken();
|
|
12
|
+
if (!out) {
|
|
13
|
+
throw errAuthTokenEmpty();
|
|
14
|
+
}
|
|
15
|
+
return out;
|
|
16
|
+
}
|
package/dist/src/core/err.d.ts
CHANGED
|
@@ -1,13 +1,36 @@
|
|
|
1
1
|
import type { HTTPErr, WrenchErr } from "@fabriktor/schema";
|
|
2
|
+
export declare const ClientErrKind: {
|
|
3
|
+
readonly AuthTokenProviderMissing: "auth_token_provider_missing";
|
|
4
|
+
readonly AuthTokenEmpty: "auth_token_empty";
|
|
5
|
+
readonly HTTPError: "http_error";
|
|
6
|
+
readonly HTTPRequestFailed: "http_request_failed";
|
|
7
|
+
readonly HTTPResponseInvalid: "http_response_invalid";
|
|
8
|
+
readonly Unknown: "unknown";
|
|
9
|
+
};
|
|
10
|
+
export type ClientErrKind = (typeof ClientErrKind)[keyof typeof ClientErrKind];
|
|
2
11
|
export type ClientErrOptions = {
|
|
3
|
-
|
|
12
|
+
kind: ClientErrKind;
|
|
4
13
|
msg: string;
|
|
14
|
+
status?: number;
|
|
5
15
|
app_err?: WrenchErr;
|
|
16
|
+
cause?: unknown;
|
|
6
17
|
};
|
|
7
18
|
export declare class ClientErr extends Error {
|
|
8
|
-
|
|
9
|
-
|
|
19
|
+
readonly kind: ClientErrKind;
|
|
20
|
+
readonly status?: number;
|
|
21
|
+
readonly app_err?: WrenchErr;
|
|
22
|
+
readonly cause?: unknown;
|
|
10
23
|
constructor(opts: ClientErrOptions);
|
|
11
24
|
}
|
|
12
|
-
export declare function
|
|
13
|
-
export declare function
|
|
25
|
+
export declare function errClient(opts: ClientErrOptions): ClientErr;
|
|
26
|
+
export declare function errFromHTTP(err: HTTPErr): ClientErr;
|
|
27
|
+
export declare function errAuthTokenProviderMissing(): ClientErr;
|
|
28
|
+
export declare function errAuthTokenEmpty(): ClientErr;
|
|
29
|
+
export declare function errHTTPRequestFailed(cause: unknown): ClientErr;
|
|
30
|
+
export declare function errHTTPResponseInvalid(cause?: unknown): ClientErr;
|
|
31
|
+
export declare function errUnknown(cause: unknown): ClientErr;
|
|
32
|
+
export declare function isClientErr(err: unknown): err is ClientErr;
|
|
33
|
+
export declare function isHTTPClientErr(err: unknown): err is ClientErr;
|
|
34
|
+
export declare function isUnauthorizedClientErr(err: unknown): boolean;
|
|
35
|
+
export declare function isNotFoundClientErr(err: unknown): boolean;
|
|
36
|
+
export declare function clientErrMessage(err: unknown): string;
|
package/dist/src/core/err.js
CHANGED
|
@@ -3,23 +3,101 @@
|
|
|
3
3
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
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
|
+
const msgUnknownClientErr = "Unknown client error.";
|
|
7
|
+
export const ClientErrKind = {
|
|
8
|
+
AuthTokenProviderMissing: "auth_token_provider_missing",
|
|
9
|
+
AuthTokenEmpty: "auth_token_empty",
|
|
10
|
+
HTTPError: "http_error",
|
|
11
|
+
HTTPRequestFailed: "http_request_failed",
|
|
12
|
+
HTTPResponseInvalid: "http_response_invalid",
|
|
13
|
+
Unknown: "unknown",
|
|
14
|
+
};
|
|
6
15
|
export class ClientErr extends Error {
|
|
7
|
-
|
|
16
|
+
kind;
|
|
17
|
+
status;
|
|
8
18
|
app_err;
|
|
19
|
+
cause;
|
|
9
20
|
constructor(opts) {
|
|
10
21
|
super(opts.msg);
|
|
11
22
|
this.name = new.target.name;
|
|
12
|
-
this.
|
|
23
|
+
this.kind = opts.kind;
|
|
24
|
+
this.status = opts.status;
|
|
13
25
|
this.app_err = opts.app_err;
|
|
26
|
+
this.cause = opts.cause;
|
|
14
27
|
}
|
|
15
28
|
}
|
|
16
|
-
export function
|
|
29
|
+
export function errClient(opts) {
|
|
17
30
|
return new ClientErr(opts);
|
|
18
31
|
}
|
|
19
|
-
export function
|
|
20
|
-
return
|
|
21
|
-
|
|
32
|
+
export function errFromHTTP(err) {
|
|
33
|
+
return errClient({
|
|
34
|
+
kind: ClientErrKind.HTTPError,
|
|
35
|
+
status: err.code,
|
|
22
36
|
msg: err.msg,
|
|
23
37
|
app_err: err.app_err,
|
|
24
38
|
});
|
|
25
39
|
}
|
|
40
|
+
export function errAuthTokenProviderMissing() {
|
|
41
|
+
return errClient({
|
|
42
|
+
kind: ClientErrKind.AuthTokenProviderMissing,
|
|
43
|
+
msg: "Authenticated client method requires a token provider.",
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
export function errAuthTokenEmpty() {
|
|
47
|
+
return errClient({
|
|
48
|
+
kind: ClientErrKind.AuthTokenEmpty,
|
|
49
|
+
msg: "Authenticated client method received an empty token.",
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
export function errHTTPRequestFailed(cause) {
|
|
53
|
+
return errClient({
|
|
54
|
+
kind: ClientErrKind.HTTPRequestFailed,
|
|
55
|
+
msg: "HTTP request failed.",
|
|
56
|
+
cause,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
export function errHTTPResponseInvalid(cause) {
|
|
60
|
+
return errClient({
|
|
61
|
+
kind: ClientErrKind.HTTPResponseInvalid,
|
|
62
|
+
msg: "HTTP response is invalid.",
|
|
63
|
+
cause,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
export function errUnknown(cause) {
|
|
67
|
+
if (isClientErr(cause)) {
|
|
68
|
+
return cause;
|
|
69
|
+
}
|
|
70
|
+
if (cause instanceof Error) {
|
|
71
|
+
return errClient({
|
|
72
|
+
kind: ClientErrKind.Unknown,
|
|
73
|
+
msg: cause.message,
|
|
74
|
+
cause,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return errClient({
|
|
78
|
+
kind: ClientErrKind.Unknown,
|
|
79
|
+
msg: msgUnknownClientErr,
|
|
80
|
+
cause,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
export function isClientErr(err) {
|
|
84
|
+
return err instanceof ClientErr;
|
|
85
|
+
}
|
|
86
|
+
export function isHTTPClientErr(err) {
|
|
87
|
+
return isClientErr(err) && err.kind === ClientErrKind.HTTPError;
|
|
88
|
+
}
|
|
89
|
+
export function isUnauthorizedClientErr(err) {
|
|
90
|
+
return isClientErr(err) && err.status === 401;
|
|
91
|
+
}
|
|
92
|
+
export function isNotFoundClientErr(err) {
|
|
93
|
+
return isClientErr(err) && err.status === 404;
|
|
94
|
+
}
|
|
95
|
+
export function clientErrMessage(err) {
|
|
96
|
+
if (isClientErr(err)) {
|
|
97
|
+
return err.message;
|
|
98
|
+
}
|
|
99
|
+
if (err instanceof Error) {
|
|
100
|
+
return err.message;
|
|
101
|
+
}
|
|
102
|
+
return msgUnknownClientErr;
|
|
103
|
+
}
|
package/dist/src/core/http.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
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 { MimeJSON, } from "@fabriktor/schema";
|
|
7
|
-
import {
|
|
7
|
+
import { errFromHTTP, errHTTPRequestFailed, errHTTPResponseInvalid, } from "./err.js";
|
|
8
8
|
const headerAuthorization = "authorization";
|
|
9
9
|
const headerContentType = "content-type";
|
|
10
10
|
const prefixBearer = "Bearer";
|
|
@@ -19,18 +19,29 @@ export class HTTPClient {
|
|
|
19
19
|
this.fetcher = opts.fetcher;
|
|
20
20
|
}
|
|
21
21
|
async do(opts) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
let res;
|
|
23
|
+
try {
|
|
24
|
+
res = await this.fetcher.fetch(url(opts.base_url, opts.path), {
|
|
25
|
+
method: opts.method,
|
|
26
|
+
headers: headers(opts),
|
|
27
|
+
body: body(opts.body),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
throw errHTTPRequestFailed(err);
|
|
32
|
+
}
|
|
27
33
|
if (!res.ok) {
|
|
28
34
|
return await fail(res);
|
|
29
35
|
}
|
|
30
36
|
if (res.body === null) {
|
|
31
37
|
return undefined;
|
|
32
38
|
}
|
|
33
|
-
|
|
39
|
+
try {
|
|
40
|
+
return (await res.json());
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
throw errHTTPResponseInvalid(err);
|
|
44
|
+
}
|
|
34
45
|
}
|
|
35
46
|
}
|
|
36
47
|
export function newHTTPClient(opts) {
|
|
@@ -55,16 +66,25 @@ function body(v) {
|
|
|
55
66
|
return v === undefined ? undefined : JSON.stringify(v);
|
|
56
67
|
}
|
|
57
68
|
async function fail(res) {
|
|
58
|
-
const txt = await
|
|
59
|
-
|
|
69
|
+
const txt = await text(res);
|
|
70
|
+
throw errFromHTTP(httpErr(res, txt));
|
|
71
|
+
}
|
|
72
|
+
async function text(res) {
|
|
73
|
+
try {
|
|
74
|
+
return await res.text();
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
throw errHTTPResponseInvalid(err);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function httpErr(res, txt) {
|
|
60
81
|
try {
|
|
61
|
-
|
|
82
|
+
return JSON.parse(txt);
|
|
62
83
|
}
|
|
63
84
|
catch {
|
|
64
|
-
|
|
85
|
+
return {
|
|
65
86
|
code: res.status,
|
|
66
87
|
msg: txt || res.statusText || res.status.toString(),
|
|
67
88
|
};
|
|
68
89
|
}
|
|
69
|
-
throw newClientErrFromHTTP(out);
|
|
70
90
|
}
|
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,56 +1,48 @@
|
|
|
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
|
-
|
|
15
|
-
} & PLUsersForgotPassword;
|
|
16
|
-
export type SendSignInLinkOptions = {
|
|
17
|
-
base_url: string;
|
|
18
|
-
} & PLUsersSignInLink;
|
|
19
|
-
export type MatchOptions = AuthOptions & PLUsersContactList;
|
|
20
|
-
export type MatchResult = {
|
|
21
|
-
users: User[];
|
|
22
|
-
};
|
|
23
|
-
export type SearchOptions = AuthOptions & {
|
|
7
|
+
export type ResolveUsernameOptions = PLUsersResolveUsername;
|
|
8
|
+
export type ForgotPasswordOptions = PLUsersForgotPassword;
|
|
9
|
+
export type SendSignInLinkOptions = PLUsersSignInLink;
|
|
10
|
+
export type MatchOptions = PLUsersContactList;
|
|
11
|
+
export type SearchOptions = {
|
|
24
12
|
q: string;
|
|
25
13
|
limit?: number;
|
|
26
14
|
};
|
|
27
|
-
export type GetByUIDOptions =
|
|
15
|
+
export type GetByUIDOptions = {
|
|
28
16
|
uid: string;
|
|
29
17
|
};
|
|
30
18
|
export interface UsersOperator {
|
|
31
19
|
bootstrap(opts: BootstrapOptions): Promise<Op<UpsertResult>>;
|
|
32
|
-
sync(
|
|
33
|
-
sendEmailVerification(
|
|
20
|
+
sync(): Promise<OperationResult>;
|
|
21
|
+
sendEmailVerification(): Promise<void>;
|
|
34
22
|
forgotPassword(opts: ForgotPasswordOptions): Promise<void>;
|
|
35
23
|
sendSignInLink(opts: SendSignInLinkOptions): Promise<void>;
|
|
36
24
|
resolveUsername(opts: ResolveUsernameOptions): Promise<Op<string>>;
|
|
37
|
-
match(opts: MatchOptions): Promise<Op<
|
|
25
|
+
match(opts: MatchOptions): Promise<Op<User[]>>;
|
|
38
26
|
search(opts: SearchOptions): Promise<Op<User[]>>;
|
|
39
27
|
getByUID(opts: GetByUIDOptions): Promise<Op<User>>;
|
|
40
28
|
}
|
|
41
29
|
export type UsersClientOptions = {
|
|
42
30
|
http: HTTPDoer;
|
|
31
|
+
base_url: string;
|
|
32
|
+
get_token?: TokenProvider;
|
|
43
33
|
};
|
|
44
34
|
export declare class UsersClient implements UsersOperator {
|
|
45
35
|
private http;
|
|
36
|
+
private base_url;
|
|
37
|
+
private get_token?;
|
|
46
38
|
constructor(opts: UsersClientOptions);
|
|
47
39
|
bootstrap(opts: BootstrapOptions): Promise<Op<UpsertResult>>;
|
|
48
|
-
sync(
|
|
49
|
-
sendEmailVerification(
|
|
40
|
+
sync(): Promise<OperationResult>;
|
|
41
|
+
sendEmailVerification(): Promise<void>;
|
|
50
42
|
forgotPassword(opts: ForgotPasswordOptions): Promise<void>;
|
|
51
43
|
sendSignInLink(opts: SendSignInLinkOptions): Promise<void>;
|
|
52
44
|
resolveUsername(opts: ResolveUsernameOptions): Promise<Op<string>>;
|
|
53
|
-
match(opts: MatchOptions): Promise<Op<
|
|
45
|
+
match(opts: MatchOptions): Promise<Op<User[]>>;
|
|
54
46
|
search(opts: SearchOptions): Promise<Op<User[]>>;
|
|
55
47
|
getByUID(opts: GetByUIDOptions): Promise<Op<User>>;
|
|
56
48
|
}
|
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
|
}
|