@fabriktor/client 0.0.96 → 0.0.98
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/http.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { IdempotencyStore } from "./idempotency.js";
|
|
|
3
3
|
export declare const headerAuthorization = "authorization";
|
|
4
4
|
export declare const headerContentType = "content-type";
|
|
5
5
|
export declare const headerContentDisposition = "content-disposition";
|
|
6
|
+
export declare const headerDate = "date";
|
|
6
7
|
export declare const prefixBearer = "Bearer";
|
|
7
8
|
export type Method = typeof HTTPMethodGet | typeof HTTPMethodPost | typeof HTTPMethodPatch | typeof HTTPMethodDelete;
|
|
8
9
|
export type RequestOptions = {
|
|
@@ -33,6 +34,8 @@ export interface HTTPDoer {
|
|
|
33
34
|
export type HTTPClientOptions = {
|
|
34
35
|
fetcher: Fetcher;
|
|
35
36
|
idempotency: IdempotencyStore;
|
|
37
|
+
cache?: RequestCache;
|
|
38
|
+
on_response?: (headers: Headers) => void;
|
|
36
39
|
};
|
|
37
40
|
export declare class WebFetcher implements Fetcher {
|
|
38
41
|
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
@@ -40,6 +43,8 @@ export declare class WebFetcher implements Fetcher {
|
|
|
40
43
|
export declare class HTTPClient implements HTTPDoer {
|
|
41
44
|
private fetcher;
|
|
42
45
|
private idempotency;
|
|
46
|
+
private readonly cache?;
|
|
47
|
+
private readonly onResponse?;
|
|
43
48
|
constructor(opts: HTTPClientOptions);
|
|
44
49
|
do<T, R>(opts: HTTPOptions<T>): Promise<R>;
|
|
45
50
|
doFile<T>(opts: HTTPOptions<T>): Promise<HTTPFile>;
|
package/dist/src/core/http.js
CHANGED
|
@@ -9,6 +9,7 @@ import { applyIdempotencyHeader, DefaultIdempotencyStore, } from "./idempotency.
|
|
|
9
9
|
export const headerAuthorization = "authorization";
|
|
10
10
|
export const headerContentType = "content-type";
|
|
11
11
|
export const headerContentDisposition = "content-disposition";
|
|
12
|
+
export const headerDate = "date";
|
|
12
13
|
export const prefixBearer = "Bearer";
|
|
13
14
|
export class WebFetcher {
|
|
14
15
|
async fetch(input, init) {
|
|
@@ -21,9 +22,13 @@ function noContent(res) {
|
|
|
21
22
|
export class HTTPClient {
|
|
22
23
|
fetcher;
|
|
23
24
|
idempotency;
|
|
25
|
+
cache;
|
|
26
|
+
onResponse;
|
|
24
27
|
constructor(opts) {
|
|
25
28
|
this.fetcher = opts.fetcher;
|
|
26
29
|
this.idempotency = opts.idempotency;
|
|
30
|
+
this.cache = opts.cache;
|
|
31
|
+
this.onResponse = opts.on_response;
|
|
27
32
|
}
|
|
28
33
|
async do(opts) {
|
|
29
34
|
const res = await this.response(opts);
|
|
@@ -71,6 +76,7 @@ export class HTTPClient {
|
|
|
71
76
|
headers: h,
|
|
72
77
|
body: requestBody,
|
|
73
78
|
signal: opts.signal,
|
|
79
|
+
...(this.cache === undefined ? {} : { cache: this.cache }),
|
|
74
80
|
});
|
|
75
81
|
}
|
|
76
82
|
catch (err) {
|
|
@@ -82,6 +88,7 @@ export class HTTPClient {
|
|
|
82
88
|
if (!res.ok) {
|
|
83
89
|
return await fail(res);
|
|
84
90
|
}
|
|
91
|
+
this.onResponse?.(res.headers);
|
|
85
92
|
return res;
|
|
86
93
|
}
|
|
87
94
|
}
|
|
@@ -89,6 +96,8 @@ export function newHTTPClient(opts) {
|
|
|
89
96
|
return new HTTPClient({
|
|
90
97
|
fetcher: opts?.fetcher ?? new WebFetcher(),
|
|
91
98
|
idempotency: opts?.idempotency ?? new DefaultIdempotencyStore(),
|
|
99
|
+
cache: opts?.cache,
|
|
100
|
+
on_response: opts?.on_response,
|
|
92
101
|
});
|
|
93
102
|
}
|
|
94
103
|
function url(base, path) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ClientAvailability, type InClientAvailability, type InRoute, type InRouteTeam, type InTag, type InTracking, type OperationResult, type PLRoutesAvailability, type PLRoutesDesignation, type Route, type RouteTeam, type RPRoutesAvailability, type Tag, type Tracking } from "@fabriktor/schema";
|
|
2
2
|
import type { TokenProvider } from "../core/auth.js";
|
|
3
3
|
import type { DeleteOneOptionsCRUD, FindOneOptionsCRUD, InsertOneOptionsCRUD, OperationResultOf, QueryOptionsCRUD, ReplaceOneOptionsCRUD, SearchManyOptionsCRUD, SearchResultOf } from "../core/crud.js";
|
|
4
|
-
import type { HTTPDoer } from "../core/http.js";
|
|
4
|
+
import type { HTTPDoer, RequestOptions } from "../core/http.js";
|
|
5
5
|
import type { CompletePayload } from "../core/type.js";
|
|
6
6
|
export type GetAvailabilityOptions = CompletePayload<PLRoutesAvailability>;
|
|
7
7
|
export type GetDesignationOptions = CompletePayload<PLRoutesDesignation>;
|
|
@@ -38,8 +38,8 @@ export interface RoutesOperator {
|
|
|
38
38
|
replaceOneRouteTeam(opts: ReplaceOneOptionsCRUD<InRouteTeam>): Promise<OperationResult>;
|
|
39
39
|
deleteOneRouteTeam(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
|
|
40
40
|
searchManyRouteTeams(opts?: SearchManyOptionsCRUD): Promise<OperationResultOf<SearchResultOf<RouteTeam>>>;
|
|
41
|
-
getAvailability(opts: GetAvailabilityOptions): Promise<OperationResultOf<RPRoutesAvailability>>;
|
|
42
|
-
getDesignation(opts: GetDesignationOptions): Promise<OperationResultOf<Route[]>>;
|
|
41
|
+
getAvailability(opts: GetAvailabilityOptions, request?: RequestOptions): Promise<OperationResultOf<RPRoutesAvailability>>;
|
|
42
|
+
getDesignation(opts: GetDesignationOptions, request?: RequestOptions): Promise<OperationResultOf<Route[]>>;
|
|
43
43
|
}
|
|
44
44
|
export declare class RoutesClient implements RoutesOperator {
|
|
45
45
|
private routes;
|
|
@@ -78,7 +78,7 @@ export declare class RoutesClient implements RoutesOperator {
|
|
|
78
78
|
replaceOneRouteTeam(opts: ReplaceOneOptionsCRUD<InRouteTeam>): Promise<OperationResult>;
|
|
79
79
|
deleteOneRouteTeam(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
|
|
80
80
|
searchManyRouteTeams(opts?: SearchManyOptionsCRUD): Promise<OperationResultOf<SearchResultOf<RouteTeam>>>;
|
|
81
|
-
getAvailability(opts: GetAvailabilityOptions): Promise<OperationResultOf<RPRoutesAvailability>>;
|
|
82
|
-
getDesignation(opts: GetDesignationOptions): Promise<OperationResultOf<Route[]>>;
|
|
81
|
+
getAvailability(opts: GetAvailabilityOptions, request?: RequestOptions): Promise<OperationResultOf<RPRoutesAvailability>>;
|
|
82
|
+
getDesignation(opts: GetDesignationOptions, request?: RequestOptions): Promise<OperationResultOf<Route[]>>;
|
|
83
83
|
}
|
|
84
84
|
export declare function newRoutesClient(opts: RoutesClientOptions): RoutesClient;
|
|
@@ -137,7 +137,7 @@ export class RoutesClient {
|
|
|
137
137
|
async searchManyRouteTeams(opts) {
|
|
138
138
|
return await this.route_teams.searchMany(opts);
|
|
139
139
|
}
|
|
140
|
-
async getAvailability(opts) {
|
|
140
|
+
async getAvailability(opts, request) {
|
|
141
141
|
const token = await requiredToken(this.get_token);
|
|
142
142
|
return await this.http.do({
|
|
143
143
|
base_url: this.base_url,
|
|
@@ -145,9 +145,11 @@ export class RoutesClient {
|
|
|
145
145
|
method: HTTPMethodPost,
|
|
146
146
|
token,
|
|
147
147
|
body: opts,
|
|
148
|
+
signal: request?.signal,
|
|
149
|
+
idempotency_key: request?.idempotency_key,
|
|
148
150
|
});
|
|
149
151
|
}
|
|
150
|
-
async getDesignation(opts) {
|
|
152
|
+
async getDesignation(opts, request) {
|
|
151
153
|
const token = await requiredToken(this.get_token);
|
|
152
154
|
return await this.http.do({
|
|
153
155
|
base_url: this.base_url,
|
|
@@ -155,6 +157,8 @@ export class RoutesClient {
|
|
|
155
157
|
method: HTTPMethodPost,
|
|
156
158
|
token,
|
|
157
159
|
body: opts,
|
|
160
|
+
signal: request?.signal,
|
|
161
|
+
idempotency_key: request?.idempotency_key,
|
|
158
162
|
});
|
|
159
163
|
}
|
|
160
164
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type InSummary, type InWeekSheet, type OperationResult, type PLTimesheetsApprove, type PLTimesheetsSync, type Punch, type Summary, type WeekSheet } from "@fabriktor/schema";
|
|
2
2
|
import type { TokenProvider } from "../core/auth.js";
|
|
3
3
|
import type { DeleteOneOptionsCRUD, FindOneOptionsCRUD, OperationResultOf, QueryOptionsCRUD, ReplaceOneOptionsCRUD } from "../core/crud.js";
|
|
4
|
-
import type { HTTPDoer } from "../core/http.js";
|
|
4
|
+
import type { HTTPDoer, RequestOptions } from "../core/http.js";
|
|
5
5
|
import type { CompletePayload } from "../core/type.js";
|
|
6
|
-
export type ApproveTimesheetsOptions = CompletePayload<PLTimesheetsApprove>;
|
|
6
|
+
export type ApproveTimesheetsOptions = CompletePayload<PLTimesheetsApprove> & Pick<RequestOptions, "idempotency_key" | "signal">;
|
|
7
7
|
export type SyncTimesheetsOptions = Omit<CompletePayload<PLTimesheetsSync>, "to_ids" | "to_owner_ids"> & Partial<Pick<PLTimesheetsSync, "to_ids" | "to_owner_ids">>;
|
|
8
8
|
export type PunchTimesheetOptions = Punch;
|
|
9
9
|
export type TimesheetsClientOptions = {
|
|
@@ -64,9 +64,10 @@ export class TimesheetsClient {
|
|
|
64
64
|
path: weekSheetPath(PathTimesheetsApprove),
|
|
65
65
|
method: HTTPMethodPost,
|
|
66
66
|
token,
|
|
67
|
-
body: opts,
|
|
67
|
+
body: { ids: opts.ids, employer_id: opts.employer_id },
|
|
68
68
|
// Each intentional action is distinct. Never replay a timed-out punch.
|
|
69
|
-
idempotency_key: newIdempotencyKey(),
|
|
69
|
+
idempotency_key: opts.idempotency_key ?? newIdempotencyKey(),
|
|
70
|
+
signal: opts.signal,
|
|
70
71
|
});
|
|
71
72
|
}
|
|
72
73
|
async sync(opts) {
|