@terros-inc/sdk 1.0.5 → 1.0.6
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/index.d.mts +1028 -0
- package/dist/index.mjs +224 -0
- package/package.json +8 -4
- package/dist/analytics.d.ts +0 -8
- package/dist/analytics.js +0 -22
- package/dist/apiCaller.d.ts +0 -12
- package/dist/apiCaller.js +0 -44
- package/dist/client.d.ts +0 -8
- package/dist/client.js +0 -13
- package/dist/client.test.d.ts +0 -1
- package/dist/client.test.js +0 -81
- package/dist/clients/account.d.ts +0 -24
- package/dist/clients/account.js +0 -53
- package/dist/clients/calendar.d.ts +0 -21
- package/dist/clients/calendar.js +0 -44
- package/dist/clients/index.d.ts +0 -3
- package/dist/clients/index.js +0 -3
- package/dist/clients/user.d.ts +0 -18
- package/dist/clients/user.js +0 -42
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -2
- package/dist/models/account/api.d.ts +0 -167
- package/dist/models/account/api.js +0 -1
- package/dist/models/account/index.d.ts +0 -2
- package/dist/models/account/index.js +0 -2
- package/dist/models/account/model.d.ts +0 -219
- package/dist/models/account/model.js +0 -1
- package/dist/models/calendar/api.d.ts +0 -122
- package/dist/models/calendar/api.js +0 -1
- package/dist/models/calendar/index.d.ts +0 -2
- package/dist/models/calendar/index.js +0 -2
- package/dist/models/calendar/model.d.ts +0 -83
- package/dist/models/calendar/model.js +0 -1
- package/dist/models/company/index.d.ts +0 -1
- package/dist/models/company/index.js +0 -1
- package/dist/models/company/model.d.ts +0 -37
- package/dist/models/company/model.js +0 -1
- package/dist/models/index.d.ts +0 -7
- package/dist/models/index.js +0 -7
- package/dist/models/location/index.d.ts +0 -1
- package/dist/models/location/index.js +0 -1
- package/dist/models/location/model.d.ts +0 -21
- package/dist/models/location/model.js +0 -1
- package/dist/models/shared.d.ts +0 -32
- package/dist/models/shared.js +0 -6
- package/dist/models/team/index.d.ts +0 -1
- package/dist/models/team/index.js +0 -1
- package/dist/models/team/model.d.ts +0 -17
- package/dist/models/team/model.js +0 -1
- package/dist/models/user/api.d.ts +0 -111
- package/dist/models/user/api.js +0 -1
- package/dist/models/user/index.d.ts +0 -2
- package/dist/models/user/index.js +0 -2
- package/dist/models/user/model.d.ts +0 -179
- package/dist/models/user/model.js +0 -1
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { platform, release } from "node:os";
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
//#region src/clients/account.ts
|
|
6
|
+
var AccountStatusClient = class {
|
|
7
|
+
api;
|
|
8
|
+
constructor(api) {
|
|
9
|
+
this.api = api;
|
|
10
|
+
}
|
|
11
|
+
add(input) {
|
|
12
|
+
return this.api.call("account/status/add", input);
|
|
13
|
+
}
|
|
14
|
+
update(input) {
|
|
15
|
+
return this.api.call("account/status/update", input);
|
|
16
|
+
}
|
|
17
|
+
list(input) {
|
|
18
|
+
return this.api.call("account/status/list", input);
|
|
19
|
+
}
|
|
20
|
+
remove(input) {
|
|
21
|
+
return this.api.call("account/status/remove", input);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var AccountClient = class {
|
|
25
|
+
api;
|
|
26
|
+
status;
|
|
27
|
+
constructor(api) {
|
|
28
|
+
this.api = api;
|
|
29
|
+
this.status = new AccountStatusClient(api);
|
|
30
|
+
}
|
|
31
|
+
add(input) {
|
|
32
|
+
return this.api.call("account/add", input);
|
|
33
|
+
}
|
|
34
|
+
update(input) {
|
|
35
|
+
return this.api.call("account/update", input);
|
|
36
|
+
}
|
|
37
|
+
updateBatch(input) {
|
|
38
|
+
return this.api.call("account/update/batch", input);
|
|
39
|
+
}
|
|
40
|
+
list(input) {
|
|
41
|
+
return this.api.call("account/list", input);
|
|
42
|
+
}
|
|
43
|
+
bulk(input) {
|
|
44
|
+
return this.api.call("account/bulk", input);
|
|
45
|
+
}
|
|
46
|
+
get(input) {
|
|
47
|
+
return this.api.call("account/get", input);
|
|
48
|
+
}
|
|
49
|
+
match(input) {
|
|
50
|
+
return this.api.call("account/match", input);
|
|
51
|
+
}
|
|
52
|
+
remove(input) {
|
|
53
|
+
return this.api.call("account/remove", input);
|
|
54
|
+
}
|
|
55
|
+
upsert(input) {
|
|
56
|
+
return this.api.call("account/upsert", input);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/clients/calendar.ts
|
|
61
|
+
var CalendarEventClient = class {
|
|
62
|
+
api;
|
|
63
|
+
constructor(api) {
|
|
64
|
+
this.api = api;
|
|
65
|
+
}
|
|
66
|
+
add(input) {
|
|
67
|
+
return this.api.call("calendar/event/add", input);
|
|
68
|
+
}
|
|
69
|
+
get(input) {
|
|
70
|
+
return this.api.call("calendar/event/get", input);
|
|
71
|
+
}
|
|
72
|
+
list(input) {
|
|
73
|
+
return this.api.call("calendar/event/list", input);
|
|
74
|
+
}
|
|
75
|
+
update(input) {
|
|
76
|
+
return this.api.call("calendar/event/update", input);
|
|
77
|
+
}
|
|
78
|
+
upsert(input) {
|
|
79
|
+
return this.api.call("calendar/event/upsert", input);
|
|
80
|
+
}
|
|
81
|
+
confirm(input) {
|
|
82
|
+
return this.api.call("calendar/event/confirm", input);
|
|
83
|
+
}
|
|
84
|
+
remove(input) {
|
|
85
|
+
return this.api.call("calendar/event/remove", input);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
var CalendarClient = class {
|
|
89
|
+
api;
|
|
90
|
+
event;
|
|
91
|
+
constructor(api) {
|
|
92
|
+
this.api = api;
|
|
93
|
+
this.event = new CalendarEventClient(api);
|
|
94
|
+
}
|
|
95
|
+
availability(input) {
|
|
96
|
+
return this.api.call("calendar/availability", input);
|
|
97
|
+
}
|
|
98
|
+
closers(input) {
|
|
99
|
+
return this.api.call("calendar/closers", input);
|
|
100
|
+
}
|
|
101
|
+
timeslots(input) {
|
|
102
|
+
return this.api.call("calendar/timeslots", input);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/clients/user.ts
|
|
107
|
+
var UserClient = class {
|
|
108
|
+
api;
|
|
109
|
+
constructor(api) {
|
|
110
|
+
this.api = api;
|
|
111
|
+
}
|
|
112
|
+
list(input) {
|
|
113
|
+
return this.api.call("user/list", input);
|
|
114
|
+
}
|
|
115
|
+
add(input) {
|
|
116
|
+
return this.api.call("user/add", input);
|
|
117
|
+
}
|
|
118
|
+
update(input) {
|
|
119
|
+
return this.api.call("user/update", input);
|
|
120
|
+
}
|
|
121
|
+
updateBulk(input) {
|
|
122
|
+
return this.api.call("user/update/bulk", input);
|
|
123
|
+
}
|
|
124
|
+
remove(input) {
|
|
125
|
+
return this.api.call("user/remove", input);
|
|
126
|
+
}
|
|
127
|
+
get(input = {}) {
|
|
128
|
+
return this.api.call("user/get", input);
|
|
129
|
+
}
|
|
130
|
+
profile(input = {}) {
|
|
131
|
+
return this.api.call("user/profile", input);
|
|
132
|
+
}
|
|
133
|
+
search(input) {
|
|
134
|
+
return this.api.call("user/search", input);
|
|
135
|
+
}
|
|
136
|
+
timezone(input) {
|
|
137
|
+
return this.api.call("user/timezone", input);
|
|
138
|
+
}
|
|
139
|
+
report(input) {
|
|
140
|
+
return this.api.call("user/report", input);
|
|
141
|
+
}
|
|
142
|
+
closers(input) {
|
|
143
|
+
return this.api.call("user/closers", input);
|
|
144
|
+
}
|
|
145
|
+
manager(input) {
|
|
146
|
+
return this.api.call("user/manager", input);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/models/shared.ts
|
|
151
|
+
function isResponseError(response) {
|
|
152
|
+
return typeof response === "object" && response !== null && response.type === "error" && Boolean(response.error);
|
|
153
|
+
}
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/analytics.ts
|
|
156
|
+
function getAnalyticsHeaders() {
|
|
157
|
+
if (typeof globalThis.process === "undefined") return {};
|
|
158
|
+
try {
|
|
159
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
160
|
+
const packageJson = JSON.parse(readFileSync(join(__dirname, "../package.json"), "utf8"));
|
|
161
|
+
return {
|
|
162
|
+
"Terros-Platform": platform(),
|
|
163
|
+
"Terros-Platform-Version": release(),
|
|
164
|
+
"Terros-Bundle-Identifier": "com.terros.sdk",
|
|
165
|
+
"Terros-App-Version": packageJson.version
|
|
166
|
+
};
|
|
167
|
+
} catch {
|
|
168
|
+
return {};
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region src/apiCaller.ts
|
|
173
|
+
const PROD_BASE_URL = "https://api.terros.com";
|
|
174
|
+
var ApiCaller = class {
|
|
175
|
+
baseUrl;
|
|
176
|
+
auth;
|
|
177
|
+
analytics;
|
|
178
|
+
constructor(config) {
|
|
179
|
+
this.baseUrl = config.baseUrl ?? readProcessEnv("TERROS_SDK_BASE_URL") ?? PROD_BASE_URL;
|
|
180
|
+
this.analytics = getAnalyticsHeaders();
|
|
181
|
+
const auth = config.apiKey ?? readProcessEnv("TERROS_API_KEY");
|
|
182
|
+
if (!auth) throw new Error("No auth provided: set TERROS_API_KEY or pass config.auth");
|
|
183
|
+
this.auth = auth;
|
|
184
|
+
}
|
|
185
|
+
async call(route, input) {
|
|
186
|
+
let response;
|
|
187
|
+
try {
|
|
188
|
+
response = await fetch(`${this.baseUrl}/${route}`, {
|
|
189
|
+
method: "POST",
|
|
190
|
+
headers: {
|
|
191
|
+
...this.analytics,
|
|
192
|
+
"Content-Type": "application/json",
|
|
193
|
+
authorization: `ApiKey ${this.auth}`
|
|
194
|
+
},
|
|
195
|
+
body: JSON.stringify(input)
|
|
196
|
+
});
|
|
197
|
+
} catch (cause) {
|
|
198
|
+
throw new Error(`Request to ${route} failed`, { cause });
|
|
199
|
+
}
|
|
200
|
+
if (!response.ok) throw new Error(response.statusText);
|
|
201
|
+
const output = await response.json();
|
|
202
|
+
if (isResponseError(output)) throw new Error(output.message ?? output.error);
|
|
203
|
+
return output;
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
function readProcessEnv(key) {
|
|
207
|
+
if (typeof globalThis.process === "undefined") return void 0;
|
|
208
|
+
return globalThis.process.env[key];
|
|
209
|
+
}
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/client.ts
|
|
212
|
+
var TerrosClient = class {
|
|
213
|
+
user;
|
|
214
|
+
account;
|
|
215
|
+
calendar;
|
|
216
|
+
constructor(config = {}) {
|
|
217
|
+
const api = new ApiCaller(config);
|
|
218
|
+
this.user = new UserClient(api);
|
|
219
|
+
this.account = new AccountClient(api);
|
|
220
|
+
this.calendar = new CalendarClient(api);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
//#endregion
|
|
224
|
+
export { TerrosClient, isResponseError };
|
package/package.json
CHANGED
|
@@ -6,12 +6,17 @@
|
|
|
6
6
|
"description": "Typescript SDK for Terros Sales platform",
|
|
7
7
|
"devDependencies": {
|
|
8
8
|
"@types/node": "^24.13.2",
|
|
9
|
+
"tsdown": "^0.22.3",
|
|
9
10
|
"typescript": "^6.0.3",
|
|
10
11
|
"vitest": "^4.1.10"
|
|
11
12
|
},
|
|
12
13
|
"engines": {
|
|
13
14
|
"node": "^24"
|
|
14
15
|
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": "./dist/index.mjs",
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
15
20
|
"files": [
|
|
16
21
|
"dist"
|
|
17
22
|
],
|
|
@@ -21,8 +26,6 @@
|
|
|
21
26
|
"sdk"
|
|
22
27
|
],
|
|
23
28
|
"license": "MIT",
|
|
24
|
-
"main": "./dist/index.js",
|
|
25
|
-
"types": "./dist/index.d.ts",
|
|
26
29
|
"name": "@terros-inc/sdk",
|
|
27
30
|
"publishConfig": {
|
|
28
31
|
"access": "public",
|
|
@@ -33,9 +36,10 @@
|
|
|
33
36
|
"url": "git+https://github.com/terros-inc/connect.git"
|
|
34
37
|
},
|
|
35
38
|
"type": "module",
|
|
36
|
-
"
|
|
39
|
+
"types": "./dist/index.d.mts",
|
|
40
|
+
"version": "1.0.6",
|
|
37
41
|
"scripts": {
|
|
38
|
-
"build": "
|
|
42
|
+
"build": "tsdown",
|
|
39
43
|
"test": "vitest run"
|
|
40
44
|
}
|
|
41
45
|
}
|
package/dist/analytics.d.ts
DELETED
package/dist/analytics.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { fileURLToPath } from 'node:url';
|
|
2
|
-
import { dirname, join } from 'node:path';
|
|
3
|
-
import { platform, release } from 'node:os';
|
|
4
|
-
import { readFileSync } from 'node:fs';
|
|
5
|
-
export function getAnalyticsHeaders() {
|
|
6
|
-
if (typeof globalThis.process === 'undefined')
|
|
7
|
-
return {};
|
|
8
|
-
try {
|
|
9
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
-
const __dirname = dirname(__filename);
|
|
11
|
-
const packageJson = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf8'));
|
|
12
|
-
return {
|
|
13
|
-
'Terros-Platform': platform(),
|
|
14
|
-
'Terros-Platform-Version': release(),
|
|
15
|
-
'Terros-Bundle-Identifier': 'com.terros.sdk',
|
|
16
|
-
'Terros-App-Version': packageJson.version,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
catch {
|
|
20
|
-
return {};
|
|
21
|
-
}
|
|
22
|
-
}
|
package/dist/apiCaller.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type ApiRoute } from './models';
|
|
2
|
-
export type ClientConfig = {
|
|
3
|
-
apiKey?: string;
|
|
4
|
-
baseUrl?: string;
|
|
5
|
-
};
|
|
6
|
-
export declare class ApiCaller {
|
|
7
|
-
private readonly baseUrl;
|
|
8
|
-
private readonly auth;
|
|
9
|
-
private readonly analytics;
|
|
10
|
-
constructor(config: ClientConfig);
|
|
11
|
-
call<Success>(route: ApiRoute, input: object): Promise<Success>;
|
|
12
|
-
}
|
package/dist/apiCaller.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { isResponseError } from './models';
|
|
2
|
-
import { getAnalyticsHeaders } from './analytics';
|
|
3
|
-
const PROD_BASE_URL = 'https://api.terros.com';
|
|
4
|
-
export class ApiCaller {
|
|
5
|
-
baseUrl;
|
|
6
|
-
auth;
|
|
7
|
-
analytics;
|
|
8
|
-
constructor(config) {
|
|
9
|
-
this.baseUrl = config.baseUrl ?? readProcessEnv('TERROS_SDK_BASE_URL') ?? PROD_BASE_URL;
|
|
10
|
-
this.analytics = getAnalyticsHeaders();
|
|
11
|
-
const auth = config.apiKey ?? readProcessEnv('TERROS_API_KEY');
|
|
12
|
-
if (!auth)
|
|
13
|
-
throw new Error('No auth provided: set TERROS_API_KEY or pass config.auth');
|
|
14
|
-
this.auth = auth;
|
|
15
|
-
}
|
|
16
|
-
async call(route, input) {
|
|
17
|
-
let response;
|
|
18
|
-
try {
|
|
19
|
-
response = await fetch(`${this.baseUrl}/${route}`, {
|
|
20
|
-
method: 'POST',
|
|
21
|
-
headers: {
|
|
22
|
-
...this.analytics,
|
|
23
|
-
'Content-Type': 'application/json',
|
|
24
|
-
authorization: `ApiKey ${this.auth}`,
|
|
25
|
-
},
|
|
26
|
-
body: JSON.stringify(input),
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
catch (cause) {
|
|
30
|
-
throw new Error(`Request to ${route} failed`, { cause });
|
|
31
|
-
}
|
|
32
|
-
if (!response.ok)
|
|
33
|
-
throw new Error(response.statusText);
|
|
34
|
-
const output = await response.json();
|
|
35
|
-
if (isResponseError(output))
|
|
36
|
-
throw new Error(output.message ?? output.error);
|
|
37
|
-
return output;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
function readProcessEnv(key) {
|
|
41
|
-
if (typeof globalThis.process === 'undefined')
|
|
42
|
-
return undefined;
|
|
43
|
-
return globalThis.process.env[key];
|
|
44
|
-
}
|
package/dist/client.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { UserClient, AccountClient, CalendarClient } from './clients';
|
|
2
|
-
import { type ClientConfig } from './apiCaller';
|
|
3
|
-
export declare class TerrosClient {
|
|
4
|
-
readonly user: UserClient;
|
|
5
|
-
readonly account: AccountClient;
|
|
6
|
-
readonly calendar: CalendarClient;
|
|
7
|
-
constructor(config?: ClientConfig);
|
|
8
|
-
}
|
package/dist/client.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { UserClient, AccountClient, CalendarClient } from './clients';
|
|
2
|
-
import { ApiCaller } from './apiCaller';
|
|
3
|
-
export class TerrosClient {
|
|
4
|
-
user;
|
|
5
|
-
account;
|
|
6
|
-
calendar;
|
|
7
|
-
constructor(config = {}) {
|
|
8
|
-
const api = new ApiCaller(config);
|
|
9
|
-
this.user = new UserClient(api);
|
|
10
|
-
this.account = new AccountClient(api);
|
|
11
|
-
this.calendar = new CalendarClient(api);
|
|
12
|
-
}
|
|
13
|
-
}
|
package/dist/client.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/client.test.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { ApiCaller } from './apiCaller';
|
|
3
|
-
describe('ApiCaller', () => {
|
|
4
|
-
const originalFetch = globalThis.fetch;
|
|
5
|
-
afterEach(() => {
|
|
6
|
-
globalThis.fetch = originalFetch;
|
|
7
|
-
delete process.env.TERROS_SDK_BASE_URL;
|
|
8
|
-
});
|
|
9
|
-
function mockFetch(body, ok = true) {
|
|
10
|
-
globalThis.fetch = vi.fn().mockResolvedValue({
|
|
11
|
-
ok,
|
|
12
|
-
statusText: 'Bad Request',
|
|
13
|
-
json: () => Promise.resolve(body),
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
it('sends a POST with the route, headers, and JSON body, returning the parsed success', async () => {
|
|
17
|
-
mockFetch({ type: 'success', value: 42 });
|
|
18
|
-
const caller = new ApiCaller({ apiKey: 'test-key', baseUrl: 'https://example.com' });
|
|
19
|
-
const result = await caller.call('user/get', { userId: 'U:1' });
|
|
20
|
-
expect(result).toEqual({ type: 'success', value: 42 });
|
|
21
|
-
expect(globalThis.fetch).toHaveBeenCalledWith('https://example.com/user/get', {
|
|
22
|
-
method: 'POST',
|
|
23
|
-
headers: expect.objectContaining({
|
|
24
|
-
'Content-Type': 'application/json',
|
|
25
|
-
authorization: 'ApiKey test-key',
|
|
26
|
-
}),
|
|
27
|
-
body: JSON.stringify({ userId: 'U:1' }),
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
it('includes analytics headers describing the platform and SDK version', async () => {
|
|
31
|
-
mockFetch({ type: 'success', value: 42 });
|
|
32
|
-
const caller = new ApiCaller({ apiKey: 'test-key', baseUrl: 'https://example.com' });
|
|
33
|
-
await caller.call('user/get', { userId: 'U:1' });
|
|
34
|
-
const [, options] = vi.mocked(globalThis.fetch).mock.calls[0];
|
|
35
|
-
expect(options.headers).toMatchObject({
|
|
36
|
-
'Terros-Bundle-Identifier': 'com.terros.sdk',
|
|
37
|
-
'Terros-Platform': expect.any(String),
|
|
38
|
-
'Terros-Platform-Version': expect.any(String),
|
|
39
|
-
'Terros-App-Version': expect.any(String),
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
it('wraps a network failure in an Error with the underlying cause', async () => {
|
|
43
|
-
const networkError = new TypeError('fetch failed');
|
|
44
|
-
globalThis.fetch = vi.fn().mockRejectedValue(networkError);
|
|
45
|
-
const caller = new ApiCaller({ apiKey: 'test-key', baseUrl: 'https://example.com' });
|
|
46
|
-
await expect(caller.call('user/get', {})).rejects.toThrow('Request to user/get failed');
|
|
47
|
-
await expect(caller.call('user/get', {})).rejects.toMatchObject({ cause: networkError });
|
|
48
|
-
});
|
|
49
|
-
it('throws with the status text on a non-ok response', async () => {
|
|
50
|
-
mockFetch({}, false);
|
|
51
|
-
const caller = new ApiCaller({ apiKey: 'test-key', baseUrl: 'https://example.com' });
|
|
52
|
-
await expect(caller.call('user/get', {})).rejects.toThrow('Bad Request');
|
|
53
|
-
});
|
|
54
|
-
it('throws with the error message on a ResponseError body', async () => {
|
|
55
|
-
mockFetch({ type: 'error', error: 'not_found', message: 'User not found' });
|
|
56
|
-
const caller = new ApiCaller({ apiKey: 'test-key', baseUrl: 'https://example.com' });
|
|
57
|
-
await expect(caller.call('user/get', {})).rejects.toThrow('User not found');
|
|
58
|
-
});
|
|
59
|
-
describe('resolveBaseUrl precedence', () => {
|
|
60
|
-
beforeEach(() => {
|
|
61
|
-
mockFetch({ type: 'success' });
|
|
62
|
-
});
|
|
63
|
-
it('prefers the explicit config baseUrl over the env var and default', async () => {
|
|
64
|
-
process.env.TERROS_SDK_BASE_URL = 'https://env.example.com';
|
|
65
|
-
const caller = new ApiCaller({ apiKey: 'test-key', baseUrl: 'https://config.example.com' });
|
|
66
|
-
await caller.call('user/get', {});
|
|
67
|
-
expect(globalThis.fetch).toHaveBeenCalledWith('https://config.example.com/user/get', expect.anything());
|
|
68
|
-
});
|
|
69
|
-
it('falls back to the env var when no baseUrl is configured', async () => {
|
|
70
|
-
process.env.TERROS_SDK_BASE_URL = 'https://env.example.com';
|
|
71
|
-
const caller = new ApiCaller({ apiKey: 'test-key' });
|
|
72
|
-
await caller.call('user/get', {});
|
|
73
|
-
expect(globalThis.fetch).toHaveBeenCalledWith('https://env.example.com/user/get', expect.anything());
|
|
74
|
-
});
|
|
75
|
-
it('falls back to the prod default when neither baseUrl nor env var is set', async () => {
|
|
76
|
-
const caller = new ApiCaller({ apiKey: 'test-key' });
|
|
77
|
-
await caller.call('user/get', {});
|
|
78
|
-
expect(globalThis.fetch).toHaveBeenCalledWith('https://api.terros.com/user/get', expect.anything());
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { type AccountStatusAddInput, type AccountStatusAddSuccess, type AccountStatusUpdateInput, type AccountStatusUpdateSuccess, type AccountStatusListInput, type AccountStatusListSuccess, type AccountStatusRemoveInput, type ApiSuccess, type AccountAddInput, type AccountAddSuccess, type AccountUpdateInput, type AccountUpdateSuccess, type AccountUpdateBatchInput, type AccountUpdateBatchSuccess, type AccountListInput, type AccountListSuccess, type BulkModifyAccountsInput, type AccountGetInput, type AccountGetSuccess, type AccountMatchInput, type AccountMatchSuccess, type AccountRemoveInput, type AccountUpsertInput, type AccountUpsertSuccess } from '../models';
|
|
2
|
-
import { type ApiCaller } from '../apiCaller';
|
|
3
|
-
export declare class AccountStatusClient {
|
|
4
|
-
private readonly api;
|
|
5
|
-
constructor(api: ApiCaller);
|
|
6
|
-
add(input: AccountStatusAddInput): Promise<AccountStatusAddSuccess>;
|
|
7
|
-
update(input: AccountStatusUpdateInput): Promise<AccountStatusUpdateSuccess>;
|
|
8
|
-
list(input: AccountStatusListInput): Promise<AccountStatusListSuccess>;
|
|
9
|
-
remove(input: AccountStatusRemoveInput): Promise<ApiSuccess>;
|
|
10
|
-
}
|
|
11
|
-
export declare class AccountClient {
|
|
12
|
-
private readonly api;
|
|
13
|
-
readonly status: AccountStatusClient;
|
|
14
|
-
constructor(api: ApiCaller);
|
|
15
|
-
add(input: AccountAddInput): Promise<AccountAddSuccess>;
|
|
16
|
-
update(input: AccountUpdateInput): Promise<AccountUpdateSuccess>;
|
|
17
|
-
updateBatch(input: AccountUpdateBatchInput): Promise<AccountUpdateBatchSuccess>;
|
|
18
|
-
list(input: AccountListInput): Promise<AccountListSuccess>;
|
|
19
|
-
bulk(input: BulkModifyAccountsInput): Promise<ApiSuccess>;
|
|
20
|
-
get(input: AccountGetInput): Promise<AccountGetSuccess>;
|
|
21
|
-
match(input: AccountMatchInput): Promise<AccountMatchSuccess>;
|
|
22
|
-
remove(input: AccountRemoveInput): Promise<ApiSuccess>;
|
|
23
|
-
upsert(input: AccountUpsertInput): Promise<AccountUpsertSuccess>;
|
|
24
|
-
}
|
package/dist/clients/account.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
export class AccountStatusClient {
|
|
2
|
-
api;
|
|
3
|
-
constructor(api) {
|
|
4
|
-
this.api = api;
|
|
5
|
-
}
|
|
6
|
-
add(input) {
|
|
7
|
-
return this.api.call('account/status/add', input);
|
|
8
|
-
}
|
|
9
|
-
update(input) {
|
|
10
|
-
return this.api.call('account/status/update', input);
|
|
11
|
-
}
|
|
12
|
-
list(input) {
|
|
13
|
-
return this.api.call('account/status/list', input);
|
|
14
|
-
}
|
|
15
|
-
remove(input) {
|
|
16
|
-
return this.api.call('account/status/remove', input);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
export class AccountClient {
|
|
20
|
-
api;
|
|
21
|
-
status;
|
|
22
|
-
constructor(api) {
|
|
23
|
-
this.api = api;
|
|
24
|
-
this.status = new AccountStatusClient(api);
|
|
25
|
-
}
|
|
26
|
-
add(input) {
|
|
27
|
-
return this.api.call('account/add', input);
|
|
28
|
-
}
|
|
29
|
-
update(input) {
|
|
30
|
-
return this.api.call('account/update', input);
|
|
31
|
-
}
|
|
32
|
-
updateBatch(input) {
|
|
33
|
-
return this.api.call('account/update/batch', input);
|
|
34
|
-
}
|
|
35
|
-
list(input) {
|
|
36
|
-
return this.api.call('account/list', input);
|
|
37
|
-
}
|
|
38
|
-
bulk(input) {
|
|
39
|
-
return this.api.call('account/bulk', input);
|
|
40
|
-
}
|
|
41
|
-
get(input) {
|
|
42
|
-
return this.api.call('account/get', input);
|
|
43
|
-
}
|
|
44
|
-
match(input) {
|
|
45
|
-
return this.api.call('account/match', input);
|
|
46
|
-
}
|
|
47
|
-
remove(input) {
|
|
48
|
-
return this.api.call('account/remove', input);
|
|
49
|
-
}
|
|
50
|
-
upsert(input) {
|
|
51
|
-
return this.api.call('account/upsert', input);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { type CalendarEventAddInput, type CalendarEventAddSuccess, type CalendarEventGetInput, type CalendarEventGetSuccess, type CalendarEventListInput, type CalendarEventListSuccess, type CalendarEventUpdateInput, type CalendarEventUpdateSuccess, type CalendarEventUpsertInput, type CalendarEventUpsertSuccess, type CalendarEventConfirmInput, type CalendarEventConfirmSuccess, type CalendarEventRemoveInput, type ApiSuccess, type CalendarAvailabilityInput, type CalendarAvailabilitySuccess, type CalendarClosersInput, type CalendarClosersSuccess, type CalendarTimeslotsInput, type CalendarTimeslotsSuccess } from '../models';
|
|
2
|
-
import { type ApiCaller } from '../apiCaller';
|
|
3
|
-
export declare class CalendarEventClient {
|
|
4
|
-
private readonly api;
|
|
5
|
-
constructor(api: ApiCaller);
|
|
6
|
-
add(input: CalendarEventAddInput): Promise<CalendarEventAddSuccess>;
|
|
7
|
-
get(input: CalendarEventGetInput): Promise<CalendarEventGetSuccess>;
|
|
8
|
-
list(input: CalendarEventListInput): Promise<CalendarEventListSuccess>;
|
|
9
|
-
update(input: CalendarEventUpdateInput): Promise<CalendarEventUpdateSuccess>;
|
|
10
|
-
upsert(input: CalendarEventUpsertInput): Promise<CalendarEventUpsertSuccess>;
|
|
11
|
-
confirm(input: CalendarEventConfirmInput): Promise<CalendarEventConfirmSuccess>;
|
|
12
|
-
remove(input: CalendarEventRemoveInput): Promise<ApiSuccess>;
|
|
13
|
-
}
|
|
14
|
-
export declare class CalendarClient {
|
|
15
|
-
private readonly api;
|
|
16
|
-
readonly event: CalendarEventClient;
|
|
17
|
-
constructor(api: ApiCaller);
|
|
18
|
-
availability(input: CalendarAvailabilityInput): Promise<CalendarAvailabilitySuccess>;
|
|
19
|
-
closers(input: CalendarClosersInput): Promise<CalendarClosersSuccess>;
|
|
20
|
-
timeslots(input: CalendarTimeslotsInput): Promise<CalendarTimeslotsSuccess>;
|
|
21
|
-
}
|
package/dist/clients/calendar.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
export class CalendarEventClient {
|
|
2
|
-
api;
|
|
3
|
-
constructor(api) {
|
|
4
|
-
this.api = api;
|
|
5
|
-
}
|
|
6
|
-
add(input) {
|
|
7
|
-
return this.api.call('calendar/event/add', input);
|
|
8
|
-
}
|
|
9
|
-
get(input) {
|
|
10
|
-
return this.api.call('calendar/event/get', input);
|
|
11
|
-
}
|
|
12
|
-
list(input) {
|
|
13
|
-
return this.api.call('calendar/event/list', input);
|
|
14
|
-
}
|
|
15
|
-
update(input) {
|
|
16
|
-
return this.api.call('calendar/event/update', input);
|
|
17
|
-
}
|
|
18
|
-
upsert(input) {
|
|
19
|
-
return this.api.call('calendar/event/upsert', input);
|
|
20
|
-
}
|
|
21
|
-
confirm(input) {
|
|
22
|
-
return this.api.call('calendar/event/confirm', input);
|
|
23
|
-
}
|
|
24
|
-
remove(input) {
|
|
25
|
-
return this.api.call('calendar/event/remove', input);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
export class CalendarClient {
|
|
29
|
-
api;
|
|
30
|
-
event;
|
|
31
|
-
constructor(api) {
|
|
32
|
-
this.api = api;
|
|
33
|
-
this.event = new CalendarEventClient(api);
|
|
34
|
-
}
|
|
35
|
-
availability(input) {
|
|
36
|
-
return this.api.call('calendar/availability', input);
|
|
37
|
-
}
|
|
38
|
-
closers(input) {
|
|
39
|
-
return this.api.call('calendar/closers', input);
|
|
40
|
-
}
|
|
41
|
-
timeslots(input) {
|
|
42
|
-
return this.api.call('calendar/timeslots', input);
|
|
43
|
-
}
|
|
44
|
-
}
|
package/dist/clients/index.d.ts
DELETED
package/dist/clients/index.js
DELETED
package/dist/clients/user.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type UserListInput, type UserListSuccess, type UserAddInput, type UserAddSuccess, type UserUpdateInput, type UserUpdateSuccess, type UserBulkUpdateInput, type UserBulkUpdateSuccess, type UserRemoveInput, type ApiSuccess, type UserGetInput, type UserGetSuccess, type UserProfileInput, type UserProfileSuccess, type UserSearchInput, type UserSearchSuccess, type UserTimezoneInput, type UserReportInput, type UserReportSuccess, type UserClosersInput, type UserClosersSuccess, type UserManagerInput, type UserManagerSuccess } from '../models';
|
|
2
|
-
import { type ApiCaller } from '../apiCaller';
|
|
3
|
-
export declare class UserClient {
|
|
4
|
-
private readonly api;
|
|
5
|
-
constructor(api: ApiCaller);
|
|
6
|
-
list(input: UserListInput): Promise<UserListSuccess>;
|
|
7
|
-
add(input: UserAddInput): Promise<UserAddSuccess>;
|
|
8
|
-
update(input: UserUpdateInput): Promise<UserUpdateSuccess>;
|
|
9
|
-
updateBulk(input: UserBulkUpdateInput): Promise<UserBulkUpdateSuccess>;
|
|
10
|
-
remove(input: UserRemoveInput): Promise<ApiSuccess>;
|
|
11
|
-
get(input?: UserGetInput): Promise<UserGetSuccess>;
|
|
12
|
-
profile(input?: UserProfileInput): Promise<UserProfileSuccess>;
|
|
13
|
-
search(input: UserSearchInput): Promise<UserSearchSuccess>;
|
|
14
|
-
timezone(input: UserTimezoneInput): Promise<ApiSuccess>;
|
|
15
|
-
report(input: UserReportInput): Promise<UserReportSuccess>;
|
|
16
|
-
closers(input: UserClosersInput): Promise<UserClosersSuccess>;
|
|
17
|
-
manager(input: UserManagerInput): Promise<UserManagerSuccess>;
|
|
18
|
-
}
|