@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.
@@ -0,0 +1,59 @@
1
+ /** `play` = play money in the pilot: real ledger rows, never a payout.
2
+ * Every UI labels such amounts "Spielgeld · Pilot" / "Play money · pilot". */
3
+ export type MoneyMode = 'play' | 'test' | 'live';
4
+ export type WorkState = 'offered' | 'active' | 'paused' | 'review' | 'disputed' | 'approved' | 'cancelled';
5
+ export interface PaidAssignment {
6
+ id: string; project_id: string; tester_id: string; title: string; project_name: string;
7
+ mode: MoneyMode; terms_version: 1; rate_cents: number; minimum_cents: number;
8
+ budget_cents: number; seconds: number; running_since: string | null;
9
+ state: WorkState; revision: number; amount_cents: number | null;
10
+ review_due: string | null; review_note: string | null; completion_note: string | null;
11
+ }
12
+ /** time = paid assignment · task = checklist task on its announced time ·
13
+ * bonus = idea bonus · bug_bonus · reproduction · retest (one per round). */
14
+ export type MoneyKind = 'time' | 'task' | 'bonus' | 'bug_bonus' | 'reproduction' | 'retest' | 'start_bonus';
15
+ export interface MoneyEntry {
16
+ id: string; project_id: string; project_name: string; tester_id: string; mode: MoneyMode;
17
+ kind: MoneyKind; reason: string; amount_cents: number; currency: 'eur';
18
+ /** review = waits for the 3-working-day window, then released. */
19
+ status: 'review' | 'approved' | 'processing' | 'transferred' | 'held';
20
+ units: number; review_due: string | null; review_note: string | null;
21
+ bug_id: string | null; task_preset_id: string | null;
22
+ created_at: string; transfer_id: string | null;
23
+ }
24
+ /** Sums in the current mode, in cents. Bonuses never count towards the 5 € floor. */
25
+ export interface MoneyTotals {
26
+ in_review_cents: number; released_cents: number; bonus_cents: number;
27
+ held_cents: number; total_cents: number;
28
+ }
29
+ export interface CompensationRates {
30
+ rate_cents_per_minute: number; minimum_cents: number;
31
+ bug_bonus_cents: { easy: number; medium: number; hard: number };
32
+ reproduction_cents: number; retest_per_fix_cents: number; retest_round_minimum_cents: number;
33
+ idea_bonus_choices_cents: number[]; review_working_days: number;
34
+ /** Start bonus, booked once per person on the first phone confirmation. */
35
+ start_bonus_cents?: number;
36
+ }
37
+ export interface CompensationWallet {
38
+ /** Current mode; `play` = label every amount as play money. */
39
+ mode: MoneyMode;
40
+ currency: 'eur'; server_time: string; rates: CompensationRates;
41
+ /** The person = every app install with the same confirmed phone. */
42
+ person: { handle: string | null; phone_confirmed: boolean; tester_count: number;
43
+ apps: Array<{ project_id: string; project_name: string }> };
44
+ /** Whole person across apps … */
45
+ totals: MoneyTotals;
46
+ /** … and the share of this app install. */
47
+ this_app: MoneyTotals;
48
+ assignments: PaidAssignment[]; entries: MoneyEntry[];
49
+ balances: Record<MoneyMode, Record<MoneyEntry['status'], number>>;
50
+ legacy: Array<{ id: string; source: string; amount_cents: number; status: string }>;
51
+ }
52
+ export interface WorkCommand {
53
+ assignment_id: string; request_id: string; revision: number;
54
+ action: 'start' | 'pause' | 'submit' | 'submit_partial' | 'decline';
55
+ accept_terms_version?: 1; seconds?: number; note?: string;
56
+ }
57
+ export interface PushRegistration {
58
+ installation_id: string; app_id: string; token?: string; enabled: boolean;
59
+ }
package/src/index.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './TesterPayKitApiClient';
2
+ export * from './compensation';
@@ -1,6 +1,9 @@
1
1
  import { describe, it, expect, vi, beforeEach } from 'vitest';
2
2
  import axios from 'axios';
3
- import { TesterPayKitApiClient } from '../src/TesterPayKitApiClient';
3
+ import {
4
+ ClientOutdatedError,
5
+ TesterPayKitApiClient,
6
+ } from '../src/TesterPayKitApiClient';
4
7
  import { TokenManager } from '@testerpaykit/core';
