@testerpaykit/api-client 1.7.0 → 3.1.0
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/CHANGELOG.md +37 -0
- package/dist/index.d.mts +209 -16
- package/dist/index.d.ts +209 -16
- package/dist/index.js +101 -19
- package/dist/index.mjs +97 -18
- package/package.json +1 -1
- package/src/TesterPayKitApiClient.ts +161 -28
- package/src/compensation.ts +59 -0
- package/src/index.ts +1 -0
- package/tests/TesterPayKitApiClient.test.ts +82 -1
package/dist/index.js
CHANGED
|
@@ -30,31 +30,77 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
|
|
33
|
+
ClientOutdatedError: () => ClientOutdatedError,
|
|
34
|
+
TPK_CLIENT_HEADER: () => TPK_CLIENT_HEADER,
|
|
35
|
+
TesterPayKitApiClient: () => TesterPayKitApiClient,
|
|
36
|
+
parseClientOutdated: () => parseClientOutdated
|
|
34
37
|
});
|
|
35
38
|
module.exports = __toCommonJS(index_exports);
|
|
36
39
|
|
|
37
40
|
// src/TesterPayKitApiClient.ts
|
|
38
41
|
var import_axios = __toESM(require("axios"));
|
|
39
42
|
var import_core = require("@testerpaykit/core");
|
|
43
|
+
var TPK_CLIENT_HEADER = "X-TPK-Client";
|
|
44
|
+
var ClientOutdatedError = class extends Error {
|
|
45
|
+
constructor(info) {
|
|
46
|
+
super(info.message ?? "TesterPayKit client is too old for the server.");
|
|
47
|
+
this.info = info;
|
|
48
|
+
this.code = "TPK_CLIENT_OUTDATED";
|
|
49
|
+
this.name = "ClientOutdatedError";
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
function parseClientOutdated(status, body) {
|
|
53
|
+
if (status !== 426 || typeof body !== "object" || body === null) return null;
|
|
54
|
+
const b = body;
|
|
55
|
+
if (b.error !== "client_outdated") return null;
|
|
56
|
+
const str = (v) => typeof v === "string" ? v : null;
|
|
57
|
+
return { kind: str(b.kind), min: str(b.min), yours: str(b.yours), message: str(b.message) };
|
|
58
|
+
}
|
|
40
59
|
var TesterPayKitApiClient = class {
|
|
41
60
|
constructor(config) {
|
|
61
|
+
/**
|
|
62
|
+
* Called on any 403 `phone_required` / `approval_required` answer: the
|
|
63
|
+
* tester is not (or no longer) cleared to report. SDKs hide their
|
|
64
|
+
* tester UI on it. The request still rejects as before.
|
|
65
|
+
*/
|
|
66
|
+
this.onTesterGate = null;
|
|
67
|
+
/**
|
|
68
|
+
* Called once, on the first 426 `client_outdated` answer. From then on
|
|
69
|
+
* this client sends nothing: every request rejects with
|
|
70
|
+
* [ClientOutdatedError] before it reaches the network.
|
|
71
|
+
*/
|
|
72
|
+
this.onClientOutdated = null;
|
|
73
|
+
this.outdated = null;
|
|
42
74
|
this.apiKey = config.apiKey;
|
|
43
75
|
this.tokenManager = config.tokenManager || new import_core.TokenManager();
|
|
76
|
+
const headers = {
|
|
77
|
+
"Content-Type": "application/json",
|
|
78
|
+
"X-API-Key": this.apiKey
|
|
79
|
+
};
|
|
80
|
+
if (config.clientHeader) headers[TPK_CLIENT_HEADER] = config.clientHeader;
|
|
44
81
|
this.client = import_axios.default.create({
|
|
45
82
|
baseURL: config.baseURL || "https://api.testerpaykit.com",
|
|
46
|
-
headers
|
|
47
|
-
"Content-Type": "application/json",
|
|
48
|
-
"X-API-Key": this.apiKey
|
|
49
|
-
}
|
|
83
|
+
headers
|
|
50
84
|
});
|
|
51
85
|
this.setupInterceptors();
|
|
52
86
|
}
|
|
87
|
+
/** Set after a 426 `client_outdated`; null while the server serves us. */
|
|
88
|
+
get clientOutdated() {
|
|
89
|
+
return this.outdated;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Blocks this client as if it had received the 426 itself (an earlier
|
|
93
|
+
* client in the same app run did). Does not call [onClientOutdated].
|
|
94
|
+
*/
|
|
95
|
+
markClientOutdated(info) {
|
|
96
|
+
this.outdated ?? (this.outdated = info);
|
|
97
|
+
}
|
|
53
98
|
/**
|
|
54
99
|
* Setup request/response interceptors for JWT authentication.
|
|
55
100
|
*/
|
|
56
101
|
setupInterceptors() {
|
|
57
102
|
this.client.interceptors.request.use(async (config) => {
|
|
103
|
+
if (this.outdated) throw new ClientOutdatedError(this.outdated);
|
|
58
104
|
const token = await this.tokenManager.ensureValidToken();
|
|
59
105
|
if (token) {
|
|
60
106
|
config.headers.Authorization = `Bearer ${token}`;
|
|
@@ -67,6 +113,21 @@ var TesterPayKitApiClient = class {
|
|
|
67
113
|
if (error.response?.status === 401) {
|
|
68
114
|
this.tokenManager.clear();
|
|
69
115
|
}
|
|
116
|
+
const outdated = parseClientOutdated(error.response?.status, error.response?.data);
|
|
117
|
+
if (outdated && !this.outdated) {
|
|
118
|
+
this.outdated = outdated;
|
|
119
|
+
try {
|
|
120
|
+
this.onClientOutdated?.(outdated);
|
|
121
|
+
} catch {
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const code = error.response?.data?.error;
|
|
125
|
+
if (error.response?.status === 403 && (code === "phone_required" || code === "approval_required")) {
|
|
126
|
+
try {
|
|
127
|
+
this.onTesterGate?.(code);
|
|
128
|
+
} catch {
|
|
129
|
+
}
|
|
130
|
+
}
|
|
70
131
|
return Promise.reject(error);
|
|
71
132
|
}
|
|
72
133
|
);
|
|
@@ -464,6 +525,35 @@ var TesterPayKitApiClient = class {
|
|
|
464
525
|
);
|
|
465
526
|
return response.data;
|
|
466
527
|
}
|
|
528
|
+
/**
|
|
529
|
+
* POST /v1/testers/me/phone/link — a short-lived code for confirming this
|
|
530
|
+
* install in the TPK app (decision 2026-11-10, replaces the SMS dialog).
|
|
531
|
+
* Open `appUrl` (TPK app installed) or `url` (web page with an install
|
|
532
|
+
* hint); the person allows it there, then GET /v1/testers/me/profile
|
|
533
|
+
* reports the install as confirmed.
|
|
534
|
+
*/
|
|
535
|
+
async createAppLink(input) {
|
|
536
|
+
const response = await this.client.post(
|
|
537
|
+
"/v1/testers/me/phone/link",
|
|
538
|
+
input
|
|
539
|
+
);
|
|
540
|
+
return response.data;
|
|
541
|
+
}
|
|
542
|
+
async getCompensation() {
|
|
543
|
+
return (await this.client.get("/v1/testers/me/compensation")).data;
|
|
544
|
+
}
|
|
545
|
+
async recordPaidWork(command) {
|
|
546
|
+
return (await this.client.post("/v1/testers/me/compensation", command)).data;
|
|
547
|
+
}
|
|
548
|
+
async registerCompensationPush(registration) {
|
|
549
|
+
await this.client.post("/v1/testers/me/compensation", { action: "push", ...registration });
|
|
550
|
+
}
|
|
551
|
+
async getPayoutAccount() {
|
|
552
|
+
return (await this.client.get("/v1/testers/me/payout-account")).data;
|
|
553
|
+
}
|
|
554
|
+
async createPayoutAccountLink() {
|
|
555
|
+
return (await this.client.post("/v1/testers/me/payout-account")).data;
|
|
556
|
+
}
|
|
467
557
|
/** GET /v1/testers/me/points — current point balance + breakdown. */
|
|
468
558
|
async getMyPoints() {
|
|
469
559
|
const response = await this.client.get(
|
|
@@ -536,7 +626,7 @@ var TesterPayKitApiClient = class {
|
|
|
536
626
|
*
|
|
537
627
|
* RAG over the project's knowledge-base markdown files. Embeds the
|
|
538
628
|
* question, retrieves top-K nearest chunks via pgvector cosine
|
|
539
|
-
* similarity, and asks gpt-
|
|
629
|
+
* similarity, and asks gpt-6-luna to synthesise an answer that
|
|
540
630
|
* STRICTLY cites those chunks. Answer language tracks the
|
|
541
631
|
* question (English / German).
|
|
542
632
|
*
|
|
@@ -580,17 +670,6 @@ var TesterPayKitApiClient = class {
|
|
|
580
670
|
);
|
|
581
671
|
return response.data;
|
|
582
672
|
}
|
|
583
|
-
/**
|
|
584
|
-
* POST /v1/session-feedback
|
|
585
|
-
* Submit end-of-session feedback (rating, comments, etc.).
|
|
586
|
-
*/
|
|
587
|
-
async submitSessionEndFeedback(payload) {
|
|
588
|
-
const response = await this.client.post(
|
|
589
|
-
"/v1/session-feedback",
|
|
590
|
-
payload
|
|
591
|
-
);
|
|
592
|
-
return response.data;
|
|
593
|
-
}
|
|
594
673
|
/**
|
|
595
674
|
* Upload an attachment directly (not tied to a specific bug report).
|
|
596
675
|
* POST /v1/attachments — alternate path from the contract alongside
|
|
@@ -639,7 +718,7 @@ var TesterPayKitApiClient = class {
|
|
|
639
718
|
* Contract: wire.bug_reports.voiceExtractBugFields
|
|
640
719
|
*
|
|
641
720
|
* Sends base64-encoded audio to the server. The server runs Whisper
|
|
642
|
-
* (transcription) + gpt-
|
|
721
|
+
* (transcription) + gpt-6-luna (structured extraction) and returns
|
|
643
722
|
* pre-filled bug-report fields in the tester's language.
|
|
644
723
|
*
|
|
645
724
|
* Wire body uses snake_case per contract. Timeout is 60 s because
|
|
@@ -703,5 +782,8 @@ function assertSessionId(sessionId, op) {
|
|
|
703
782
|
}
|
|
704
783
|
// Annotate the CommonJS export names for ESM import in node:
|
|
705
784
|
0 && (module.exports = {
|
|
706
|
-
|
|
785
|
+
ClientOutdatedError,
|
|
786
|
+
TPK_CLIENT_HEADER,
|
|
787
|
+
TesterPayKitApiClient,
|
|
788
|
+
parseClientOutdated
|
|
707
789
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -3,24 +3,67 @@ import axios from "axios";
|
|
|
3
3
|
import {
|
|
4
4
|
TokenManager
|
|
5
5
|
} from "@testerpaykit/core";
|
|
6
|
+
var TPK_CLIENT_HEADER = "X-TPK-Client";
|
|
7
|
+
var ClientOutdatedError = class extends Error {
|
|
8
|
+
constructor(info) {
|
|
9
|
+
super(info.message ?? "TesterPayKit client is too old for the server.");
|
|
10
|
+
this.info = info;
|
|
11
|
+
this.code = "TPK_CLIENT_OUTDATED";
|
|
12
|
+
this.name = "ClientOutdatedError";
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
function parseClientOutdated(status, body) {
|
|
16
|
+
if (status !== 426 || typeof body !== "object" || body === null) return null;
|
|
17
|
+
const b = body;
|
|
18
|
+
if (b.error !== "client_outdated") return null;
|
|
19
|
+
const str = (v) => typeof v === "string" ? v : null;
|
|
20
|
+
return { kind: str(b.kind), min: str(b.min), yours: str(b.yours), message: str(b.message) };
|
|
21
|
+
}
|
|
6
22
|
var TesterPayKitApiClient = class {
|
|
7
23
|
constructor(config) {
|
|
24
|
+
/**
|
|
25
|
+
* Called on any 403 `phone_required` / `approval_required` answer: the
|
|
26
|
+
* tester is not (or no longer) cleared to report. SDKs hide their
|
|
27
|
+
* tester UI on it. The request still rejects as before.
|
|
28
|
+
*/
|
|
29
|
+
this.onTesterGate = null;
|
|
30
|
+
/**
|
|
31
|
+
* Called once, on the first 426 `client_outdated` answer. From then on
|
|
32
|
+
* this client sends nothing: every request rejects with
|
|
33
|
+
* [ClientOutdatedError] before it reaches the network.
|
|
34
|
+
*/
|
|
35
|
+
this.onClientOutdated = null;
|
|
36
|
+
this.outdated = null;
|
|
8
37
|
this.apiKey = config.apiKey;
|
|
9
38
|
this.tokenManager = config.tokenManager || new TokenManager();
|
|
39
|
+
const headers = {
|
|
40
|
+
"Content-Type": "application/json",
|
|
41
|
+
"X-API-Key": this.apiKey
|
|
42
|
+
};
|
|
43
|
+
if (config.clientHeader) headers[TPK_CLIENT_HEADER] = config.clientHeader;
|
|
10
44
|
this.client = axios.create({
|
|
11
45
|
baseURL: config.baseURL || "https://api.testerpaykit.com",
|
|
12
|
-
headers
|
|
13
|
-
"Content-Type": "application/json",
|
|
14
|
-
"X-API-Key": this.apiKey
|
|
15
|
-
}
|
|
46
|
+
headers
|
|
16
47
|
});
|
|
17
48
|
this.setupInterceptors();
|
|
18
49
|
}
|
|
50
|
+
/** Set after a 426 `client_outdated`; null while the server serves us. */
|
|
51
|
+
get clientOutdated() {
|
|
52
|
+
return this.outdated;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Blocks this client as if it had received the 426 itself (an earlier
|
|
56
|
+
* client in the same app run did). Does not call [onClientOutdated].
|
|
57
|
+
*/
|
|
58
|
+
markClientOutdated(info) {
|
|
59
|
+
this.outdated ?? (this.outdated = info);
|
|
60
|
+
}
|
|
19
61
|
/**
|
|
20
62
|
* Setup request/response interceptors for JWT authentication.
|
|
21
63
|
*/
|
|
22
64
|
setupInterceptors() {
|
|
23
65
|
this.client.interceptors.request.use(async (config) => {
|
|
66
|
+
if (this.outdated) throw new ClientOutdatedError(this.outdated);
|
|
24
67
|
const token = await this.tokenManager.ensureValidToken();
|
|
25
68
|
if (token) {
|
|
26
69
|
config.headers.Authorization = `Bearer ${token}`;
|
|
@@ -33,6 +76,21 @@ var TesterPayKitApiClient = class {
|
|
|
33
76
|
if (error.response?.status === 401) {
|
|
34
77
|
this.tokenManager.clear();
|
|
35
78
|
}
|
|
79
|
+
const outdated = parseClientOutdated(error.response?.status, error.response?.data);
|
|
80
|
+
if (outdated && !this.outdated) {
|
|
81
|
+
this.outdated = outdated;
|
|
82
|
+
try {
|
|
83
|
+
this.onClientOutdated?.(outdated);
|
|
84
|
+
} catch {
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const code = error.response?.data?.error;
|
|
88
|
+
if (error.response?.status === 403 && (code === "phone_required" || code === "approval_required")) {
|
|
89
|
+
try {
|
|
90
|
+
this.onTesterGate?.(code);
|
|
91
|
+
} catch {
|
|
92
|
+
}
|
|
93
|
+
}
|
|
36
94
|
return Promise.reject(error);
|
|
37
95
|
}
|
|
38
96
|
);
|
|
@@ -430,6 +488,35 @@ var TesterPayKitApiClient = class {
|
|
|
430
488
|
);
|
|
431
489
|
return response.data;
|
|
432
490
|
}
|
|
491
|
+
/**
|
|
492
|
+
* POST /v1/testers/me/phone/link — a short-lived code for confirming this
|
|
493
|
+
* install in the TPK app (decision 2026-11-10, replaces the SMS dialog).
|
|
494
|
+
* Open `appUrl` (TPK app installed) or `url` (web page with an install
|
|
495
|
+
* hint); the person allows it there, then GET /v1/testers/me/profile
|
|
496
|
+
* reports the install as confirmed.
|
|
497
|
+
*/
|
|
498
|
+
async createAppLink(input) {
|
|
499
|
+
const response = await this.client.post(
|
|
500
|
+
"/v1/testers/me/phone/link",
|
|
501
|
+
input
|
|
502
|
+
);
|
|
503
|
+
return response.data;
|
|
504
|
+
}
|
|
505
|
+
async getCompensation() {
|
|
506
|
+
return (await this.client.get("/v1/testers/me/compensation")).data;
|
|
507
|
+
}
|
|
508
|
+
async recordPaidWork(command) {
|
|
509
|
+
return (await this.client.post("/v1/testers/me/compensation", command)).data;
|
|
510
|
+
}
|
|
511
|
+
async registerCompensationPush(registration) {
|
|
512
|
+
await this.client.post("/v1/testers/me/compensation", { action: "push", ...registration });
|
|
513
|
+
}
|
|
514
|
+
async getPayoutAccount() {
|
|
515
|
+
return (await this.client.get("/v1/testers/me/payout-account")).data;
|
|
516
|
+
}
|
|
517
|
+
async createPayoutAccountLink() {
|
|
518
|
+
return (await this.client.post("/v1/testers/me/payout-account")).data;
|
|
519
|
+
}
|
|
433
520
|
/** GET /v1/testers/me/points — current point balance + breakdown. */
|
|
434
521
|
async getMyPoints() {
|
|
435
522
|
const response = await this.client.get(
|
|
@@ -502,7 +589,7 @@ var TesterPayKitApiClient = class {
|
|
|
502
589
|
*
|
|
503
590
|
* RAG over the project's knowledge-base markdown files. Embeds the
|
|
504
591
|
* question, retrieves top-K nearest chunks via pgvector cosine
|
|
505
|
-
* similarity, and asks gpt-
|
|
592
|
+
* similarity, and asks gpt-6-luna to synthesise an answer that
|
|
506
593
|
* STRICTLY cites those chunks. Answer language tracks the
|
|
507
594
|
* question (English / German).
|
|
508
595
|
*
|
|
@@ -546,17 +633,6 @@ var TesterPayKitApiClient = class {
|
|
|
546
633
|
);
|
|
547
634
|
return response.data;
|
|
548
635
|
}
|
|
549
|
-
/**
|
|
550
|
-
* POST /v1/session-feedback
|
|
551
|
-
* Submit end-of-session feedback (rating, comments, etc.).
|
|
552
|
-
*/
|
|
553
|
-
async submitSessionEndFeedback(payload) {
|
|
554
|
-
const response = await this.client.post(
|
|
555
|
-
"/v1/session-feedback",
|
|
556
|
-
payload
|
|
557
|
-
);
|
|
558
|
-
return response.data;
|
|
559
|
-
}
|
|
560
636
|
/**
|
|
561
637
|
* Upload an attachment directly (not tied to a specific bug report).
|
|
562
638
|
* POST /v1/attachments — alternate path from the contract alongside
|
|
@@ -605,7 +681,7 @@ var TesterPayKitApiClient = class {
|
|
|
605
681
|
* Contract: wire.bug_reports.voiceExtractBugFields
|
|
606
682
|
*
|
|
607
683
|
* Sends base64-encoded audio to the server. The server runs Whisper
|
|
608
|
-
* (transcription) + gpt-
|
|
684
|
+
* (transcription) + gpt-6-luna (structured extraction) and returns
|
|
609
685
|
* pre-filled bug-report fields in the tester's language.
|
|
610
686
|
*
|
|
611
687
|
* Wire body uses snake_case per contract. Timeout is 60 s because
|
|
@@ -668,5 +744,8 @@ function assertSessionId(sessionId, op) {
|
|
|
668
744
|
}
|
|
669
745
|
}
|
|
670
746
|
export {
|
|
671
|
-
|
|
747
|
+
ClientOutdatedError,
|
|
748
|
+
TPK_CLIENT_HEADER,
|
|
749
|
+
TesterPayKitApiClient,
|
|
750
|
+
parseClientOutdated
|
|
672
751
|
};
|
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import axios, { AxiosInstance } from 'axios';
|
|
2
|
+
import type { CompensationWallet, PaidAssignment, WorkCommand, PushRegistration } from './compensation';
|
|
2
3
|
import {
|
|
3
4
|
IApiClient,
|
|
4
5
|
LoginRequest,
|
|
@@ -60,6 +61,51 @@ export interface ApiClientConfig {
|
|
|
60
61
|
baseURL?: string;
|
|
61
62
|
apiKey: string;
|
|
62
63
|
tokenManager?: TokenManager;
|
|
64
|
+
/**
|
|
65
|
+
* Sent as `X-TPK-Client` on every request, e.g. `expo/2.2.0` (decision
|
|
66
|
+
* 2026-11-14 "Mindestversion je Client-Art"). Default none: the server
|
|
67
|
+
* then serves the request without a version check.
|
|
68
|
+
*/
|
|
69
|
+
clientHeader?: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Request header a client identifies itself with (`<kind>/<version>`). */
|
|
73
|
+
export const TPK_CLIENT_HEADER = 'X-TPK-Client';
|
|
74
|
+
|
|
75
|
+
/** Body of a 426 `client_outdated` answer: this client is below the
|
|
76
|
+
* minimum version the server still serves. Fields are null when the
|
|
77
|
+
* request carried no `X-TPK-Client`. */
|
|
78
|
+
export interface ClientOutdatedInfo {
|
|
79
|
+
kind: string | null;
|
|
80
|
+
min: string | null;
|
|
81
|
+
yours: string | null;
|
|
82
|
+
message: string | null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Thrown instead of sending, for every request after a 426
|
|
87
|
+
* `client_outdated` (see `TesterPayKitApiClient.clientOutdated`). It has
|
|
88
|
+
* no `response`, so callers that retry on network errors keep their
|
|
89
|
+
* queued work for a newer build instead of dropping it.
|
|
90
|
+
*/
|
|
91
|
+
export class ClientOutdatedError extends Error {
|
|
92
|
+
readonly code = 'TPK_CLIENT_OUTDATED';
|
|
93
|
+
constructor(readonly info: ClientOutdatedInfo) {
|
|
94
|
+
super(info.message ?? 'TesterPayKit client is too old for the server.');
|
|
95
|
+
this.name = 'ClientOutdatedError';
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** The `client_outdated` body of a 426 answer, else null. */
|
|
100
|
+
export function parseClientOutdated(
|
|
101
|
+
status: number | undefined,
|
|
102
|
+
body: unknown,
|
|
103
|
+
): ClientOutdatedInfo | null {
|
|
104
|
+
if (status !== 426 || typeof body !== 'object' || body === null) return null;
|
|
105
|
+
const b = body as Record<string, unknown>;
|
|
106
|
+
if (b.error !== 'client_outdated') return null;
|
|
107
|
+
const str = (v: unknown) => (typeof v === 'string' ? v : null);
|
|
108
|
+
return { kind: str(b.kind), min: str(b.min), yours: str(b.yours), message: str(b.message) };
|
|
63
109
|
}
|
|
64
110
|
|
|
65
111
|
/**
|
|
@@ -70,21 +116,55 @@ export interface ApiClientConfig {
|
|
|
70
116
|
* - Request/response interceptors for auth headers
|
|
71
117
|
* - Integration with TokenManager for token lifecycle
|
|
72
118
|
*/
|
|
119
|
+
/** The tester gate's 403 codes (migrations 075 + 077). */
|
|
120
|
+
export type TesterGateReason = 'phone_required' | 'approval_required';
|
|
121
|
+
|
|
73
122
|
export class TesterPayKitApiClient implements IApiClient {
|
|
74
123
|
private client: AxiosInstance;
|
|
75
124
|
private tokenManager: TokenManager;
|
|
76
125
|
private apiKey: string;
|
|
77
126
|
|
|
127
|
+
/**
|
|
128
|
+
* Called on any 403 `phone_required` / `approval_required` answer: the
|
|
129
|
+
* tester is not (or no longer) cleared to report. SDKs hide their
|
|
130
|
+
* tester UI on it. The request still rejects as before.
|
|
131
|
+
*/
|
|
132
|
+
onTesterGate: ((reason: TesterGateReason) => void) | null = null;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Called once, on the first 426 `client_outdated` answer. From then on
|
|
136
|
+
* this client sends nothing: every request rejects with
|
|
137
|
+
* [ClientOutdatedError] before it reaches the network.
|
|
138
|
+
*/
|
|
139
|
+
onClientOutdated: ((info: ClientOutdatedInfo) => void) | null = null;
|
|
140
|
+
|
|
141
|
+
private outdated: ClientOutdatedInfo | null = null;
|
|
142
|
+
|
|
143
|
+
/** Set after a 426 `client_outdated`; null while the server serves us. */
|
|
144
|
+
get clientOutdated(): ClientOutdatedInfo | null {
|
|
145
|
+
return this.outdated;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Blocks this client as if it had received the 426 itself (an earlier
|
|
150
|
+
* client in the same app run did). Does not call [onClientOutdated].
|
|
151
|
+
*/
|
|
152
|
+
markClientOutdated(info: ClientOutdatedInfo): void {
|
|
153
|
+
this.outdated ??= info;
|
|
154
|
+
}
|
|
155
|
+
|
|
78
156
|
constructor(config: ApiClientConfig) {
|
|
79
157
|
this.apiKey = config.apiKey;
|
|
80
158
|
this.tokenManager = config.tokenManager || new TokenManager();
|
|
81
159
|
|
|
160
|
+
const headers: Record<string, string> = {
|
|
161
|
+
'Content-Type': 'application/json',
|
|
162
|
+
'X-API-Key': this.apiKey,
|
|
163
|
+
};
|
|
164
|
+
if (config.clientHeader) headers[TPK_CLIENT_HEADER] = config.clientHeader;
|
|
82
165
|
this.client = axios.create({
|
|
83
166
|
baseURL: config.baseURL || 'https://api.testerpaykit.com',
|
|
84
|
-
headers
|
|
85
|
-
'Content-Type': 'application/json',
|
|
86
|
-
'X-API-Key': this.apiKey,
|
|
87
|
-
},
|
|
167
|
+
headers,
|
|
88
168
|
});
|
|
89
169
|
|
|
90
170
|
this.setupInterceptors();
|
|
@@ -96,6 +176,8 @@ export class TesterPayKitApiClient implements IApiClient {
|
|
|
96
176
|
private setupInterceptors(): void {
|
|
97
177
|
// Request interceptor: Add auth token to every request
|
|
98
178
|
this.client.interceptors.request.use(async (config) => {
|
|
179
|
+
// Too old for the server: nothing more goes out in this app run.
|
|
180
|
+
if (this.outdated) throw new ClientOutdatedError(this.outdated);
|
|
99
181
|
const token = await this.tokenManager.ensureValidToken();
|
|
100
182
|
if (token) {
|
|
101
183
|
config.headers.Authorization = `Bearer ${token}`;
|
|
@@ -111,6 +193,26 @@ export class TesterPayKitApiClient implements IApiClient {
|
|
|
111
193
|
// Token expired or invalid, clear tokens
|
|
112
194
|
this.tokenManager.clear();
|
|
113
195
|
}
|
|
196
|
+
const outdated = parseClientOutdated(error.response?.status, error.response?.data);
|
|
197
|
+
if (outdated && !this.outdated) {
|
|
198
|
+
this.outdated = outdated;
|
|
199
|
+
try {
|
|
200
|
+
this.onClientOutdated?.(outdated);
|
|
201
|
+
} catch {
|
|
202
|
+
// A listener problem must not change the request's outcome.
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
const code = error.response?.data?.error;
|
|
206
|
+
if (
|
|
207
|
+
error.response?.status === 403 &&
|
|
208
|
+
(code === 'phone_required' || code === 'approval_required')
|
|
209
|
+
) {
|
|
210
|
+
try {
|
|
211
|
+
this.onTesterGate?.(code);
|
|
212
|
+
} catch {
|
|
213
|
+
// A listener problem must not change the request's outcome.
|
|
214
|
+
}
|
|
215
|
+
}
|
|
114
216
|
return Promise.reject(error);
|
|
115
217
|
}
|
|
116
218
|
);
|
|
@@ -606,6 +708,44 @@ export class TesterPayKitApiClient implements IApiClient {
|
|
|
606
708
|
return response.data;
|
|
607
709
|
}
|
|
608
710
|
|
|
711
|
+
/**
|
|
712
|
+
* POST /v1/testers/me/phone/link — a short-lived code for confirming this
|
|
713
|
+
* install in the TPK app (decision 2026-11-10, replaces the SMS dialog).
|
|
714
|
+
* Open `appUrl` (TPK app installed) or `url` (web page with an install
|
|
715
|
+
* hint); the person allows it there, then GET /v1/testers/me/profile
|
|
716
|
+
* reports the install as confirmed.
|
|
717
|
+
*/
|
|
718
|
+
async createAppLink(input: {
|
|
719
|
+
projectId?: string;
|
|
720
|
+
platform?: 'ios' | 'android' | 'web';
|
|
721
|
+
}): Promise<AppLinkResponse> {
|
|
722
|
+
const response = await this.client.post<AppLinkResponse>(
|
|
723
|
+
'/v1/testers/me/phone/link',
|
|
724
|
+
input,
|
|
725
|
+
);
|
|
726
|
+
return response.data;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
async getCompensation(): Promise<CompensationWallet> {
|
|
730
|
+
return (await this.client.get<CompensationWallet>('/v1/testers/me/compensation')).data;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
async recordPaidWork(command: WorkCommand): Promise<PaidAssignment> {
|
|
734
|
+
return (await this.client.post<PaidAssignment>('/v1/testers/me/compensation', command)).data;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
async registerCompensationPush(registration: PushRegistration): Promise<void> {
|
|
738
|
+
await this.client.post('/v1/testers/me/compensation', { action: 'push', ...registration });
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
async getPayoutAccount(): Promise<{ has_account: boolean; transfers_active: boolean; payments_configured: boolean }> {
|
|
742
|
+
return (await this.client.get('/v1/testers/me/payout-account')).data;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
async createPayoutAccountLink(): Promise<{ url: string }> {
|
|
746
|
+
return (await this.client.post('/v1/testers/me/payout-account')).data;
|
|
747
|
+
}
|
|
748
|
+
|
|
609
749
|
/** GET /v1/testers/me/points — current point balance + breakdown. */
|
|
610
750
|
async getMyPoints(): Promise<TesterPoints> {
|
|
611
751
|
const response = await this.client.get<TesterPoints>(
|
|
@@ -704,7 +844,7 @@ export class TesterPayKitApiClient implements IApiClient {
|
|
|
704
844
|
*
|
|
705
845
|
* RAG over the project's knowledge-base markdown files. Embeds the
|
|
706
846
|
* question, retrieves top-K nearest chunks via pgvector cosine
|
|
707
|
-
* similarity, and asks gpt-
|
|
847
|
+
* similarity, and asks gpt-6-luna to synthesise an answer that
|
|
708
848
|
* STRICTLY cites those chunks. Answer language tracks the
|
|
709
849
|
* question (English / German).
|
|
710
850
|
*
|
|
@@ -754,20 +894,6 @@ export class TesterPayKitApiClient implements IApiClient {
|
|
|
754
894
|
return response.data;
|
|
755
895
|
}
|
|
756
896
|
|
|
757
|
-
/**
|
|
758
|
-
* POST /v1/session-feedback
|
|
759
|
-
* Submit end-of-session feedback (rating, comments, etc.).
|
|
760
|
-
*/
|
|
761
|
-
async submitSessionEndFeedback(
|
|
762
|
-
payload: Record<string, unknown>,
|
|
763
|
-
): Promise<FeedbackResponse> {
|
|
764
|
-
const response = await this.client.post<FeedbackResponse>(
|
|
765
|
-
'/v1/session-feedback',
|
|
766
|
-
payload,
|
|
767
|
-
);
|
|
768
|
-
return response.data;
|
|
769
|
-
}
|
|
770
|
-
|
|
771
897
|
/**
|
|
772
898
|
* Upload an attachment directly (not tied to a specific bug report).
|
|
773
899
|
* POST /v1/attachments — alternate path from the contract alongside
|
|
@@ -826,7 +952,7 @@ export class TesterPayKitApiClient implements IApiClient {
|
|
|
826
952
|
* Contract: wire.bug_reports.voiceExtractBugFields
|
|
827
953
|
*
|
|
828
954
|
* Sends base64-encoded audio to the server. The server runs Whisper
|
|
829
|
-
* (transcription) + gpt-
|
|
955
|
+
* (transcription) + gpt-6-luna (structured extraction) and returns
|
|
830
956
|
* pre-filled bug-report fields in the tester's language.
|
|
831
957
|
*
|
|
832
958
|
* Wire body uses snake_case per contract. Timeout is 60 s because
|
|
@@ -902,7 +1028,7 @@ export interface KnowledgeBaseAnswer {
|
|
|
902
1028
|
citations: KnowledgeBaseCitation[];
|
|
903
1029
|
/** Resolved project UUID — useful for telemetry / dedup. */
|
|
904
1030
|
projectId: string;
|
|
905
|
-
/** Echo of the model used for the answer (e.g. "gpt-
|
|
1031
|
+
/** Echo of the model used for the answer (e.g. "gpt-6-luna"). */
|
|
906
1032
|
model?: string;
|
|
907
1033
|
}
|
|
908
1034
|
|
|
@@ -1214,7 +1340,12 @@ export interface EnrollmentResponse {
|
|
|
1214
1340
|
export interface TesterProfile {
|
|
1215
1341
|
id: string;
|
|
1216
1342
|
email?: string | null;
|
|
1343
|
+
/** System handle, e.g. "sad-banana" (migration 074). */
|
|
1217
1344
|
handle?: string | null;
|
|
1345
|
+
/** True once this install confirmed a phone number. */
|
|
1346
|
+
phoneVerified?: boolean;
|
|
1347
|
+
/** True once an admin approved the person (migration 077). */
|
|
1348
|
+
approved?: boolean;
|
|
1218
1349
|
fullName?: string | null;
|
|
1219
1350
|
rating?: number | null;
|
|
1220
1351
|
pointsTotal?: number | null;
|
|
@@ -1222,6 +1353,15 @@ export interface TesterProfile {
|
|
|
1222
1353
|
createdAt?: string;
|
|
1223
1354
|
}
|
|
1224
1355
|
|
|
1356
|
+
export interface AppLinkResponse {
|
|
1357
|
+
code: string;
|
|
1358
|
+
/** Web page: opens the TPK app via universal link, else an install hint. */
|
|
1359
|
+
url: string;
|
|
1360
|
+
/** testerpaykit://link/<code>, opens the TPK app directly. */
|
|
1361
|
+
appUrl: string;
|
|
1362
|
+
expiresAt: string;
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1225
1365
|
export interface TesterPoints {
|
|
1226
1366
|
total: number;
|
|
1227
1367
|
breakdown?: Record<string, number>;
|
|
@@ -1284,13 +1424,6 @@ export interface TesterDeviceResponse {
|
|
|
1284
1424
|
deviceType: string;
|
|
1285
1425
|
}
|
|
1286
1426
|
|
|
1287
|
-
/** Response from POST /v1/session-feedback */
|
|
1288
|
-
export interface FeedbackResponse {
|
|
1289
|
-
id: string;
|
|
1290
|
-
status: string;
|
|
1291
|
-
message?: string;
|
|
1292
|
-
}
|
|
1293
|
-
|
|
1294
1427
|
function stepResults(verdicts: RetestStepVerdicts): { step: number; passed: boolean }[] {
|
|
1295
1428
|
return Object.entries(verdicts).map(([step, passed]) => ({ step: Number(step), passed }));
|
|
1296
1429
|
}
|