5
8
 
6
9
  // Mock axios
@@ -72,6 +75,84 @@ describe('TesterPayKitApiClient', () => {
72
75
  });
73
76
  });
74
77
 
78
+ describe('onTesterGate', () => {
79
+ function rejectWith(status: number, error?: string) {
80
+ const onError = mockAxiosInstance.interceptors.response.use.mock.calls[0][1];
81
+ return onError({ response: { status, data: error ? { error } : {} } });
82
+ }
83
+
84
+ it('reports a 403 phone_required / approval_required and still rejects', async () => {
85
+ const seen: string[] = [];
86
+ client.onTesterGate = (reason) => seen.push(reason);
87
+ await expect(rejectWith(403, 'phone_required')).rejects.toBeTruthy();
88
+ await expect(rejectWith(403, 'approval_required')).rejects.toBeTruthy();
89
+ expect(seen).toEqual(['phone_required', 'approval_required']);
90
+ });
91
+
92
+ it('ignores other errors', async () => {
93
+ const seen: string[] = [];
94
+ client.onTesterGate = (reason) => seen.push(reason);
95
+ await expect(rejectWith(403, 'forbidden')).rejects.toBeTruthy();
96
+ await expect(rejectWith(500)).rejects.toBeTruthy();
97
+ expect(seen).toEqual([]);
98
+ });
99
+ });
100
+
101
+ describe('client version check', () => {
102
+ const outdatedBody = {
103
+ error: 'client_outdated',
104
+ kind: 'expo',
105
+ min: '2.2.0',
106
+ yours: '2.1.0',
107
+ message: 'too old',
108
+ };
109
+
110
+ it('sends no X-TPK-Client unless the caller sets one', () => {
111
+ new TesterPayKitApiClient({ apiKey: 'k', clientHeader: 'expo/2.2.0' });
112
+ expect(mockedAxios.create).toHaveBeenLastCalledWith({
113
+ baseURL: 'https://api.testerpaykit.com',
114
+ headers: {
115
+ 'Content-Type': 'application/json',
116
+ 'X-API-Key': 'k',
117
+ 'X-TPK-Client': 'expo/2.2.0',
118
+ },
119
+ });
120
+ });
121
+
122
+ it('426 client_outdated: reports once, then sends nothing more', async () => {
123
+ const onRequest = mockAxiosInstance.interceptors.request.use.mock.calls[0][0];
124
+ const onError = mockAxiosInstance.interceptors.response.use.mock.calls[0][1];
125
+ const seen: unknown[] = [];
126
+ client.onClientOutdated = (info) => seen.push(info);
127
+
128
+ expect(client.clientOutdated).toBeNull();
129
+ await expect(onRequest({ headers: {} })).resolves.toBeTruthy();
130
+
131
+ await expect(
132
+ onError({ response: { status: 426, data: outdatedBody } }),
133
+ ).rejects.toBeTruthy();
134
+ await expect(
135
+ onError({ response: { status: 426, data: outdatedBody } }),
136
+ ).rejects.toBeTruthy();
137
+
138
+ const info = { kind: 'expo', min: '2.2.0', yours: '2.1.0', message: 'too old' };
139
+ expect(seen).toEqual([info]);
140
+ expect(client.clientOutdated).toEqual(info);
141
+ const blocked = onRequest({ headers: {} });
142
+ await expect(blocked).rejects.toBeInstanceOf(ClientOutdatedError);
143
+ await expect(blocked).rejects.toMatchObject({ info });
144
+ await expect(blocked).rejects.not.toHaveProperty('response');
145
+ });
146
+
147
+ it('ignores a 426 without client_outdated', async () => {
148
+ const onError = mockAxiosInstance.interceptors.response.use.mock.calls[0][1];
149
+ await expect(
150
+ onError({ response: { status: 426, data: { error: 'other' } } }),
151
+ ).rejects.toBeTruthy();
152
+ expect(client.clientOutdated).toBeNull();
153
+ });
154
+ });
155
+
75
156
  describe('login', () => {
76
157
  it('should successfully login and store tokens', async () => {
77
158
  const loginRequest = {