salesdock 0.1.1

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.cjs ADDED
@@ -0,0 +1,3516 @@
1
+ 'use strict';
2
+
3
+ var zod = require('zod');
4
+
5
+ // src/client.ts
6
+
7
+ // src/core/config.ts
8
+ var PRODUCTION_BASE_URL = "https://app.salesdock.nl";
9
+ var STAGING_BASE_URL = "https://app-staging.salesdock.nl";
10
+ var DEFAULT_VERSION = "v1";
11
+ var SDK_VERSION = "0.1.0";
12
+ function resolveConfig(config) {
13
+ if (!config || typeof config !== "object") {
14
+ throw new Error("Salesdock: configuration object is required.");
15
+ }
16
+ if (!config.domain || typeof config.domain !== "string") {
17
+ throw new Error(
18
+ 'Salesdock: `domain` is required (your account sub-domain, e.g. "testomgeving").'
19
+ );
20
+ }
21
+ if (!config.token || typeof config.token !== "string") {
22
+ throw new Error("Salesdock: `token` (Bearer API token) is required.");
23
+ }
24
+ const resolvedFetch = config.fetch ?? globalFetch();
25
+ if (!resolvedFetch) {
26
+ throw new Error(
27
+ "Salesdock: no global `fetch` found in this runtime. Pass a `fetch` implementation in the config."
28
+ );
29
+ }
30
+ const baseUrl = (config.baseUrl ?? PRODUCTION_BASE_URL).replace(/\/+$/, "");
31
+ return {
32
+ domain: config.domain,
33
+ token: config.token,
34
+ scope: config.scope ?? "user",
35
+ version: config.version ?? DEFAULT_VERSION,
36
+ baseUrl,
37
+ fetch: resolvedFetch,
38
+ validateResponses: config.validateResponses ?? true,
39
+ validateRequests: config.validateRequests ?? true,
40
+ maxRetries: config.maxRetries ?? 2,
41
+ retryDelayMs: config.retryDelayMs ?? 500,
42
+ timeout: config.timeout ?? 6e4,
43
+ headers: { ...config.headers ?? {} },
44
+ onRequest: config.onRequest,
45
+ onResponse: config.onResponse,
46
+ userAgent: config.userAgent
47
+ };
48
+ }
49
+ function globalFetch() {
50
+ const f = globalThis.fetch;
51
+ return typeof f === "function" ? f.bind(globalThis) : void 0;
52
+ }
53
+
54
+ // src/core/errors.ts
55
+ var SalesdockError = class extends Error {
56
+ constructor(message, options = {}) {
57
+ super(message, options.cause !== void 0 ? { cause: options.cause } : void 0);
58
+ this.name = new.target.name;
59
+ this.status = options.status;
60
+ this.code = options.code;
61
+ this.body = options.body;
62
+ this.errors = options.errors;
63
+ this.url = options.url;
64
+ this.method = options.method;
65
+ this.retryAfterMs = options.retryAfterMs;
66
+ Object.setPrototypeOf(this, new.target.prototype);
67
+ }
68
+ };
69
+ var SalesdockValidationError = class extends SalesdockError {
70
+ };
71
+ var SalesdockAuthenticationError = class extends SalesdockError {
72
+ };
73
+ var SalesdockForbiddenError = class extends SalesdockError {
74
+ };
75
+ var SalesdockNotFoundError = class extends SalesdockError {
76
+ };
77
+ var SalesdockMethodNotAllowedError = class extends SalesdockError {
78
+ };
79
+ var SalesdockRateLimitError = class extends SalesdockError {
80
+ };
81
+ var SalesdockServerError = class extends SalesdockError {
82
+ };
83
+ var SalesdockConnectionError = class extends SalesdockError {
84
+ };
85
+ var SalesdockTimeoutError = class extends SalesdockConnectionError {
86
+ };
87
+ var SalesdockInvalidRequestError = class extends SalesdockError {
88
+ constructor(message, zodError, options = {}) {
89
+ super(message, options);
90
+ this.zodError = zodError;
91
+ }
92
+ };
93
+ var SalesdockResponseValidationError = class extends SalesdockError {
94
+ constructor(message, zodError, options = {}) {
95
+ super(message, options);
96
+ this.zodError = zodError;
97
+ }
98
+ };
99
+ function errorFromResponse(status, body, context) {
100
+ const parsed = body && typeof body === "object" ? body : {};
101
+ const rawTextMessage = typeof body === "string" && body.trim() ? body.trim().slice(0, 500) : void 0;
102
+ const message = typeof parsed.message === "string" && parsed.message || rawTextMessage || defaultMessageForStatus(status);
103
+ const options = {
104
+ status,
105
+ code: typeof parsed.code === "number" ? parsed.code : void 0,
106
+ body,
107
+ errors: parsed.errors,
108
+ url: context.url,
109
+ method: context.method,
110
+ retryAfterMs: context.retryAfterMs
111
+ };
112
+ switch (status) {
113
+ case 400:
114
+ case 422:
115
+ return new SalesdockValidationError(message, options);
116
+ case 401:
117
+ return new SalesdockAuthenticationError(message, options);
118
+ case 403:
119
+ return new SalesdockForbiddenError(message, options);
120
+ case 404:
121
+ return new SalesdockNotFoundError(message, options);
122
+ case 405:
123
+ return new SalesdockMethodNotAllowedError(message, options);
124
+ case 429:
125
+ return new SalesdockRateLimitError(message, options);
126
+ default:
127
+ if (status >= 500) return new SalesdockServerError(message, options);
128
+ return new SalesdockError(message, options);
129
+ }
130
+ }
131
+ function defaultMessageForStatus(status) {
132
+ switch (status) {
133
+ case 400:
134
+ return "Bad request";
135
+ case 401:
136
+ return "Unauthorized";
137
+ case 403:
138
+ return "Forbidden";
139
+ case 404:
140
+ return "Not found";
141
+ case 405:
142
+ return "Method not allowed";
143
+ case 422:
144
+ return "Unprocessable entity";
145
+ case 429:
146
+ return "Too many requests";
147
+ default:
148
+ return status >= 500 ? "Server error" : `Request failed with status ${status}`;
149
+ }
150
+ }
151
+ function loose(shape) {
152
+ return zod.z.object(shape).passthrough();
153
+ }
154
+ function nullish(schema) {
155
+ return schema.nullish();
156
+ }
157
+ var idSchema = zod.z.union([zod.z.number(), zod.z.string()]);
158
+ var boolishSchema = zod.z.union([
159
+ zod.z.boolean(),
160
+ zod.z.literal("0"),
161
+ zod.z.literal("1"),
162
+ zod.z.literal(0),
163
+ zod.z.literal(1)
164
+ ]);
165
+ var dateTimeSchema = zod.z.string();
166
+ function envelopeSchema(data) {
167
+ return zod.z.object({
168
+ success: zod.z.boolean(),
169
+ data,
170
+ message: zod.z.string().optional()
171
+ }).passthrough();
172
+ }
173
+ var paginationLinkSchema = loose({
174
+ url: zod.z.string().nullable(),
175
+ label: zod.z.string(),
176
+ active: zod.z.boolean()
177
+ });
178
+ function offsetPaginatedSchema(item) {
179
+ return loose({
180
+ current_page: zod.z.number(),
181
+ data: zod.z.array(item),
182
+ first_page_url: zod.z.string().nullable().optional(),
183
+ from: zod.z.number().nullable().optional(),
184
+ last_page: zod.z.number(),
185
+ last_page_url: zod.z.string().nullable().optional(),
186
+ links: zod.z.array(paginationLinkSchema).optional(),
187
+ next_page_url: zod.z.string().nullable().optional(),
188
+ path: zod.z.string().optional(),
189
+ per_page: zod.z.union([zod.z.number(), zod.z.string()]),
190
+ prev_page_url: zod.z.string().nullable().optional(),
191
+ to: zod.z.number().nullable().optional(),
192
+ total: zod.z.number()
193
+ });
194
+ }
195
+ function cursorPaginatedSchema(item) {
196
+ return loose({
197
+ path: zod.z.string().optional(),
198
+ per_page: zod.z.union([zod.z.number(), zod.z.string()]),
199
+ next_cursor: zod.z.string().nullable().optional(),
200
+ next_page_url: zod.z.string().nullable().optional(),
201
+ prev_cursor: zod.z.string().nullable().optional(),
202
+ prev_page_url: zod.z.string().nullable().optional(),
203
+ data: zod.z.array(item)
204
+ });
205
+ }
206
+ var addressSchema = loose({
207
+ postcode: nullish(zod.z.string()),
208
+ housenumber: nullish(zod.z.union([zod.z.string(), zod.z.number()])),
209
+ suffix: nullish(zod.z.string()),
210
+ streetname: nullish(zod.z.string()),
211
+ city: nullish(zod.z.string())
212
+ });
213
+ var customerSchema = loose({
214
+ gender: nullish(zod.z.string()),
215
+ initials: nullish(zod.z.string()),
216
+ firstname: nullish(zod.z.string()),
217
+ infix: nullish(zod.z.string()),
218
+ lastname: nullish(zod.z.string()),
219
+ birthdate: nullish(zod.z.string()),
220
+ email: nullish(zod.z.string()),
221
+ phone: nullish(zod.z.string()),
222
+ business: nullish(zod.z.union([zod.z.boolean(), zod.z.string(), zod.z.number()])),
223
+ company_name: nullish(zod.z.string()),
224
+ contact_person: nullish(zod.z.string()),
225
+ coc: nullish(zod.z.string()),
226
+ vat: nullish(zod.z.string()),
227
+ iban: nullish(zod.z.string()),
228
+ iban_holder: nullish(zod.z.string()),
229
+ address: addressSchema.optional()
230
+ });
231
+ var extraFieldSchema = loose({
232
+ id: idSchema.optional(),
233
+ identifier: nullish(zod.z.string()),
234
+ type: nullish(zod.z.string()),
235
+ label: nullish(zod.z.string()),
236
+ value: zod.z.unknown().optional()
237
+ });
238
+ var statusSchema = loose({
239
+ status_identifier: nullish(zod.z.string()),
240
+ status: nullish(zod.z.string()),
241
+ status_remark: nullish(zod.z.string())
242
+ });
243
+
244
+ // src/core/http.ts
245
+ var RETRYABLE_5XX = /* @__PURE__ */ new Set([500, 502, 503, 504]);
246
+ var HttpClient = class {
247
+ constructor(config) {
248
+ this.config = config;
249
+ }
250
+ /** Execute a request and return the validated `data` payload. */
251
+ async request(req) {
252
+ const url = this.buildUrl(req.segments, req.query);
253
+ return this.send(req.method, url, req.dataSchema, req.body, req.options);
254
+ }
255
+ /** Build a full request URL from path segments and query parameters. */
256
+ buildUrl(segments, query) {
257
+ const base = `${this.config.baseUrl}/api/${encodeURIComponent(
258
+ this.config.domain
259
+ )}/${encodeURIComponent(this.config.version)}`;
260
+ const path = segments.map((s) => encodeURIComponent(String(s))).join("/");
261
+ const qs = buildQueryString(query);
262
+ return `${base}/${path}${qs ? `?${qs}` : ""}`;
263
+ }
264
+ async send(method, url, dataSchema, body, options) {
265
+ const headers = this.buildHeaders(body !== void 0, options?.headers);
266
+ const serializedBody = body !== void 0 ? JSON.stringify(body) : void 0;
267
+ const safeToRetry = options?.idempotent ?? method === "GET";
268
+ const maxAttempts = this.config.maxRetries + 1;
269
+ let lastError;
270
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
271
+ const isLastAttempt = attempt === maxAttempts - 1;
272
+ await this.config.onRequest?.({ method, url, headers, body: serializedBody });
273
+ const started = nowMs();
274
+ let res;
275
+ try {
276
+ res = await this.fetchWithTimeout(method, url, headers, serializedBody, options);
277
+ } catch (err) {
278
+ lastError = wrapNetworkError(err, url, method);
279
+ const aborted = options?.signal?.aborted === true;
280
+ const isTimeout = err instanceof SalesdockTimeoutError;
281
+ if (!aborted && !isTimeout && safeToRetry && !isLastAttempt) {
282
+ await sleep(this.backoffDelay(attempt, void 0));
283
+ continue;
284
+ }
285
+ throw lastError;
286
+ }
287
+ const durationMs = nowMs() - started;
288
+ await this.config.onResponse?.({
289
+ method,
290
+ url,
291
+ status: res.status,
292
+ durationMs
293
+ });
294
+ const { parsedBody, rawText } = await readBody(res);
295
+ const success = res.ok && !(parsedBody && typeof parsedBody === "object" && parsedBody.success === false);
296
+ if (success) {
297
+ if (parsedBody === void 0) {
298
+ if (!rawText) return void 0;
299
+ throw new SalesdockError("Salesdock returned a non-JSON success response body.", {
300
+ status: res.status,
301
+ url,
302
+ method,
303
+ body: rawText
304
+ });
305
+ }
306
+ return this.validateResponse(dataSchema, parsedBody, url, method);
307
+ }
308
+ const retryAfterMs = parseRetryAfter(res.headers.get("retry-after"));
309
+ const statusRetryable = res.status === 429 || RETRYABLE_5XX.has(res.status) && safeToRetry;
310
+ if (statusRetryable && !isLastAttempt) {
311
+ await sleep(this.backoffDelay(attempt, retryAfterMs));
312
+ continue;
313
+ }
314
+ throw errorFromResponse(res.status, parsedBody ?? rawText, {
315
+ url,
316
+ method,
317
+ retryAfterMs
318
+ });
319
+ }
320
+ throw lastError instanceof Error ? lastError : new SalesdockConnectionError("Request failed", { url, method });
321
+ }
322
+ validateResponse(dataSchema, parsedBody, url, method) {
323
+ if (!this.config.validateResponses) {
324
+ if (parsedBody && typeof parsedBody === "object" && "data" in parsedBody) {
325
+ return parsedBody.data;
326
+ }
327
+ return parsedBody;
328
+ }
329
+ const schema = envelopeSchema(dataSchema);
330
+ const result = schema.safeParse(parsedBody);
331
+ if (!result.success) {
332
+ throw new SalesdockResponseValidationError(
333
+ "Salesdock response did not match the expected schema. If the API changed, you can disable this check with `validateResponses: false`.",
334
+ result.error,
335
+ { url, method, body: parsedBody }
336
+ );
337
+ }
338
+ return result.data.data;
339
+ }
340
+ buildHeaders(hasBody, extra) {
341
+ const headers = {
342
+ Accept: "application/json",
343
+ Authorization: `Bearer ${this.config.token}`,
344
+ ...this.config.headers
345
+ };
346
+ if (hasBody) headers["Content-Type"] = "application/json";
347
+ if (this.config.userAgent) {
348
+ headers["User-Agent"] = `salesdock-sdk/${SDK_VERSION} ${this.config.userAgent}`;
349
+ }
350
+ if (extra) Object.assign(headers, extra);
351
+ return headers;
352
+ }
353
+ async fetchWithTimeout(method, url, headers, body, options) {
354
+ const timeout = options?.timeout ?? this.config.timeout;
355
+ const controller = timeout > 0 ? new AbortController() : void 0;
356
+ let timer;
357
+ let timedOut = false;
358
+ if (controller && timeout > 0) {
359
+ timer = setTimeout(() => {
360
+ timedOut = true;
361
+ controller.abort();
362
+ }, timeout);
363
+ }
364
+ const onExternalAbort = () => controller?.abort();
365
+ if (options?.signal) {
366
+ if (options.signal.aborted) controller?.abort();
367
+ else options.signal.addEventListener("abort", onExternalAbort, { once: true });
368
+ }
369
+ try {
370
+ const signal = controller?.signal ?? options?.signal;
371
+ return await this.config.fetch(url, {
372
+ method,
373
+ headers,
374
+ body,
375
+ signal
376
+ });
377
+ } catch (err) {
378
+ if (timedOut) {
379
+ throw new SalesdockTimeoutError(`Request timed out after ${timeout}ms`, {
380
+ url,
381
+ method,
382
+ cause: err
383
+ });
384
+ }
385
+ throw err;
386
+ } finally {
387
+ if (timer) clearTimeout(timer);
388
+ if (options?.signal) options.signal.removeEventListener("abort", onExternalAbort);
389
+ }
390
+ }
391
+ backoffDelay(attempt, retryAfterMs) {
392
+ if (retryAfterMs !== void 0) return retryAfterMs;
393
+ const base = this.config.retryDelayMs * Math.pow(2, attempt);
394
+ const jitter = base * 0.25 * Math.random();
395
+ return Math.round(base + jitter);
396
+ }
397
+ };
398
+ function buildQueryString(query) {
399
+ if (!query) return "";
400
+ const params = new URLSearchParams();
401
+ for (const [key, value] of Object.entries(query)) {
402
+ if (value === null || value === void 0) continue;
403
+ if (Array.isArray(value)) {
404
+ for (const v of value) {
405
+ if (v === null || v === void 0) continue;
406
+ params.append(`${key}[]`, String(v));
407
+ }
408
+ } else {
409
+ params.append(key, String(value));
410
+ }
411
+ }
412
+ return params.toString();
413
+ }
414
+ async function readBody(res) {
415
+ let rawText = "";
416
+ try {
417
+ rawText = await res.text();
418
+ } catch {
419
+ return { parsedBody: void 0, rawText: "" };
420
+ }
421
+ if (!rawText) return { parsedBody: void 0, rawText };
422
+ try {
423
+ return { parsedBody: JSON.parse(rawText), rawText };
424
+ } catch {
425
+ return { parsedBody: void 0, rawText };
426
+ }
427
+ }
428
+ function parseRetryAfter(value) {
429
+ if (!value) return void 0;
430
+ const seconds = Number(value);
431
+ if (!Number.isNaN(seconds)) return Math.max(0, seconds * 1e3);
432
+ const date = Date.parse(value);
433
+ if (!Number.isNaN(date)) return Math.max(0, date - Date.now());
434
+ return void 0;
435
+ }
436
+ function wrapNetworkError(err, url, method) {
437
+ if (err instanceof SalesdockTimeoutError) return err;
438
+ return new SalesdockConnectionError(
439
+ err instanceof Error ? err.message : "Network request failed",
440
+ { url, method, cause: err }
441
+ );
442
+ }
443
+ function sleep(ms) {
444
+ return new Promise((resolve) => setTimeout(resolve, ms));
445
+ }
446
+ function nowMs() {
447
+ return Date.now();
448
+ }
449
+
450
+ // src/resources/base.ts
451
+ var BaseResource = class {
452
+ constructor(http, config) {
453
+ this.http = http;
454
+ this.config = config;
455
+ }
456
+ /** Resolve the scope segment for a call (per-call override beats config). */
457
+ scope(options) {
458
+ return options?.scope ?? this.config.scope;
459
+ }
460
+ /**
461
+ * Validate request input against a Zod schema when request validation is
462
+ * enabled, returning the parsed value. Throws
463
+ * {@link SalesdockInvalidRequestError} on failure (before any network call).
464
+ */
465
+ parseInput(schema, value, label) {
466
+ if (!this.config.validateRequests) return value;
467
+ const result = schema.safeParse(value);
468
+ if (!result.success) {
469
+ throw new SalesdockInvalidRequestError(
470
+ `Invalid input for ${label}: ${summarize(result.error)}`,
471
+ result.error
472
+ );
473
+ }
474
+ return result.data;
475
+ }
476
+ };
477
+ function summarize(error) {
478
+ return error.issues.slice(0, 5).map((i) => `${i.path.join(".") || "(root)"}: ${i.message}`).join("; ");
479
+ }
480
+
481
+ // src/core/pagination.ts
482
+ var OffsetPage = class _OffsetPage {
483
+ constructor(meta, loader) {
484
+ this.loader = loader;
485
+ this.meta = meta;
486
+ this.items = meta.data ?? [];
487
+ }
488
+ get currentPage() {
489
+ return this.meta.current_page;
490
+ }
491
+ get lastPage() {
492
+ return this.meta.last_page;
493
+ }
494
+ get perPage() {
495
+ const n = Number(this.meta.per_page);
496
+ return Number.isFinite(n) ? n : 0;
497
+ }
498
+ get total() {
499
+ return this.meta.total;
500
+ }
501
+ get hasNextPage() {
502
+ return Boolean(this.meta.next_page_url);
503
+ }
504
+ get hasPrevPage() {
505
+ return Boolean(this.meta.prev_page_url);
506
+ }
507
+ /** Fetch the next page, or `null` if there is none. */
508
+ async nextPage() {
509
+ if (!this.meta.next_page_url) return null;
510
+ const meta = await this.loader(this.meta.next_page_url);
511
+ return new _OffsetPage(meta, this.loader);
512
+ }
513
+ /** Fetch the previous page, or `null` if there is none. */
514
+ async prevPage() {
515
+ if (!this.meta.prev_page_url) return null;
516
+ const meta = await this.loader(this.meta.prev_page_url);
517
+ return new _OffsetPage(meta, this.loader);
518
+ }
519
+ /** Collect every item across this and all following pages into one array. */
520
+ async all() {
521
+ const out = [];
522
+ for await (const item of this) out.push(item);
523
+ return out;
524
+ }
525
+ /** Async-iterate items across this and all subsequent pages. */
526
+ async *[Symbol.asyncIterator]() {
527
+ let page = this;
528
+ while (page) {
529
+ for (const item of page.items) yield item;
530
+ page = await page.nextPage();
531
+ }
532
+ }
533
+ };
534
+ var CursorPage = class _CursorPage {
535
+ constructor(meta, loader) {
536
+ this.loader = loader;
537
+ this.meta = meta;
538
+ this.items = meta.data ?? [];
539
+ }
540
+ get perPage() {
541
+ const n = Number(this.meta.per_page);
542
+ return Number.isFinite(n) ? n : 0;
543
+ }
544
+ get nextCursor() {
545
+ return this.meta.next_cursor ?? null;
546
+ }
547
+ get prevCursor() {
548
+ return this.meta.prev_cursor ?? null;
549
+ }
550
+ get hasNextPage() {
551
+ return Boolean(this.meta.next_page_url);
552
+ }
553
+ get hasPrevPage() {
554
+ return Boolean(this.meta.prev_page_url);
555
+ }
556
+ /** Fetch the next page, or `null` if there is none. */
557
+ async nextPage() {
558
+ if (!this.meta.next_page_url) return null;
559
+ const meta = await this.loader(this.meta.next_page_url);
560
+ return new _CursorPage(meta, this.loader);
561
+ }
562
+ /** Fetch the previous page, or `null` if there is none. */
563
+ async prevPage() {
564
+ if (!this.meta.prev_page_url) return null;
565
+ const meta = await this.loader(this.meta.prev_page_url);
566
+ return new _CursorPage(meta, this.loader);
567
+ }
568
+ /** Collect every item across this and all following pages into one array. */
569
+ async all() {
570
+ const out = [];
571
+ for await (const item of this) out.push(item);
572
+ return out;
573
+ }
574
+ /** Async-iterate items across this and all subsequent pages. */
575
+ async *[Symbol.asyncIterator]() {
576
+ let page = this;
577
+ while (page) {
578
+ for (const item of page.items) yield item;
579
+ page = await page.nextPage();
580
+ }
581
+ }
582
+ };
583
+ async function fetchOffsetPage(http, itemSchema, segments, query, options) {
584
+ const schema = offsetPaginatedSchema(itemSchema);
585
+ const loader = (url) => http.request({
586
+ method: "GET",
587
+ segments,
588
+ dataSchema: schema,
589
+ query: mergePageQuery(query, url),
590
+ options
591
+ });
592
+ const meta = await http.request({
593
+ method: "GET",
594
+ segments,
595
+ dataSchema: schema,
596
+ query,
597
+ options
598
+ });
599
+ return new OffsetPage(meta, loader);
600
+ }
601
+ async function fetchCursorPage(http, itemSchema, segments, query, options) {
602
+ const schema = cursorPaginatedSchema(itemSchema);
603
+ const loader = (url) => http.request({
604
+ method: "GET",
605
+ segments,
606
+ dataSchema: schema,
607
+ query: mergePageQuery(query, url),
608
+ options
609
+ });
610
+ const meta = await http.request({
611
+ method: "GET",
612
+ segments,
613
+ dataSchema: schema,
614
+ query,
615
+ options
616
+ });
617
+ return new CursorPage(meta, loader);
618
+ }
619
+ function mergePageQuery(original, pageUrl) {
620
+ const out = { ...original ?? {} };
621
+ let search;
622
+ try {
623
+ search = new URL(pageUrl).searchParams;
624
+ } catch {
625
+ return out;
626
+ }
627
+ for (const rawKey of new Set(search.keys())) {
628
+ const key = rawKey.endsWith("[]") ? rawKey.slice(0, -2) : rawKey;
629
+ const all = search.getAll(rawKey);
630
+ out[key] = rawKey.endsWith("[]") || all.length > 1 ? all : all[0];
631
+ }
632
+ return out;
633
+ }
634
+
635
+ // src/resources/sales.ts
636
+ var CreateSaleResultSchema = loose({ sale_id: idSchema });
637
+ var MutateSaleResultSchema = loose({ sale_id: idSchema });
638
+ var saleCreateBaseShape = {
639
+ transaction_type: zod.z.enum(["offer", "order"]).optional(),
640
+ sale_channel: zod.z.string().optional(),
641
+ product_id: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
642
+ // Customer
643
+ gender: zod.z.string().optional(),
644
+ firstname: zod.z.string().optional(),
645
+ lastname: zod.z.string().optional(),
646
+ birthdate: zod.z.string().nullable().optional(),
647
+ email: zod.z.string().optional(),
648
+ phone: zod.z.string().optional(),
649
+ contact_person: zod.z.string().nullable().optional(),
650
+ company_name: zod.z.string().nullable().optional(),
651
+ company_coc: zod.z.string().nullable().optional(),
652
+ company_coc_branch_number: zod.z.string().nullable().optional(),
653
+ company_vat: zod.z.string().nullable().optional(),
654
+ iban: zod.z.string().optional(),
655
+ iban_holder: zod.z.string().optional(),
656
+ business: zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean()]).optional(),
657
+ // Address
658
+ postcode: zod.z.string().optional(),
659
+ housenumber: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
660
+ suffix: zod.z.string().nullable().optional(),
661
+ streetname: zod.z.string().optional(),
662
+ city: zod.z.string().optional(),
663
+ // Connection address
664
+ connection_postcode: zod.z.string().optional(),
665
+ connection_housenumber: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
666
+ connection_suffix: zod.z.string().nullable().optional(),
667
+ connection_streetname: zod.z.string().optional(),
668
+ connection_city: zod.z.string().optional(),
669
+ // Misc
670
+ valid_till: zod.z.string().optional(),
671
+ signature: zod.z.string().optional(),
672
+ initial_user_firstname: zod.z.string().optional(),
673
+ initial_user_lastname: zod.z.string().optional(),
674
+ initial_organisation_name: zod.z.string().optional(),
675
+ // Free-form question answers and agreement acceptances (identifier -> value)
676
+ questionData: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
677
+ agreements: zod.z.record(zod.z.string(), zod.z.unknown()).optional()
678
+ };
679
+ var energyFieldsShape = {
680
+ type: zod.z.string().optional(),
681
+ has_return: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
682
+ building_function: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
683
+ return: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
684
+ return_e_high: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
685
+ return_e_low: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
686
+ usage_e_single: zod.z.union([zod.z.string(), zod.z.number()]).nullable().optional(),
687
+ usage_e_high: zod.z.union([zod.z.string(), zod.z.number()]).nullable().optional(),
688
+ usage_e_low: zod.z.union([zod.z.string(), zod.z.number()]).nullable().optional(),
689
+ usage_g: zod.z.union([zod.z.string(), zod.z.number()]).nullable().optional(),
690
+ tarifftype: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
691
+ e_gridoperator: zod.z.string().optional(),
692
+ g_gridoperator: zod.z.string().optional(),
693
+ e_connection_type: zod.z.string().optional(),
694
+ g_connection_type: zod.z.string().optional(),
695
+ g_region: zod.z.string().optional(),
696
+ electricity_ean: zod.z.string().nullable().optional(),
697
+ gas_ean: zod.z.string().nullable().optional(),
698
+ delivery_mainly_private: zod.z.union([zod.z.string(), zod.z.number()]).optional()
699
+ };
700
+ var EnergyNlSaleInputSchema = zod.z.object({ ...saleCreateBaseShape, ...energyFieldsShape }).passthrough();
701
+ var EnergyBeSaleInputSchema = zod.z.object({
702
+ ...saleCreateBaseShape,
703
+ ...energyFieldsShape,
704
+ e_measurement_frequency: zod.z.string().optional(),
705
+ g_measurement_frequency: zod.z.string().optional(),
706
+ exclusive_night: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
707
+ usage_e_exclusive: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
708
+ region: zod.z.string().optional(),
709
+ e_grid_operator: zod.z.string().optional(),
710
+ g_grid_operator: zod.z.string().optional()
711
+ }).passthrough();
712
+ var relatedProductsSchema = zod.z.union([zod.z.record(zod.z.string(), zod.z.unknown()), zod.z.array(zod.z.unknown())]).optional();
713
+ var TelecomSaleInputSchema = zod.z.object({ ...saleCreateBaseShape, related_products: relatedProductsSchema }).passthrough();
714
+ var HostedVoiceSaleInputSchema = zod.z.object({
715
+ ...saleCreateBaseShape,
716
+ includes_internet: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
717
+ related_products: relatedProductsSchema
718
+ }).passthrough();
719
+ var SolarSaleInputSchema = zod.z.object({
720
+ ...saleCreateBaseShape,
721
+ sell_type: zod.z.string().optional(),
722
+ usage: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
723
+ building_type: zod.z.string().optional(),
724
+ household_size: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
725
+ address: zod.z.string().optional(),
726
+ country: zod.z.string().optional(),
727
+ area: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
728
+ panel_product: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
729
+ panel_count: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
730
+ option_products: zod.z.array(zod.z.unknown()).optional()
731
+ }).passthrough();
732
+ var HeatPumpSaleInputSchema = zod.z.object({
733
+ ...saleCreateBaseShape,
734
+ sell_type: zod.z.string().optional(),
735
+ number_of_persons: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
736
+ electricity_usage: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
737
+ gas_usage: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
738
+ heating_system: zod.z.string().optional(),
739
+ gas_usage_tap_water_per_person: zod.z.union([zod.z.string(), zod.z.number()]).optional()
740
+ }).passthrough();
741
+ var DefaultSaleInputSchema = zod.z.object(saleCreateBaseShape).passthrough();
742
+ var MultiProductSaleInputSchema = zod.z.object({
743
+ ...saleCreateBaseShape,
744
+ related_products: zod.z.array(
745
+ zod.z.object({
746
+ product_id: zod.z.union([zod.z.string(), zod.z.number()]),
747
+ quantity: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
748
+ section_identifier: zod.z.string().optional()
749
+ }).passthrough()
750
+ ).optional()
751
+ }).passthrough();
752
+ var mutationBlockSchema = zod.z.object({
753
+ delete: zod.z.array(zod.z.union([zod.z.string(), zod.z.number()])).optional(),
754
+ upsert: zod.z.unknown().optional()
755
+ }).passthrough();
756
+ var UpdateSaleInputSchema = zod.z.object({
757
+ product_id: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
758
+ valid_till: zod.z.string().optional(),
759
+ customer: zod.z.object({
760
+ business: zod.z.union([zod.z.boolean(), zod.z.string(), zod.z.number()]).optional(),
761
+ gender: zod.z.string().optional(),
762
+ firstname: zod.z.string().optional(),
763
+ lastname: zod.z.string().optional(),
764
+ birthdate: zod.z.string().nullable().optional(),
765
+ email: zod.z.string().optional(),
766
+ phone: zod.z.string().nullable().optional(),
767
+ company_name: zod.z.string().nullable().optional(),
768
+ contact_person: zod.z.string().nullable().optional(),
769
+ coc: zod.z.string().nullable().optional(),
770
+ vat: zod.z.string().nullable().optional(),
771
+ address: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
772
+ correspondence_address: zod.z.record(zod.z.string(), zod.z.unknown()).optional()
773
+ }).passthrough().optional(),
774
+ product_questions: mutationBlockSchema.optional(),
775
+ agreements: mutationBlockSchema.optional()
776
+ }).passthrough();
777
+ var UpdateEnergyProductInputSchema = zod.z.object({
778
+ type: zod.z.string().optional(),
779
+ active: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
780
+ valid_from: zod.z.string().optional(),
781
+ valid_till: zod.z.string().optional(),
782
+ tariff_single: zod.z.string().optional(),
783
+ tariff_high: zod.z.string().optional(),
784
+ tariff_low: zod.z.string().optional(),
785
+ tariff_high_t2: zod.z.string().optional(),
786
+ tariff_low_t2: zod.z.string().optional(),
787
+ tariff_return: zod.z.string().optional(),
788
+ tariff_return_high: zod.z.string().optional(),
789
+ tariff_return_low: zod.z.string().optional(),
790
+ tariff_fixed_e: zod.z.string().optional(),
791
+ g_region_tax_level: zod.z.string().optional(),
792
+ tariff_g: zod.z.string().optional(),
793
+ tariff_g_g2: zod.z.string().optional(),
794
+ tariff_fixed_g: zod.z.string().optional(),
795
+ product_type: zod.z.string().optional()
796
+ }).passthrough();
797
+ var UpdateSaleFieldsInputSchema = zod.z.record(zod.z.string(), zod.z.unknown());
798
+ var CreateOptinInputSchema = zod.z.record(zod.z.string(), zod.z.unknown());
799
+ var SaleListItemSchema = loose({
800
+ id: idSchema,
801
+ user_id: nullish(idSchema),
802
+ type: nullish(zod.z.string()),
803
+ sub_type: nullish(zod.z.string()),
804
+ offer: nullish(zod.z.unknown()),
805
+ offer_accepted: nullish(zod.z.unknown()),
806
+ status: nullish(zod.z.union([zod.z.string(), statusSchema])),
807
+ verification: nullish(zod.z.unknown()),
808
+ flow_id: nullish(idSchema),
809
+ product_id: nullish(idSchema),
810
+ incoming_id: nullish(idSchema),
811
+ created_at: nullish(zod.z.string()),
812
+ finalized_at: nullish(zod.z.string()),
813
+ updated_at: nullish(zod.z.string()),
814
+ valid_till: nullish(zod.z.string()),
815
+ firstname: nullish(zod.z.string()),
816
+ lastname: nullish(zod.z.string()),
817
+ email: nullish(zod.z.string()),
818
+ phone: nullish(zod.z.string()),
819
+ product_name: nullish(zod.z.string()),
820
+ supplier_name: nullish(zod.z.string()),
821
+ lead_id: nullish(idSchema),
822
+ relation_id: nullish(idSchema)
823
+ });
824
+ var SaleSchema = loose({
825
+ id: idSchema,
826
+ type: nullish(zod.z.string()),
827
+ status: statusSchema.optional(),
828
+ offer_accepted: nullish(zod.z.boolean()),
829
+ offer_valid_till: nullish(zod.z.string()),
830
+ created_at: nullish(zod.z.string()),
831
+ finalized_at: nullish(zod.z.string()),
832
+ updated_at: nullish(zod.z.string()),
833
+ channel: nullish(zod.z.string()),
834
+ source: nullish(zod.z.string()),
835
+ customer: customerSchema.optional()
836
+ });
837
+ var SaleExportRowSchema = zod.z.record(zod.z.string(), zod.z.unknown());
838
+ var FlowListItemSchema = loose({
839
+ id: idSchema,
840
+ title: nullish(zod.z.string()),
841
+ type: nullish(zod.z.string()),
842
+ identifier: nullish(zod.z.string()),
843
+ created_at: nullish(zod.z.string()),
844
+ updated_at: nullish(zod.z.string())
845
+ });
846
+ var FlowSchema = loose({
847
+ id: idSchema,
848
+ title: nullish(zod.z.string()),
849
+ type: nullish(zod.z.string()),
850
+ identifier: nullish(zod.z.string()),
851
+ transaction_type: nullish(zod.z.string()),
852
+ verification_method: nullish(zod.z.string()),
853
+ created_at: nullish(zod.z.string()),
854
+ updated_at: nullish(zod.z.string())
855
+ });
856
+ var ProductQuestionListItemSchema = loose({
857
+ id: idSchema,
858
+ name: nullish(zod.z.string()),
859
+ identifier: nullish(zod.z.string()),
860
+ input_type: nullish(zod.z.string()),
861
+ description: nullish(zod.z.string())
862
+ });
863
+ var ProductQuestionSchema = loose({
864
+ id: idSchema,
865
+ name: nullish(zod.z.string()),
866
+ identifier: nullish(zod.z.string()),
867
+ input_type: nullish(zod.z.string()),
868
+ description: nullish(zod.z.string()),
869
+ required: nullish(zod.z.unknown()),
870
+ visible: nullish(zod.z.unknown()),
871
+ options: nullish(zod.z.unknown()),
872
+ default_value: nullish(zod.z.unknown()),
873
+ created_at: nullish(zod.z.string()),
874
+ updated_at: nullish(zod.z.string())
875
+ });
876
+ var AgreementListItemSchema = loose({
877
+ id: idSchema,
878
+ identifier: nullish(zod.z.string()),
879
+ name: nullish(zod.z.string()),
880
+ text: nullish(zod.z.string())
881
+ });
882
+ var AgreementSchema = loose({
883
+ id: idSchema,
884
+ account_id: nullish(idSchema),
885
+ name: nullish(zod.z.string()),
886
+ identifier: nullish(zod.z.string()),
887
+ text: nullish(zod.z.string()),
888
+ description: nullish(zod.z.string()),
889
+ type: nullish(zod.z.string()),
890
+ required: nullish(zod.z.unknown()),
891
+ created_at: nullish(zod.z.string())
892
+ });
893
+ var EnergyProductSchema = loose({
894
+ id: idSchema,
895
+ name: nullish(zod.z.string()),
896
+ identifier: nullish(zod.z.string()),
897
+ supplier_id: nullish(idSchema),
898
+ type: nullish(zod.z.string()),
899
+ business: nullish(zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean()])),
900
+ cost_specifications: nullish(zod.z.unknown()),
901
+ valid_from: nullish(zod.z.string()),
902
+ valid_till: nullish(zod.z.string())
903
+ });
904
+ var SaleStatusSchema = loose({
905
+ source: nullish(zod.z.string()),
906
+ id: nullish(idSchema),
907
+ name: nullish(zod.z.string()),
908
+ text: nullish(zod.z.string()),
909
+ type: nullish(zod.z.string()),
910
+ source_data: nullish(zod.z.unknown())
911
+ });
912
+ var SaleDocumentSchema = loose({
913
+ name: nullish(zod.z.string()),
914
+ location: nullish(zod.z.string())
915
+ });
916
+ var SaleHistoryEntrySchema = loose({
917
+ type: nullish(zod.z.string()),
918
+ modified_at: nullish(zod.z.string()),
919
+ previous_status: nullish(zod.z.unknown()),
920
+ new_status: nullish(zod.z.unknown()),
921
+ remark: nullish(zod.z.string()),
922
+ user: nullish(zod.z.unknown()),
923
+ type_data: nullish(zod.z.unknown())
924
+ });
925
+ var SaleProductsSchema = loose({
926
+ sale_id: idSchema,
927
+ products: nullish(zod.z.unknown()),
928
+ additional_costs: nullish(zod.z.unknown()),
929
+ discounts: nullish(zod.z.unknown()),
930
+ totals: nullish(zod.z.unknown())
931
+ });
932
+ var SaleOfLeadSchema = loose({ id: idSchema });
933
+ var SaleContractSchema = loose({
934
+ id: idSchema,
935
+ contract: loose({ content: nullish(zod.z.string()) }).optional()
936
+ });
937
+ var EnergyUsageEstimationSchema = loose({
938
+ type: nullish(zod.z.string()),
939
+ e_single: nullish(zod.z.union([zod.z.string(), zod.z.number()])),
940
+ e_high: nullish(zod.z.union([zod.z.string(), zod.z.number()])),
941
+ e_low: nullish(zod.z.union([zod.z.string(), zod.z.number()])),
942
+ gas: nullish(zod.z.union([zod.z.string(), zod.z.number()]))
943
+ });
944
+ var PanelsEstimationSchema = loose({
945
+ number_of_panels: nullish(zod.z.union([zod.z.string(), zod.z.number()]))
946
+ });
947
+ var TelecomCompareSchema = loose({
948
+ address: nullish(zod.z.unknown()),
949
+ bandwidth: nullish(zod.z.unknown()),
950
+ products: nullish(zod.z.unknown()),
951
+ options: nullish(zod.z.unknown())
952
+ });
953
+ var SolarComparePackageSchema = loose({ packages: nullish(zod.z.unknown()) });
954
+ var SaleMutationsBase = class extends BaseResource {
955
+ /** PATCH a sale proposal: `{scope}/proposal/{saleId}`. */
956
+ patchProposal(saleId, input, label, options) {
957
+ const body = this.parseInput(UpdateSaleInputSchema, input, label);
958
+ return this.http.request({
959
+ method: "PATCH",
960
+ segments: [this.scope(options), "proposal", saleId],
961
+ dataSchema: MutateSaleResultSchema,
962
+ body,
963
+ options
964
+ });
965
+ }
966
+ /** PATCH a finalized sale: `account/sales/{saleId}` (always `account` scope). */
967
+ patchFinalized(saleId, input, label, options) {
968
+ const body = this.parseInput(UpdateSaleInputSchema, input, label);
969
+ return this.http.request({
970
+ method: "PATCH",
971
+ segments: ["account", "sales", saleId],
972
+ dataSchema: MutateSaleResultSchema,
973
+ body,
974
+ options
975
+ });
976
+ }
977
+ };
978
+ var EnergyNlClient = class extends BaseResource {
979
+ /**
980
+ * Create an energy sale (offer or order) on a NL flow. `flowType` is your
981
+ * flow's type identifier and `flowIdentifier` the flow identifier.
982
+ */
983
+ create(flowType, flowIdentifier, input, options) {
984
+ const body = this.parseInput(EnergyNlSaleInputSchema, input, "sales.energy.nl.create");
985
+ return this.http.request({
986
+ method: "POST",
987
+ segments: ["sales", "flow", flowType, flowIdentifier],
988
+ dataSchema: CreateSaleResultSchema,
989
+ body,
990
+ options
991
+ });
992
+ }
993
+ /** List energy products with tariff + calculation for the given address/usage. */
994
+ listProducts(params, options) {
995
+ return this.http.request({
996
+ method: "GET",
997
+ segments: ["user", "products", "energy"],
998
+ dataSchema: zod.z.array(EnergyProductSchema),
999
+ query: params,
1000
+ options
1001
+ });
1002
+ }
1003
+ /** Get a single energy product (by id) with tariff + calculation. */
1004
+ getProduct(productId, params, options) {
1005
+ return this.http.request({
1006
+ method: "GET",
1007
+ segments: ["user", "products", productId, "energy"],
1008
+ dataSchema: EnergyProductSchema,
1009
+ query: params,
1010
+ options
1011
+ });
1012
+ }
1013
+ /** Update an energy product's tariffs. */
1014
+ updateProduct(productId, input, options) {
1015
+ const body = this.parseInput(
1016
+ UpdateEnergyProductInputSchema,
1017
+ input,
1018
+ "sales.energy.nl.updateProduct"
1019
+ );
1020
+ return this.http.request({
1021
+ method: "PUT",
1022
+ segments: ["account", "products", productId, "energy"],
1023
+ dataSchema: zod.z.unknown(),
1024
+ body,
1025
+ options
1026
+ });
1027
+ }
1028
+ };
1029
+ var EnergyBeClient = class extends BaseResource {
1030
+ /** Create an energy sale on a BE flow. */
1031
+ create(flowType, flowIdentifier, input, options) {
1032
+ const body = this.parseInput(EnergyBeSaleInputSchema, input, "sales.energy.be.create");
1033
+ return this.http.request({
1034
+ method: "POST",
1035
+ segments: ["sales", "flow", flowType, flowIdentifier],
1036
+ dataSchema: CreateSaleResultSchema,
1037
+ body,
1038
+ options
1039
+ });
1040
+ }
1041
+ /** List BE energy products with tariffs + calculations. */
1042
+ listProducts(params, options) {
1043
+ return this.http.request({
1044
+ method: "GET",
1045
+ segments: ["user", "products", "energy-be"],
1046
+ dataSchema: zod.z.array(EnergyProductSchema),
1047
+ query: params,
1048
+ options
1049
+ });
1050
+ }
1051
+ };
1052
+ var EnergyClient = class extends BaseResource {
1053
+ constructor(http, config) {
1054
+ super(http, config);
1055
+ this.nl = new EnergyNlClient(http, config);
1056
+ this.be = new EnergyBeClient(http, config);
1057
+ }
1058
+ /** List energy sales (offset-paginated export-style rows). Honors the scope. */
1059
+ listSales(params = {}, options) {
1060
+ return fetchOffsetPage(
1061
+ this.http,
1062
+ SaleExportRowSchema,
1063
+ [this.scope(options), "sales", "energy"],
1064
+ params,
1065
+ options
1066
+ );
1067
+ }
1068
+ /** Estimate yearly energy usage for a household/business. */
1069
+ estimateUsage(params = {}, options) {
1070
+ return this.http.request({
1071
+ method: "GET",
1072
+ segments: ["user", "energy", "estimation"],
1073
+ dataSchema: EnergyUsageEstimationSchema,
1074
+ query: params,
1075
+ options
1076
+ });
1077
+ }
1078
+ };
1079
+ var TelecomClient = class extends SaleMutationsBase {
1080
+ /** Create a telecom sale (offer or order). */
1081
+ create(flowType, flowIdentifier, input, options) {
1082
+ const body = this.parseInput(TelecomSaleInputSchema, input, "sales.telecom.create");
1083
+ return this.http.request({
1084
+ method: "POST",
1085
+ segments: ["sales", "flow", flowType, flowIdentifier],
1086
+ dataSchema: CreateSaleResultSchema,
1087
+ body,
1088
+ options
1089
+ });
1090
+ }
1091
+ /** Update a telecom sale proposal. Honors the configured scope. */
1092
+ updateProposal(saleId, input, options) {
1093
+ return this.patchProposal(saleId, input, "sales.telecom.updateProposal", options);
1094
+ }
1095
+ /** Update a finalized telecom sale (always `account` scope). */
1096
+ updateFinalized(saleId, input, options) {
1097
+ return this.patchFinalized(saleId, input, "sales.telecom.updateFinalized", options);
1098
+ }
1099
+ /** Compare telecom availability/products for an address (no scope). */
1100
+ compare(input, options) {
1101
+ return this.http.request({
1102
+ method: "POST",
1103
+ segments: ["telecom", "compare"],
1104
+ dataSchema: TelecomCompareSchema,
1105
+ body: input,
1106
+ options
1107
+ });
1108
+ }
1109
+ };
1110
+ var HostedVoiceClient = class extends BaseResource {
1111
+ /** Create a hosted-voice sale. */
1112
+ create(flowType, flowIdentifier, input, options) {
1113
+ const body = this.parseInput(HostedVoiceSaleInputSchema, input, "sales.hostedVoice.create");
1114
+ return this.http.request({
1115
+ method: "POST",
1116
+ segments: ["sales", "flow", flowType, flowIdentifier],
1117
+ dataSchema: CreateSaleResultSchema,
1118
+ body,
1119
+ options
1120
+ });
1121
+ }
1122
+ };
1123
+ var SolarClient = class extends BaseResource {
1124
+ /** Create a solar-panel sale (flow type is fixed to `solar-panels`). */
1125
+ create(flowIdentifier, input, options) {
1126
+ const body = this.parseInput(SolarSaleInputSchema, input, "sales.solar.create");
1127
+ return this.http.request({
1128
+ method: "POST",
1129
+ segments: ["sales", "flow", "solar-panels", flowIdentifier],
1130
+ dataSchema: CreateSaleResultSchema,
1131
+ body,
1132
+ options
1133
+ });
1134
+ }
1135
+ /** Estimate the number of solar panels that fit a roof (no scope). */
1136
+ estimatePanels(params = {}, options) {
1137
+ return this.http.request({
1138
+ method: "GET",
1139
+ segments: ["solar", "estimate-panels"],
1140
+ dataSchema: PanelsEstimationSchema,
1141
+ query: params,
1142
+ options
1143
+ });
1144
+ }
1145
+ /** Compare solar packages for a configuration (no scope). */
1146
+ compare(input, options) {
1147
+ return this.http.request({
1148
+ method: "POST",
1149
+ segments: ["solar", "compare"],
1150
+ dataSchema: zod.z.array(SolarComparePackageSchema),
1151
+ body: input,
1152
+ options
1153
+ });
1154
+ }
1155
+ };
1156
+ var HeatPumpsClient = class extends SaleMutationsBase {
1157
+ /** Create a heat-pump sale (flow type is fixed to `heat-pump`). */
1158
+ create(flowIdentifier, input, options) {
1159
+ const body = this.parseInput(HeatPumpSaleInputSchema, input, "sales.heatPumps.create");
1160
+ return this.http.request({
1161
+ method: "POST",
1162
+ segments: ["sales", "flow", "heat-pump", flowIdentifier],
1163
+ dataSchema: CreateSaleResultSchema,
1164
+ body,
1165
+ options
1166
+ });
1167
+ }
1168
+ /** Update a heat-pump sale proposal. Honors the configured scope. */
1169
+ updateProposal(saleId, input, options) {
1170
+ return this.patchProposal(saleId, input, "sales.heatPumps.updateProposal", options);
1171
+ }
1172
+ /** Update a finalized heat-pump sale (always `account` scope). */
1173
+ updateFinalized(saleId, input, options) {
1174
+ return this.patchFinalized(saleId, input, "sales.heatPumps.updateFinalized", options);
1175
+ }
1176
+ };
1177
+ var SalesClient = class extends SaleMutationsBase {
1178
+ constructor(http, config) {
1179
+ super(http, config);
1180
+ this.energy = new EnergyClient(http, config);
1181
+ this.telecom = new TelecomClient(http, config);
1182
+ this.hostedVoice = new HostedVoiceClient(http, config);
1183
+ this.solar = new SolarClient(http, config);
1184
+ this.heatPumps = new HeatPumpsClient(http, config);
1185
+ }
1186
+ /* ----------------------------- Sales listing ---------------------------- */
1187
+ /** List sales (offset-paginated). Honors the configured scope. */
1188
+ list(params = {}, options) {
1189
+ return fetchOffsetPage(
1190
+ this.http,
1191
+ SaleListItemSchema,
1192
+ [this.scope(options), "sales"],
1193
+ params,
1194
+ options
1195
+ );
1196
+ }
1197
+ /** Retrieve a single sale by id. Honors the configured scope. */
1198
+ get(saleId, options) {
1199
+ return this.http.request({
1200
+ method: "GET",
1201
+ segments: [this.scope(options), "sales", saleId],
1202
+ dataSchema: SaleSchema,
1203
+ options
1204
+ });
1205
+ }
1206
+ /** Retrieve a sale's signed contract (base64 PDF in `contract.content`). */
1207
+ getContract(saleId, options) {
1208
+ return this.http.request({
1209
+ method: "GET",
1210
+ segments: ["account", "sales", "contract", saleId],
1211
+ dataSchema: SaleContractSchema,
1212
+ options
1213
+ });
1214
+ }
1215
+ /** Retrieve the answers (question identifier -> value) given for a sale. */
1216
+ getAnswers(saleId, options) {
1217
+ return this.http.request({
1218
+ method: "GET",
1219
+ segments: [this.scope(options), "sales", "answers", saleId],
1220
+ dataSchema: zod.z.record(zod.z.string(), zod.z.unknown()),
1221
+ options
1222
+ });
1223
+ }
1224
+ /** List sales rendered through an export template (offset-paginated rows). */
1225
+ listByExportTemplate(exportTemplate, params = {}, options) {
1226
+ return fetchOffsetPage(
1227
+ this.http,
1228
+ SaleExportRowSchema,
1229
+ ["account", "sales", "export", exportTemplate],
1230
+ params,
1231
+ options
1232
+ );
1233
+ }
1234
+ /* ------------------------------ Sale catalog ---------------------------- */
1235
+ /** List flows. Honors the configured scope. */
1236
+ listFlows(options) {
1237
+ return this.http.request({
1238
+ method: "GET",
1239
+ segments: [this.scope(options), "flows"],
1240
+ dataSchema: zod.z.array(FlowListItemSchema),
1241
+ options
1242
+ });
1243
+ }
1244
+ /** Get a single flow by id. */
1245
+ getFlow(flowId, options) {
1246
+ return this.http.request({
1247
+ method: "GET",
1248
+ segments: [this.scope(options), "flows", flowId],
1249
+ dataSchema: FlowSchema,
1250
+ options
1251
+ });
1252
+ }
1253
+ /** List product questions. */
1254
+ listProductQuestions(options) {
1255
+ return this.http.request({
1256
+ method: "GET",
1257
+ segments: [this.scope(options), "productquestions"],
1258
+ dataSchema: zod.z.array(ProductQuestionListItemSchema),
1259
+ options
1260
+ });
1261
+ }
1262
+ /** Get a single product question by id. */
1263
+ getProductQuestion(productQuestionId, options) {
1264
+ return this.http.request({
1265
+ method: "GET",
1266
+ segments: [this.scope(options), "productquestions", productQuestionId],
1267
+ dataSchema: ProductQuestionSchema,
1268
+ options
1269
+ });
1270
+ }
1271
+ /** List agreements. */
1272
+ listAgreements(options) {
1273
+ return this.http.request({
1274
+ method: "GET",
1275
+ segments: [this.scope(options), "agreements"],
1276
+ dataSchema: zod.z.array(AgreementListItemSchema),
1277
+ options
1278
+ });
1279
+ }
1280
+ /** Get a single agreement by id. */
1281
+ getAgreement(agreementId, options) {
1282
+ return this.http.request({
1283
+ method: "GET",
1284
+ segments: [this.scope(options), "agreements", agreementId],
1285
+ dataSchema: AgreementSchema,
1286
+ options
1287
+ });
1288
+ }
1289
+ /* ----------------------------- Create sales ----------------------------- */
1290
+ /**
1291
+ * Low-level create-sale call: POST to `sales/flow/{flowType}/{flowIdentifier}`
1292
+ * with an arbitrary body. Prefer the typed helpers (`createDefault`,
1293
+ * `sales.energy.nl.create`, `sales.telecom.create`, ...) where they exist.
1294
+ */
1295
+ createSale(flowType, flowIdentifier, body, options) {
1296
+ return this.http.request({
1297
+ method: "POST",
1298
+ segments: ["sales", "flow", flowType, flowIdentifier],
1299
+ dataSchema: CreateSaleResultSchema,
1300
+ body,
1301
+ options
1302
+ });
1303
+ }
1304
+ /** Create a default (generic) sale. */
1305
+ createDefault(flowType, flowIdentifier, input, options) {
1306
+ const body = this.parseInput(DefaultSaleInputSchema, input, "sales.createDefault");
1307
+ return this.http.request({
1308
+ method: "POST",
1309
+ segments: ["sales", "flow", flowType, flowIdentifier],
1310
+ dataSchema: CreateSaleResultSchema,
1311
+ body,
1312
+ options
1313
+ });
1314
+ }
1315
+ /** Create a default sale with multiple related products. */
1316
+ createDefaultMultiple(flowType, flowIdentifier, input, options) {
1317
+ const body = this.parseInput(MultiProductSaleInputSchema, input, "sales.createDefaultMultiple");
1318
+ return this.http.request({
1319
+ method: "POST",
1320
+ segments: ["sales", "flow", flowType, flowIdentifier],
1321
+ dataSchema: CreateSaleResultSchema,
1322
+ body,
1323
+ options
1324
+ });
1325
+ }
1326
+ /** Update a default sale proposal. Honors the configured scope. */
1327
+ updateDefaultProposal(saleId, input, options) {
1328
+ return this.patchProposal(saleId, input, "sales.updateDefaultProposal", options);
1329
+ }
1330
+ /** Update a finalized default sale (always `account` scope). */
1331
+ updateDefaultFinalized(saleId, input, options) {
1332
+ return this.patchFinalized(saleId, input, "sales.updateDefaultFinalized", options);
1333
+ }
1334
+ /* ------------------------- Statuses & extra fields ---------------------- */
1335
+ /** List the available sale statuses. Honors the configured scope. */
1336
+ listStatuses(params = {}, options) {
1337
+ return this.http.request({
1338
+ method: "GET",
1339
+ segments: [this.scope(options), "statuses"],
1340
+ dataSchema: zod.z.array(SaleStatusSchema),
1341
+ query: params,
1342
+ options
1343
+ });
1344
+ }
1345
+ /** Update a sale's status (always `account` scope). */
1346
+ updateStatus(saleId, params, options) {
1347
+ return this.http.request({
1348
+ method: "POST",
1349
+ segments: ["account", "sales", "updatestatus", saleId],
1350
+ dataSchema: zod.z.unknown(),
1351
+ query: params,
1352
+ options
1353
+ });
1354
+ }
1355
+ /** Update a sale's status by the incoming id (always `account` scope). */
1356
+ updateStatusByIncoming(incomingId, params, options) {
1357
+ return this.http.request({
1358
+ method: "POST",
1359
+ segments: ["account", "sales", "updatestatus", "incoming", incomingId],
1360
+ dataSchema: zod.z.unknown(),
1361
+ query: params,
1362
+ options
1363
+ });
1364
+ }
1365
+ /** Update a sale's extra field values (always `account` scope). */
1366
+ updateFields(saleId, fields, options) {
1367
+ const body = this.parseInput(UpdateSaleFieldsInputSchema, fields, "sales.updateFields");
1368
+ return this.http.request({
1369
+ method: "POST",
1370
+ segments: ["account", "sales", "updatefields", saleId],
1371
+ dataSchema: zod.z.unknown(),
1372
+ body,
1373
+ options
1374
+ });
1375
+ }
1376
+ /** Update a sale's extra field values by incoming id (always `account` scope). */
1377
+ updateFieldsByIncoming(incomingId, fields, options) {
1378
+ const body = this.parseInput(
1379
+ UpdateSaleFieldsInputSchema,
1380
+ fields,
1381
+ "sales.updateFieldsByIncoming"
1382
+ );
1383
+ return this.http.request({
1384
+ method: "POST",
1385
+ segments: ["account", "sales", "updatefields", "incoming", incomingId],
1386
+ dataSchema: zod.z.unknown(),
1387
+ body,
1388
+ options
1389
+ });
1390
+ }
1391
+ /** Cancel a sale (always `user` scope). */
1392
+ cancel(saleId, params, options) {
1393
+ return this.http.request({
1394
+ method: "POST",
1395
+ segments: ["user", "sales", "cancel", saleId],
1396
+ dataSchema: zod.z.unknown(),
1397
+ query: params,
1398
+ options
1399
+ });
1400
+ }
1401
+ /* ------------------------------ Sale reads ------------------------------ */
1402
+ /** Get the sale linked to a lead. Honors the configured scope. */
1403
+ getOfLead(leadId, options) {
1404
+ return this.http.request({
1405
+ method: "GET",
1406
+ segments: [this.scope(options), "leads", leadId, "sale"],
1407
+ dataSchema: SaleOfLeadSchema,
1408
+ options
1409
+ });
1410
+ }
1411
+ /** Get a sale's products + totals breakdown. Honors the configured scope. */
1412
+ getProducts(saleId, options) {
1413
+ return this.http.request({
1414
+ method: "GET",
1415
+ segments: [this.scope(options), "sales", saleId, "products"],
1416
+ dataSchema: SaleProductsSchema,
1417
+ options
1418
+ });
1419
+ }
1420
+ /** Get the sale ids attached to a form instance. Honors the configured scope. */
1421
+ getOfFormInstance(formInstanceId, options) {
1422
+ return this.http.request({
1423
+ method: "GET",
1424
+ segments: [this.scope(options), "sales", "form_instance", formInstanceId],
1425
+ dataSchema: zod.z.array(idSchema),
1426
+ options
1427
+ });
1428
+ }
1429
+ /** List a sale's documents (each with a download `location`). */
1430
+ getDocuments(saleId, options) {
1431
+ return this.http.request({
1432
+ method: "GET",
1433
+ segments: ["account", "sales", saleId, "documents"],
1434
+ dataSchema: zod.z.array(SaleDocumentSchema),
1435
+ options
1436
+ });
1437
+ }
1438
+ /** Get a sale's change history (always `account` scope). */
1439
+ getHistory(saleId, options) {
1440
+ return this.http.request({
1441
+ method: "GET",
1442
+ segments: ["account", "sales", saleId, "history"],
1443
+ dataSchema: zod.z.array(SaleHistoryEntrySchema),
1444
+ options
1445
+ });
1446
+ }
1447
+ /** Create an opt-in for a sale (always `account` scope). */
1448
+ createOptin(saleId, input = {}, options) {
1449
+ const body = this.parseInput(CreateOptinInputSchema, input, "sales.createOptin");
1450
+ return this.http.request({
1451
+ method: "POST",
1452
+ segments: ["account", "sales", saleId, "optin"],
1453
+ dataSchema: zod.z.unknown(),
1454
+ body,
1455
+ options
1456
+ });
1457
+ }
1458
+ };
1459
+ var baseConceptFields = {
1460
+ /** The name of the dialer company in lower case (max 20 chars). */
1461
+ source: zod.z.string(),
1462
+ /** A unique identifier for the record on the dialer platform. */
1463
+ source_id: zod.z.union([zod.z.string(), zod.z.number()]),
1464
+ /** Gender of the customer: `"male"` or `"female"`. */
1465
+ gender: zod.z.string().optional(),
1466
+ firstname: zod.z.string().optional(),
1467
+ lastname: zod.z.string().optional(),
1468
+ /** Date of birth in `dd-mm-yyyy` format. */
1469
+ birthdate: zod.z.string().optional(),
1470
+ email: zod.z.string().optional(),
1471
+ /** `1` for business, `0` for consumer. */
1472
+ customer_type: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
1473
+ company_name: zod.z.string().optional(),
1474
+ contact_person: zod.z.string().optional(),
1475
+ coc: zod.z.string().optional(),
1476
+ postcode: zod.z.string().optional(),
1477
+ housenumber: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
1478
+ suffix: zod.z.string().optional(),
1479
+ streetname: zod.z.string().optional(),
1480
+ city: zod.z.string().optional(),
1481
+ /** Country code: `"NL"` or `"BE"`. */
1482
+ country: zod.z.string().optional(),
1483
+ phone: zod.z.string().optional(),
1484
+ mobile: zod.z.string().optional()
1485
+ };
1486
+ var OptinChannelInputSchema = zod.z.object({
1487
+ /** Channel type: `"email"` or `"phone"`. */
1488
+ type: zod.z.string(),
1489
+ /** Email address or phone number, matching `type`. */
1490
+ value: zod.z.string(),
1491
+ /** Topic(s) the customer has opted in for. */
1492
+ topic: zod.z.string().optional(),
1493
+ /** When the opt-in was verified (phone double opt-in). */
1494
+ verified_at: zod.z.string().optional(),
1495
+ /** IP address from which the opt-in was verified. */
1496
+ verified_ip: zod.z.string().optional(),
1497
+ /** Verification method: `"sms"`, `"call"` or `"whatsapp"`. */
1498
+ verified_method: zod.z.string().optional()
1499
+ }).passthrough();
1500
+ var CreateConceptTransactionSchema = zod.z.object({
1501
+ ...baseConceptFields,
1502
+ /** Integer version of the source row (1-255). */
1503
+ source_version: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
1504
+ /** Arbitrary metadata associated with the source row. */
1505
+ source_metadata: zod.z.unknown().optional()
1506
+ }).passthrough();
1507
+ var CreateConceptTransactionWithOptinSchema = zod.z.object({
1508
+ ...baseConceptFields,
1509
+ source_version: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
1510
+ source_metadata: zod.z.unknown().optional(),
1511
+ /** `1` to create an opt-in, `0` otherwise. */
1512
+ optin: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
1513
+ optin_source: zod.z.string().optional(),
1514
+ /** When the opt-in was obtained (`yyyy-mm-dd HH:mm:ss`). */
1515
+ optin_obtained_at: zod.z.string().optional(),
1516
+ optin_obtained_by: zod.z.string().optional(),
1517
+ optin_obtained_system: zod.z.string().optional(),
1518
+ optin_obtained_via_url: zod.z.string().optional(),
1519
+ optin_client_ip: zod.z.string().optional(),
1520
+ /** Until when the opt-in is valid (`yyyy-mm-dd HH:mm:ss`). */
1521
+ optin_valid_till: zod.z.string().optional(),
1522
+ /** When the opt-in was withdrawn (`yyyy-mm-dd HH:mm:ss`). */
1523
+ optin_withdrawn_at: zod.z.string().optional(),
1524
+ optin_remarks: zod.z.string().optional(),
1525
+ optin_campaign_code: zod.z.string().optional(),
1526
+ /** Proof of the opt-in as a base64 document plus its extension. */
1527
+ optin_proof: zod.z.object({
1528
+ content: zod.z.string().optional(),
1529
+ extension: zod.z.string().optional()
1530
+ }).passthrough().optional(),
1531
+ /** The channels (at least one) the customer has opted in for. */
1532
+ optin_channels: zod.z.array(OptinChannelInputSchema).optional()
1533
+ }).passthrough();
1534
+ var CreateConceptLeadSchema = zod.z.object({ ...baseConceptFields }).passthrough();
1535
+ var ConceptTransactionResultSchema = loose({
1536
+ uuid: zod.z.string(),
1537
+ order_url: nullish(zod.z.string()),
1538
+ offer_url: nullish(zod.z.string())
1539
+ });
1540
+ var ConceptLeadResultSchema = loose({
1541
+ uuid: zod.z.string(),
1542
+ agenda_url: nullish(zod.z.string()),
1543
+ lead_url: nullish(zod.z.string())
1544
+ });
1545
+ var ConceptFieldSchema = loose({
1546
+ name: zod.z.string(),
1547
+ type: nullish(zod.z.string()),
1548
+ required: nullish(zod.z.boolean()),
1549
+ description: nullish(zod.z.string()),
1550
+ validations: zod.z.array(zod.z.string()).optional()
1551
+ });
1552
+ var ConceptFieldsSchema = loose({
1553
+ fields: zod.z.array(ConceptFieldSchema),
1554
+ validators: zod.z.record(zod.z.string(), zod.z.string()).optional()
1555
+ });
1556
+ var LastSaleSchema = loose({
1557
+ sale_id: idSchema
1558
+ });
1559
+ var ConceptTransactionSalesSchema = loose({
1560
+ sale_ids: zod.z.array(idSchema)
1561
+ });
1562
+ var SaleViewUrlSchema = loose({
1563
+ admin: nullish(zod.z.string()),
1564
+ reseller: nullish(zod.z.string())
1565
+ });
1566
+ var DialerClient = class extends BaseResource {
1567
+ /** Create a concept transaction and get the prefilled order/offer URLs. */
1568
+ createConceptTransaction(input, options) {
1569
+ const body = this.parseInput(
1570
+ CreateConceptTransactionSchema,
1571
+ input,
1572
+ "dialer.createConceptTransaction"
1573
+ );
1574
+ return this.http.request({
1575
+ method: "POST",
1576
+ segments: ["account", "concepttransaction"],
1577
+ dataSchema: ConceptTransactionResultSchema,
1578
+ body,
1579
+ options
1580
+ });
1581
+ }
1582
+ /** Create a concept transaction together with opt-in information. */
1583
+ createConceptTransactionWithOptin(input, options) {
1584
+ const body = this.parseInput(
1585
+ CreateConceptTransactionWithOptinSchema,
1586
+ input,
1587
+ "dialer.createConceptTransactionWithOptin"
1588
+ );
1589
+ return this.http.request({
1590
+ method: "POST",
1591
+ segments: ["account", "concepttransaction"],
1592
+ dataSchema: ConceptTransactionResultSchema,
1593
+ body,
1594
+ options
1595
+ });
1596
+ }
1597
+ /** List the fields supported when creating a concept transaction. */
1598
+ getConceptTransactionFields(options) {
1599
+ return this.http.request({
1600
+ method: "GET",
1601
+ segments: ["account", "concepttransaction", "fields"],
1602
+ dataSchema: ConceptFieldsSchema,
1603
+ options
1604
+ });
1605
+ }
1606
+ /** List the concept-transaction fields including the opt-in fields. */
1607
+ getConceptTransactionFieldsWithOptin(options) {
1608
+ return this.http.request({
1609
+ method: "GET",
1610
+ segments: ["account", "concepttransaction", "fields", "optin"],
1611
+ dataSchema: ConceptFieldsSchema,
1612
+ options
1613
+ });
1614
+ }
1615
+ /** Create a concept lead and get the prefilled agenda/lead URLs. */
1616
+ createConceptLead(input, options) {
1617
+ const body = this.parseInput(CreateConceptLeadSchema, input, "dialer.createConceptLead");
1618
+ return this.http.request({
1619
+ method: "POST",
1620
+ segments: ["account", "conceptlead"],
1621
+ dataSchema: ConceptLeadResultSchema,
1622
+ body,
1623
+ options
1624
+ });
1625
+ }
1626
+ /** List the fields supported when creating a concept lead. */
1627
+ getConceptLeadFields(options) {
1628
+ return this.http.request({
1629
+ method: "GET",
1630
+ segments: ["account", "conceptlead", "fields"],
1631
+ dataSchema: ConceptFieldsSchema,
1632
+ options
1633
+ });
1634
+ }
1635
+ /**
1636
+ * Get the last sale id created from a concept transaction. At least one of
1637
+ * `source_id` or `uuid` must be provided.
1638
+ */
1639
+ getLastSale(source, params = {}, options) {
1640
+ return this.http.request({
1641
+ method: "GET",
1642
+ segments: ["account", "concepttransaction", "sale_id", source],
1643
+ dataSchema: LastSaleSchema,
1644
+ query: {
1645
+ source_id: params.source_id,
1646
+ uuid: params.uuid
1647
+ },
1648
+ options
1649
+ });
1650
+ }
1651
+ /**
1652
+ * Get all sale ids created from a concept transaction. At least one of
1653
+ * `source_id` or `uuid` must be provided.
1654
+ */
1655
+ getSales(source, params = {}, options) {
1656
+ return this.http.request({
1657
+ method: "GET",
1658
+ segments: ["account", "concepttransaction", "sales", source],
1659
+ dataSchema: ConceptTransactionSalesSchema,
1660
+ query: {
1661
+ source_id: params.source_id,
1662
+ uuid: params.uuid
1663
+ },
1664
+ options
1665
+ });
1666
+ }
1667
+ /** Get the admin/reseller URLs for viewing a sale by id. */
1668
+ getSaleViewUrl(saleId, options) {
1669
+ return this.http.request({
1670
+ method: "GET",
1671
+ segments: ["account", "sales", "url", saleId],
1672
+ dataSchema: SaleViewUrlSchema,
1673
+ options
1674
+ });
1675
+ }
1676
+ };
1677
+ var extraFieldsMapSchema = zod.z.record(zod.z.string(), zod.z.unknown());
1678
+ var UserSchema = loose({
1679
+ id: idSchema,
1680
+ firstname: nullish(zod.z.string()),
1681
+ lastname: nullish(zod.z.string()),
1682
+ email: nullish(zod.z.string()),
1683
+ role: nullish(zod.z.string()),
1684
+ active: nullish(boolishSchema),
1685
+ /** Basic response: organisation name string. Extended response: an object. */
1686
+ organisation: nullish(
1687
+ zod.z.union([
1688
+ zod.z.string(),
1689
+ loose({
1690
+ id: nullish(idSchema),
1691
+ label: nullish(zod.z.string()),
1692
+ identifier: nullish(zod.z.string())
1693
+ })
1694
+ ])
1695
+ ),
1696
+ organisation_id: nullish(idSchema),
1697
+ organisation_identifier: nullish(zod.z.string()),
1698
+ team: nullish(
1699
+ loose({
1700
+ id: nullish(idSchema),
1701
+ label: nullish(zod.z.string()),
1702
+ identifier: nullish(zod.z.string())
1703
+ })
1704
+ ),
1705
+ extrafields: nullish(extraFieldsMapSchema),
1706
+ business: nullish(
1707
+ loose({
1708
+ name: nullish(zod.z.string()),
1709
+ email: nullish(zod.z.string()),
1710
+ phone_number: nullish(zod.z.string()),
1711
+ contact_person: nullish(zod.z.string()),
1712
+ postcode: nullish(zod.z.string()),
1713
+ housenumber: nullish(zod.z.union([zod.z.string(), zod.z.number()])),
1714
+ housenumber_suffix: nullish(zod.z.string()),
1715
+ suffix: nullish(zod.z.string()),
1716
+ streetname: nullish(zod.z.string()),
1717
+ city: nullish(zod.z.string()),
1718
+ coc: nullish(zod.z.string()),
1719
+ vat: nullish(zod.z.string()),
1720
+ address: addressSchema.optional()
1721
+ })
1722
+ )
1723
+ });
1724
+ var OrganisationListItemSchema = loose({
1725
+ id: idSchema,
1726
+ name: nullish(zod.z.string()),
1727
+ identifier: nullish(zod.z.string()),
1728
+ company_name: nullish(zod.z.string()),
1729
+ contact_person: nullish(zod.z.string()),
1730
+ email: nullish(zod.z.string()),
1731
+ phone: nullish(zod.z.string()),
1732
+ extrafields: nullish(extraFieldsMapSchema)
1733
+ });
1734
+ var OrganisationLogoSchema = loose({
1735
+ extension: nullish(zod.z.string()),
1736
+ content: nullish(zod.z.string())
1737
+ });
1738
+ var OrganisationSchema = loose({
1739
+ id: idSchema,
1740
+ name: nullish(zod.z.string()),
1741
+ text: nullish(zod.z.string()),
1742
+ identifier: nullish(zod.z.string()),
1743
+ description: nullish(zod.z.string()),
1744
+ partner: nullish(zod.z.string()),
1745
+ sales_channel: nullish(zod.z.string()),
1746
+ contractor: nullish(zod.z.string()),
1747
+ company_name: nullish(zod.z.string()),
1748
+ contact_person: nullish(zod.z.string()),
1749
+ postcode: nullish(zod.z.string()),
1750
+ housenumber: nullish(zod.z.union([zod.z.string(), zod.z.number()])),
1751
+ suffix: nullish(zod.z.string()),
1752
+ streetname: nullish(zod.z.string()),
1753
+ city: nullish(zod.z.string()),
1754
+ email: nullish(zod.z.string()),
1755
+ phone: nullish(zod.z.string()),
1756
+ coc: nullish(zod.z.string()),
1757
+ vat: nullish(zod.z.string()),
1758
+ website: nullish(zod.z.string()),
1759
+ created_at: nullish(zod.z.string()),
1760
+ updated_at: nullish(zod.z.string()),
1761
+ logo: nullish(OrganisationLogoSchema),
1762
+ extrafields: nullish(extraFieldsMapSchema)
1763
+ });
1764
+ var MutateOrganisationResultSchema = loose({ organisation_id: idSchema });
1765
+ var OrganisationProductsSchema = loose({ products: zod.z.array(idSchema) });
1766
+ var OrganisationLogoInputSchema = zod.z.object({
1767
+ /** Base64 string of the organisation logo. */
1768
+ content: zod.z.string(),
1769
+ /** Image extension: `png`, `gif`, `jpg` or `jpeg`. */
1770
+ extension: zod.z.string()
1771
+ }).passthrough();
1772
+ var OrganisationInputSchema = zod.z.object({
1773
+ /** The name of the organisation. */
1774
+ name: zod.z.string().optional(),
1775
+ /** Unique identifier slug for the organisation. */
1776
+ identifier: zod.z.string().optional(),
1777
+ description: zod.z.string().optional(),
1778
+ /** Sales channel: `d2d`, `retail`, `telemarketing`, `online` or `f2f`. */
1779
+ sales_channel: zod.z.string().optional(),
1780
+ /** `yes` if the organisation is a contractor, otherwise `no`. */
1781
+ contractor: zod.z.string().optional(),
1782
+ /** Required if `contractor` = `yes`. */
1783
+ company_name: zod.z.string().optional(),
1784
+ /** Required if `contractor` = `yes`. */
1785
+ email: zod.z.string().optional(),
1786
+ phone: zod.z.string().optional(),
1787
+ /** Required if `contractor` = `yes`. */
1788
+ contact_person: zod.z.string().optional(),
1789
+ /** Required if `contractor` = `yes`. */
1790
+ postcode: zod.z.string().optional(),
1791
+ /** Required if `contractor` = `yes`. */
1792
+ housenumber: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
1793
+ suffix: zod.z.string().optional(),
1794
+ /** Required if `contractor` = `yes`. */
1795
+ streetname: zod.z.string().optional(),
1796
+ /** Required if `contractor` = `yes`. */
1797
+ city: zod.z.string().optional(),
1798
+ /** Chamber of commerce number (required if `contractor` = `yes`). */
1799
+ coc: zod.z.string().optional(),
1800
+ /** BTW/VAT number (required if `contractor` = `yes`). */
1801
+ vat: zod.z.string().optional(),
1802
+ website: zod.z.string().optional(),
1803
+ /** The organisation logo. */
1804
+ logo: OrganisationLogoInputSchema.optional()
1805
+ }).passthrough();
1806
+ var InviteUserInputSchema = zod.z.object({
1807
+ /** Email of the user; becomes their Salesdock username. */
1808
+ email: zod.z.string(),
1809
+ /** Role: `agent`, `teamleader`, `organisationadmin` or `admin`. */
1810
+ role: zod.z.string(),
1811
+ /** The organisation the user belongs to. */
1812
+ organisation_id: idSchema,
1813
+ /** Team id — only required when the user is a `teamleader`. */
1814
+ team_id: idSchema.optional()
1815
+ }).passthrough();
1816
+ var OrganisationsClient = class extends BaseResource {
1817
+ /** List organisations (offset-paginated). */
1818
+ list(params = {}, options) {
1819
+ return fetchOffsetPage(
1820
+ this.http,
1821
+ OrganisationListItemSchema,
1822
+ ["account", "organisations"],
1823
+ params,
1824
+ options
1825
+ );
1826
+ }
1827
+ /** Retrieve a single organisation by id. */
1828
+ get(organisationId, options) {
1829
+ return this.http.request({
1830
+ method: "GET",
1831
+ segments: ["account", "organisations", organisationId],
1832
+ dataSchema: OrganisationSchema,
1833
+ options
1834
+ });
1835
+ }
1836
+ /** Create an organisation. */
1837
+ create(input, options) {
1838
+ const body = this.parseInput(OrganisationInputSchema, input, "users.organisations.create");
1839
+ return this.http.request({
1840
+ method: "POST",
1841
+ segments: ["account", "organisations"],
1842
+ dataSchema: MutateOrganisationResultSchema,
1843
+ body,
1844
+ options
1845
+ });
1846
+ }
1847
+ /** Update an organisation by id. */
1848
+ update(organisationId, input, options) {
1849
+ const body = this.parseInput(OrganisationInputSchema, input, "users.organisations.update");
1850
+ return this.http.request({
1851
+ method: "PUT",
1852
+ segments: ["account", "organisations", organisationId],
1853
+ dataSchema: MutateOrganisationResultSchema,
1854
+ body,
1855
+ options
1856
+ });
1857
+ }
1858
+ /** Delete an organisation by id (only allowed when it has no users). */
1859
+ delete(organisationId, options) {
1860
+ return this.http.request({
1861
+ method: "DELETE",
1862
+ segments: ["account", "organisations", organisationId],
1863
+ dataSchema: MutateOrganisationResultSchema,
1864
+ options
1865
+ });
1866
+ }
1867
+ /** List the product ids accessible to users of an organisation. */
1868
+ listProducts(organisationId, options) {
1869
+ return this.http.request({
1870
+ method: "GET",
1871
+ segments: ["account", "organisations", organisationId, "products"],
1872
+ dataSchema: OrganisationProductsSchema,
1873
+ options
1874
+ });
1875
+ }
1876
+ };
1877
+ var UsersClient = class extends BaseResource {
1878
+ constructor(http, config) {
1879
+ super(http, config);
1880
+ this.organisations = new OrganisationsClient(http, config);
1881
+ }
1882
+ /** List account users (offset-paginated). */
1883
+ list(params = {}, options) {
1884
+ return fetchOffsetPage(
1885
+ this.http,
1886
+ UserSchema,
1887
+ ["account", "users"],
1888
+ params,
1889
+ options
1890
+ );
1891
+ }
1892
+ /** Invite a user by email; sends them a Salesdock registration link. */
1893
+ invite(input, options) {
1894
+ const body = this.parseInput(InviteUserInputSchema, input, "users.invite");
1895
+ return this.http.request({
1896
+ method: "POST",
1897
+ segments: ["account", "invitation"],
1898
+ dataSchema: zod.z.unknown(),
1899
+ body,
1900
+ options
1901
+ });
1902
+ }
1903
+ };
1904
+ var CommissionSchema = loose({
1905
+ sale_id: nullish(idSchema),
1906
+ partner_type: nullish(zod.z.string()),
1907
+ product_id: nullish(idSchema),
1908
+ commission_plan: nullish(zod.z.string()),
1909
+ description: nullish(zod.z.string()),
1910
+ payout_percentage: nullish(zod.z.union([zod.z.string(), zod.z.number()])),
1911
+ currency: nullish(zod.z.string()),
1912
+ amount: nullish(zod.z.union([zod.z.string(), zod.z.number()])),
1913
+ recurring_type: nullish(zod.z.string()),
1914
+ recurring_count: nullish(zod.z.union([zod.z.string(), zod.z.number()])),
1915
+ run_count: nullish(zod.z.union([zod.z.string(), zod.z.number()]))
1916
+ });
1917
+ var CommissionTotalsBreakdownSchema = loose({
1918
+ total: nullish(zod.z.number()),
1919
+ pending: nullish(zod.z.number()),
1920
+ final: nullish(zod.z.number())
1921
+ });
1922
+ var CommissionTotalsSchema = loose({
1923
+ amounts: CommissionTotalsBreakdownSchema.optional(),
1924
+ counts: CommissionTotalsBreakdownSchema.optional()
1925
+ });
1926
+ var CommissionListSchema = loose({
1927
+ items: zod.z.array(CommissionSchema),
1928
+ totals: CommissionTotalsSchema.nullish()
1929
+ });
1930
+ var OutgoingCommissionsClient = class extends BaseResource {
1931
+ /** List all outgoing commissions (always `account` scope). */
1932
+ list(params = {}, options) {
1933
+ return this.http.request({
1934
+ method: "GET",
1935
+ segments: ["account", "commissions", "outgoing"],
1936
+ dataSchema: CommissionListSchema,
1937
+ query: params,
1938
+ options
1939
+ });
1940
+ }
1941
+ /** Get the outgoing commissions of a single sale (always `account` scope). */
1942
+ forSale(saleId, options) {
1943
+ return this.http.request({
1944
+ method: "GET",
1945
+ segments: ["account", "commissions", "outgoing", saleId],
1946
+ dataSchema: CommissionListSchema,
1947
+ options
1948
+ });
1949
+ }
1950
+ };
1951
+ var IncomingCommissionsClient = class extends BaseResource {
1952
+ /** List all incoming commissions (always `account` scope). */
1953
+ list(params = {}, options) {
1954
+ return this.http.request({
1955
+ method: "GET",
1956
+ segments: ["account", "commissions", "incoming"],
1957
+ dataSchema: CommissionListSchema,
1958
+ query: params,
1959
+ options
1960
+ });
1961
+ }
1962
+ /** Get the incoming commissions of a single sale (always `account` scope). */
1963
+ forSale(saleId, options) {
1964
+ return this.http.request({
1965
+ method: "GET",
1966
+ segments: ["account", "commissions", "incoming", saleId],
1967
+ dataSchema: CommissionListSchema,
1968
+ options
1969
+ });
1970
+ }
1971
+ };
1972
+ var CommissionsClient = class extends BaseResource {
1973
+ constructor(http, config) {
1974
+ super(http, config);
1975
+ this.outgoing = new OutgoingCommissionsClient(http, config);
1976
+ this.incoming = new IncomingCommissionsClient(http, config);
1977
+ }
1978
+ };
1979
+ var leadFieldEntrySchema = loose({
1980
+ label: nullish(zod.z.string()),
1981
+ type: nullish(zod.z.string()),
1982
+ value: zod.z.unknown().optional()
1983
+ });
1984
+ var leadFieldMapSchema = zod.z.union([zod.z.record(leadFieldEntrySchema), zod.z.array(zod.z.unknown())]);
1985
+ var LeadLabelSchema = loose({
1986
+ id: idSchema,
1987
+ label: nullish(zod.z.string()),
1988
+ identifier: nullish(zod.z.string())
1989
+ });
1990
+ var leadUserRefSchema = loose({
1991
+ id: nullish(idSchema),
1992
+ name: nullish(zod.z.string())
1993
+ });
1994
+ var LeadHistoryEntrySchema = loose({
1995
+ type: nullish(zod.z.string()),
1996
+ modified_at: nullish(zod.z.string()),
1997
+ previous_status: nullish(zod.z.string()),
1998
+ new_status: nullish(zod.z.string()),
1999
+ user: leadUserRefSchema.optional(),
2000
+ type_data: zod.z.unknown().optional()
2001
+ });
2002
+ var TownshipSchema = loose({
2003
+ id: idSchema,
2004
+ identifier: nullish(zod.z.string()),
2005
+ label: nullish(zod.z.string()),
2006
+ active: nullish(zod.z.union([zod.z.number(), zod.z.string(), zod.z.boolean()])),
2007
+ boundaries: zod.z.array(zod.z.string()).optional()
2008
+ });
2009
+ var TownshipsClient = class extends BaseResource {
2010
+ /** List townships (always `account` scope, admin only). */
2011
+ list(params = {}, options) {
2012
+ return this.http.request({
2013
+ method: "GET",
2014
+ segments: ["account", "leads", "townships"],
2015
+ dataSchema: zod.z.array(TownshipSchema),
2016
+ query: params,
2017
+ options
2018
+ });
2019
+ }
2020
+ };
2021
+ var LeadListItemSchema = loose({
2022
+ id: idSchema,
2023
+ business: nullish(zod.z.union([zod.z.boolean(), zod.z.string(), zod.z.number()])),
2024
+ gender: nullish(zod.z.string()),
2025
+ firstname: nullish(zod.z.string()),
2026
+ lastname: nullish(zod.z.string()),
2027
+ postcode: nullish(zod.z.string()),
2028
+ housenumber: nullish(zod.z.union([zod.z.string(), zod.z.number()])),
2029
+ suffix: nullish(zod.z.string()),
2030
+ streetname: nullish(zod.z.string()),
2031
+ city: nullish(zod.z.string()),
2032
+ email: nullish(zod.z.string()),
2033
+ company_name: nullish(zod.z.string()),
2034
+ activity: nullish(zod.z.string()),
2035
+ locked: nullish(zod.z.union([zod.z.boolean(), zod.z.string(), zod.z.number()])),
2036
+ status: nullish(zod.z.string()),
2037
+ created_by: nullish(idSchema),
2038
+ planned_user_id: nullish(idSchema),
2039
+ planned_date: nullish(zod.z.string()),
2040
+ planned_by: nullish(idSchema),
2041
+ planned_at: nullish(zod.z.string()),
2042
+ planned_from: nullish(zod.z.string()),
2043
+ planned_to: nullish(zod.z.string()),
2044
+ completed_at: nullish(zod.z.string()),
2045
+ created_at: nullish(zod.z.string()),
2046
+ updated_at: nullish(zod.z.string()),
2047
+ planned_to_username: nullish(zod.z.string()),
2048
+ completed_by_username: nullish(zod.z.string()),
2049
+ relative_distance: nullish(zod.z.number()),
2050
+ filter_status: nullish(zod.z.string()),
2051
+ name: nullish(zod.z.string()),
2052
+ address: nullish(zod.z.string()),
2053
+ organisation_id: nullish(idSchema),
2054
+ township_id: nullish(idSchema),
2055
+ latitude: nullish(zod.z.union([zod.z.number(), zod.z.string()])),
2056
+ longitude: nullish(zod.z.union([zod.z.number(), zod.z.string()])),
2057
+ extrafields: leadFieldMapSchema.optional(),
2058
+ questions: leadFieldMapSchema.optional(),
2059
+ labels: zod.z.array(LeadLabelSchema).optional(),
2060
+ history: zod.z.array(LeadHistoryEntrySchema).optional()
2061
+ });
2062
+ var LeadSchema = loose({
2063
+ id: idSchema,
2064
+ origin: nullish(zod.z.string()),
2065
+ business: nullish(zod.z.union([zod.z.boolean(), zod.z.string(), zod.z.number()])),
2066
+ gender: nullish(zod.z.string()),
2067
+ firstname: nullish(zod.z.string()),
2068
+ lastname: nullish(zod.z.string()),
2069
+ birthdate: nullish(zod.z.string()),
2070
+ email: nullish(zod.z.string()),
2071
+ phone: nullish(zod.z.string()),
2072
+ company_name: nullish(zod.z.string()),
2073
+ contact_person: nullish(zod.z.string()),
2074
+ coc: nullish(zod.z.string()),
2075
+ vat: nullish(zod.z.string()),
2076
+ postcode: nullish(zod.z.string()),
2077
+ housenumber: nullish(zod.z.union([zod.z.string(), zod.z.number()])),
2078
+ suffix: nullish(zod.z.string()),
2079
+ streetname: nullish(zod.z.string()),
2080
+ city: nullish(zod.z.string()),
2081
+ country: nullish(zod.z.string()),
2082
+ activity: nullish(zod.z.string()),
2083
+ organisation_id: nullish(idSchema),
2084
+ township_id: nullish(idSchema),
2085
+ latitude: nullish(zod.z.union([zod.z.number(), zod.z.string()])),
2086
+ longitude: nullish(zod.z.union([zod.z.number(), zod.z.string()])),
2087
+ imported_file_name: nullish(zod.z.string()),
2088
+ locked: nullish(zod.z.union([zod.z.boolean(), zod.z.string(), zod.z.number()])),
2089
+ status: nullish(zod.z.string()),
2090
+ created_by: nullish(idSchema),
2091
+ planned_user_id: nullish(idSchema),
2092
+ planned_date: nullish(zod.z.string()),
2093
+ planned_by: nullish(idSchema),
2094
+ planned_at: nullish(zod.z.string()),
2095
+ planned_from: nullish(zod.z.string()),
2096
+ planned_to: nullish(zod.z.string()),
2097
+ completed_at: nullish(zod.z.string()),
2098
+ completed_team_id: nullish(idSchema),
2099
+ completed_by: nullish(idSchema),
2100
+ created_at: nullish(zod.z.string()),
2101
+ updated_at: nullish(zod.z.string()),
2102
+ extrafields: leadFieldMapSchema.optional(),
2103
+ questions: leadFieldMapSchema.optional(),
2104
+ labels: zod.z.array(LeadLabelSchema).optional(),
2105
+ history: zod.z.array(LeadHistoryEntrySchema).optional()
2106
+ });
2107
+ var LeadActivitySchema = loose({
2108
+ id: idSchema,
2109
+ identifier: nullish(zod.z.string()),
2110
+ label: nullish(zod.z.string()),
2111
+ type: nullish(zod.z.string())
2112
+ });
2113
+ var LeadSourceSchema = loose({
2114
+ id: idSchema,
2115
+ identifier: nullish(zod.z.string()),
2116
+ label: nullish(zod.z.string())
2117
+ });
2118
+ var LeadFormSchema = loose({
2119
+ id: idSchema,
2120
+ identifier: nullish(zod.z.string()),
2121
+ label: nullish(zod.z.string()),
2122
+ description: nullish(zod.z.string()),
2123
+ active: nullish(zod.z.boolean()),
2124
+ created_at: nullish(zod.z.string()),
2125
+ updated_at: nullish(zod.z.string())
2126
+ });
2127
+ var LeadFormElementSchema = loose({
2128
+ id: idSchema,
2129
+ identifier: nullish(zod.z.string()),
2130
+ input_type: nullish(zod.z.string()),
2131
+ label: nullish(zod.z.string()),
2132
+ description: nullish(zod.z.string()),
2133
+ filled_by_client: nullish(zod.z.boolean()),
2134
+ filled_by_agent: nullish(zod.z.boolean()),
2135
+ lead_component: nullish(zod.z.boolean()),
2136
+ format: zod.z.unknown().optional()
2137
+ });
2138
+ var LeadResultSchema = loose({
2139
+ created_at: nullish(zod.z.string()),
2140
+ result_at: nullish(zod.z.string()),
2141
+ action: nullish(zod.z.string()),
2142
+ previous_status: nullish(zod.z.string()),
2143
+ new_status: nullish(zod.z.string()),
2144
+ contact_established: nullish(zod.z.boolean()),
2145
+ sales_opportunity: nullish(zod.z.boolean()),
2146
+ not_reached: nullish(zod.z.boolean()),
2147
+ appointment: nullish(zod.z.boolean()),
2148
+ latitude: nullish(zod.z.union([zod.z.number(), zod.z.string()])),
2149
+ longitude: nullish(zod.z.union([zod.z.number(), zod.z.string()])),
2150
+ distance: nullish(zod.z.union([zod.z.number(), zod.z.string()])),
2151
+ result_latitude: nullish(zod.z.union([zod.z.number(), zod.z.string()])),
2152
+ result_longitude: nullish(zod.z.union([zod.z.number(), zod.z.string()])),
2153
+ result_distance: nullish(zod.z.union([zod.z.number(), zod.z.string()])),
2154
+ user: leadUserRefSchema.optional(),
2155
+ organisation: loose({
2156
+ id: nullish(idSchema),
2157
+ name: nullish(zod.z.string()),
2158
+ identifier: nullish(zod.z.string())
2159
+ }).optional(),
2160
+ team: nullish(
2161
+ loose({
2162
+ id: nullish(idSchema),
2163
+ name: nullish(zod.z.string())
2164
+ })
2165
+ ),
2166
+ township: nullish(
2167
+ loose({
2168
+ id: nullish(idSchema),
2169
+ name: nullish(zod.z.string())
2170
+ })
2171
+ ),
2172
+ lead: loose({ id: idSchema }).optional()
2173
+ });
2174
+ var LeadStatusSchema = loose({
2175
+ source: nullish(zod.z.string()),
2176
+ id: nullish(idSchema),
2177
+ name: nullish(zod.z.string()),
2178
+ text: nullish(zod.z.string()),
2179
+ type: nullish(zod.z.string()),
2180
+ source_data: loose({
2181
+ contact_established: nullish(zod.z.boolean()),
2182
+ sales_opportunity: nullish(zod.z.boolean()),
2183
+ activities: nullish(zod.z.array(zod.z.string()))
2184
+ }).optional()
2185
+ });
2186
+ var LeadFormPdfSchema = loose({
2187
+ name: nullish(zod.z.string()),
2188
+ /** Base64-encoded PDF bytes. Decode it yourself; the SDK keeps it as a string. */
2189
+ content: zod.z.string()
2190
+ });
2191
+ var MutateLeadResultSchema = loose({ lead_id: idSchema });
2192
+ var CreateLeadFormInstanceResultSchema = loose({
2193
+ form_instance_id: idSchema,
2194
+ lead_id: idSchema
2195
+ });
2196
+ var CreateLeadAsAdminSchema = zod.z.object({
2197
+ /** Lead activity identifier, e.g. `calling`. */
2198
+ activity: zod.z.string().optional(),
2199
+ gender: zod.z.string().optional(),
2200
+ firstname: zod.z.string().optional(),
2201
+ lastname: zod.z.string().optional(),
2202
+ postcode: zod.z.string().optional(),
2203
+ housenumber: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
2204
+ suffix: zod.z.string().optional(),
2205
+ streetname: zod.z.string().optional(),
2206
+ city: zod.z.string().optional(),
2207
+ birthdate: zod.z.string().optional(),
2208
+ email: zod.z.string().optional(),
2209
+ phone: zod.z.string().optional(),
2210
+ business: zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean()]).optional(),
2211
+ company_name: zod.z.string().optional(),
2212
+ contact_person: zod.z.string().optional(),
2213
+ coc: zod.z.string().optional(),
2214
+ vat: zod.z.string().optional(),
2215
+ /** How to assign the lead, e.g. `user`. */
2216
+ assign: zod.z.string().optional(),
2217
+ /** The user id to assign the lead to. */
2218
+ user: idSchema.optional(),
2219
+ /** Whether to plan the lead for a date: `1`/`0`. */
2220
+ planned_for_date: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
2221
+ /** Planned date in `dd-mm-yyyy` format. */
2222
+ planned_date: zod.z.string().optional(),
2223
+ /** Planned start time in `hh:mm` format. */
2224
+ start_at: zod.z.string().optional(),
2225
+ /** Planned end time in `hh:mm` format. */
2226
+ end_at: zod.z.string().optional(),
2227
+ /** The lead source id. */
2228
+ lead_source_id: idSchema.optional(),
2229
+ /** Label ids to attach to the lead. */
2230
+ labels: zod.z.array(idSchema).optional()
2231
+ }).passthrough();
2232
+ var UpdateLeadAsAdminSchema = CreateLeadAsAdminSchema;
2233
+ var CreateLeadAsResellerSchema = zod.z.object({
2234
+ activity: zod.z.string().optional(),
2235
+ gender: zod.z.string().optional(),
2236
+ firstname: zod.z.string().optional(),
2237
+ lastname: zod.z.string().optional(),
2238
+ postcode: zod.z.string().optional(),
2239
+ housenumber: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
2240
+ suffix: zod.z.string().optional(),
2241
+ streetname: zod.z.string().optional(),
2242
+ city: zod.z.string().optional(),
2243
+ birthdate: zod.z.string().optional(),
2244
+ email: zod.z.string().optional(),
2245
+ phone: zod.z.string().optional(),
2246
+ business: zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean()]).optional(),
2247
+ company_name: zod.z.string().optional(),
2248
+ contact_person: zod.z.string().optional(),
2249
+ coc: zod.z.string().optional(),
2250
+ vat: zod.z.string().optional(),
2251
+ /** The user id to assign the lead to. */
2252
+ user: idSchema.optional(),
2253
+ /** Whether to plan the lead for a date: `1`/`0`. */
2254
+ planned_for_date: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
2255
+ /** Planned date in `dd-mm-yyyy` format. */
2256
+ planned_date: zod.z.string().optional(),
2257
+ /** Planned start time in `hh:mm` format. */
2258
+ start_at: zod.z.string().optional(),
2259
+ /** Planned end time in `hh:mm` format. */
2260
+ end_at: zod.z.string().optional(),
2261
+ /** The lead source id. */
2262
+ lead_source_id: idSchema.optional(),
2263
+ /** Label ids to attach to the lead. */
2264
+ labels: zod.z.array(idSchema).optional()
2265
+ }).passthrough();
2266
+ var UpdateLeadAsResellerSchema = CreateLeadAsResellerSchema;
2267
+ var UpdateLeadStatusSchema = zod.z.object({
2268
+ /** The new status identifier, e.g. `afspraak`. */
2269
+ status: zod.z.string(),
2270
+ /** Optional remark accompanying the status change. */
2271
+ remark: zod.z.string().optional()
2272
+ }).passthrough();
2273
+ var CreateLeadFormInstanceSchema = zod.z.object({
2274
+ /** Answers keyed by form element identifier. */
2275
+ questionData: zod.z.record(zod.z.unknown()).optional(),
2276
+ /** The client's name. */
2277
+ client_name: zod.z.string().optional(),
2278
+ /** The client's email address. */
2279
+ client_email: zod.z.string().optional(),
2280
+ /** The client's phone number. */
2281
+ client_phone: zod.z.string().optional()
2282
+ }).passthrough();
2283
+ var LeadsClient = class extends BaseResource {
2284
+ constructor(http, config) {
2285
+ super(http, config);
2286
+ this.townships = new TownshipsClient(http, config);
2287
+ }
2288
+ /** List leads (cursor-paginated). Honors the configured scope. */
2289
+ list(params = {}, options) {
2290
+ return fetchCursorPage(
2291
+ this.http,
2292
+ LeadListItemSchema,
2293
+ [this.scope(options), "leads"],
2294
+ params,
2295
+ options
2296
+ );
2297
+ }
2298
+ /** Retrieve a single lead by id. Honors the configured scope. */
2299
+ get(leadId, options) {
2300
+ return this.http.request({
2301
+ method: "GET",
2302
+ segments: [this.scope(options), "leads", leadId],
2303
+ dataSchema: LeadSchema,
2304
+ options
2305
+ });
2306
+ }
2307
+ /** List the available lead activities. Honors the configured scope. */
2308
+ listActivities(options) {
2309
+ return this.http.request({
2310
+ method: "GET",
2311
+ segments: [this.scope(options), "leads", "activities"],
2312
+ dataSchema: zod.z.array(LeadActivitySchema),
2313
+ options
2314
+ });
2315
+ }
2316
+ /** List the available lead sources. Honors the configured scope. */
2317
+ listSources(options) {
2318
+ return this.http.request({
2319
+ method: "GET",
2320
+ segments: [this.scope(options), "leads", "sources"],
2321
+ dataSchema: zod.z.array(LeadSourceSchema),
2322
+ options
2323
+ });
2324
+ }
2325
+ /** Create a lead as an admin (always `account` scope). */
2326
+ createAsAdmin(input, options) {
2327
+ const body = this.parseInput(CreateLeadAsAdminSchema, input, "leads.createAsAdmin");
2328
+ return this.http.request({
2329
+ method: "POST",
2330
+ segments: ["account", "leads"],
2331
+ dataSchema: MutateLeadResultSchema,
2332
+ body,
2333
+ options
2334
+ });
2335
+ }
2336
+ /** Update a lead by id as an admin (always `account` scope). */
2337
+ updateAsAdmin(leadId, input, options) {
2338
+ const body = this.parseInput(UpdateLeadAsAdminSchema, input, "leads.updateAsAdmin");
2339
+ return this.http.request({
2340
+ method: "PUT",
2341
+ segments: ["account", "leads", leadId],
2342
+ dataSchema: MutateLeadResultSchema,
2343
+ body,
2344
+ options
2345
+ });
2346
+ }
2347
+ /** Create a lead as a reseller (always `user` scope). */
2348
+ createAsReseller(input, options) {
2349
+ const body = this.parseInput(CreateLeadAsResellerSchema, input, "leads.createAsReseller");
2350
+ return this.http.request({
2351
+ method: "POST",
2352
+ segments: ["user", "leads"],
2353
+ dataSchema: MutateLeadResultSchema,
2354
+ body,
2355
+ options
2356
+ });
2357
+ }
2358
+ /** Update a lead by id as a reseller (always `user` scope). */
2359
+ updateAsReseller(leadId, input, options) {
2360
+ const body = this.parseInput(UpdateLeadAsResellerSchema, input, "leads.updateAsReseller");
2361
+ return this.http.request({
2362
+ method: "PUT",
2363
+ segments: ["user", "leads", leadId],
2364
+ dataSchema: MutateLeadResultSchema,
2365
+ body,
2366
+ options
2367
+ });
2368
+ }
2369
+ /** Retrieve a lead's form rendered as a base64-encoded PDF. Honors the configured scope. */
2370
+ getFormPdf(leadId, options) {
2371
+ return this.http.request({
2372
+ method: "GET",
2373
+ segments: [this.scope(options), "leads", leadId, "form", "pdf"],
2374
+ dataSchema: LeadFormPdfSchema,
2375
+ options
2376
+ });
2377
+ }
2378
+ /** Retrieve the change history of a lead. Honors the configured scope. */
2379
+ getHistory(leadId, options) {
2380
+ return this.http.request({
2381
+ method: "GET",
2382
+ segments: [this.scope(options), "leads", leadId, "history"],
2383
+ dataSchema: zod.z.array(LeadHistoryEntrySchema),
2384
+ options
2385
+ });
2386
+ }
2387
+ /** Retrieve the results (logged actions) for a single lead. Honors the configured scope. */
2388
+ getResults(leadId, options) {
2389
+ return this.http.request({
2390
+ method: "GET",
2391
+ segments: [this.scope(options), "leads", leadId, "results"],
2392
+ dataSchema: zod.z.array(LeadResultSchema),
2393
+ options
2394
+ });
2395
+ }
2396
+ /** List lead results across leads (cursor-paginated). Honors the configured scope. */
2397
+ listResults(params = {}, options) {
2398
+ return fetchCursorPage(
2399
+ this.http,
2400
+ LeadResultSchema,
2401
+ [this.scope(options), "leads", "results"],
2402
+ params,
2403
+ options
2404
+ );
2405
+ }
2406
+ /** Update a lead's status (always `account` scope). */
2407
+ updateStatus(leadId, input, options) {
2408
+ const body = this.parseInput(UpdateLeadStatusSchema, input, "leads.updateStatus");
2409
+ return this.http.request({
2410
+ method: "POST",
2411
+ segments: ["account", "leads", "status", leadId],
2412
+ dataSchema: zod.z.unknown(),
2413
+ body,
2414
+ options
2415
+ });
2416
+ }
2417
+ /** List lead forms (templates). Honors the configured scope. */
2418
+ listForms(options) {
2419
+ return this.http.request({
2420
+ method: "GET",
2421
+ segments: [this.scope(options), "leads", "forms"],
2422
+ dataSchema: zod.z.array(LeadFormSchema),
2423
+ options
2424
+ });
2425
+ }
2426
+ /** List the elements/fields of a lead form. Honors the configured scope. */
2427
+ getFormElements(leadFormId, options) {
2428
+ return this.http.request({
2429
+ method: "GET",
2430
+ segments: [this.scope(options), "leads", "forms", leadFormId, "elements"],
2431
+ dataSchema: zod.z.array(LeadFormElementSchema),
2432
+ options
2433
+ });
2434
+ }
2435
+ /** Create a lead form instance (no scope segment). */
2436
+ createFormInstance(leadFormId, input, options) {
2437
+ const body = this.parseInput(CreateLeadFormInstanceSchema, input, "leads.createFormInstance");
2438
+ return this.http.request({
2439
+ method: "POST",
2440
+ segments: ["leads", "forms", leadFormId, "instances"],
2441
+ dataSchema: CreateLeadFormInstanceResultSchema,
2442
+ body,
2443
+ options
2444
+ });
2445
+ }
2446
+ /** List lead statuses. Honors the configured scope. */
2447
+ listStatuses(params = {}, options) {
2448
+ return this.http.request({
2449
+ method: "GET",
2450
+ segments: [this.scope(options), "statuses"],
2451
+ dataSchema: zod.z.array(LeadStatusSchema),
2452
+ query: params,
2453
+ options
2454
+ });
2455
+ }
2456
+ };
2457
+ var FormSchema = loose({
2458
+ id: idSchema,
2459
+ name: nullish(zod.z.string())
2460
+ });
2461
+ var FormElementSchema = loose({
2462
+ id: idSchema,
2463
+ name: nullish(zod.z.string()),
2464
+ identifier: nullish(zod.z.string()),
2465
+ input_type: nullish(zod.z.string()),
2466
+ description: nullish(zod.z.string())
2467
+ });
2468
+ var FormInstanceListItemSchema = loose({
2469
+ id: idSchema,
2470
+ title: nullish(zod.z.string()),
2471
+ status: nullish(zod.z.string()),
2472
+ status_remark: nullish(zod.z.string()),
2473
+ organisation_name: nullish(zod.z.string()),
2474
+ agent: nullish(zod.z.string()),
2475
+ client_info: zod.z.union([
2476
+ loose({
2477
+ client_name_for_receiving_confirmation_email: nullish(zod.z.string()),
2478
+ client_email_for_receiving_confirmation_email: nullish(zod.z.string())
2479
+ }),
2480
+ zod.z.array(zod.z.unknown())
2481
+ ]).optional(),
2482
+ created_at: nullish(zod.z.string()),
2483
+ updated_at: nullish(zod.z.string())
2484
+ });
2485
+ var FormInstanceRelationSchema = loose({
2486
+ id: idSchema,
2487
+ postcode: nullish(zod.z.string()),
2488
+ housenumber: nullish(zod.z.union([zod.z.string(), zod.z.number()])),
2489
+ suffix: nullish(zod.z.string()),
2490
+ streetname: nullish(zod.z.string()),
2491
+ city: nullish(zod.z.string()),
2492
+ email: nullish(zod.z.string()),
2493
+ phone: nullish(zod.z.string()),
2494
+ company_name: nullish(zod.z.string()),
2495
+ contact_person: nullish(zod.z.string()),
2496
+ coc: nullish(zod.z.string()),
2497
+ vat: nullish(zod.z.string())
2498
+ });
2499
+ var FormInstanceSchema = loose({
2500
+ id: idSchema,
2501
+ title: nullish(zod.z.string()),
2502
+ status: nullish(zod.z.string()),
2503
+ status_remark: nullish(zod.z.string()),
2504
+ agent: nullish(zod.z.string()),
2505
+ organisation: nullish(zod.z.string()),
2506
+ created_at: nullish(zod.z.string()),
2507
+ updated_at: nullish(zod.z.string()),
2508
+ relation: FormInstanceRelationSchema.optional(),
2509
+ client_name: nullish(zod.z.string()),
2510
+ client_email: nullish(zod.z.string()),
2511
+ question_data: zod.z.record(zod.z.string(), zod.z.unknown()).optional()
2512
+ });
2513
+ var FillFormInstanceResultSchema = loose({
2514
+ form_instance_id: idSchema
2515
+ });
2516
+ var FormInstancePdfSchema = loose({
2517
+ id: idSchema,
2518
+ pdf: loose({
2519
+ /** The base64-encoded PDF document (not decoded by the SDK). */
2520
+ content: nullish(zod.z.string())
2521
+ }).optional()
2522
+ });
2523
+ var FormStatusSchema = loose({
2524
+ source: nullish(zod.z.string()),
2525
+ id: nullish(idSchema),
2526
+ name: nullish(zod.z.string()),
2527
+ text: nullish(zod.z.string()),
2528
+ type: nullish(zod.z.string()),
2529
+ source_data: nullish(zod.z.unknown())
2530
+ });
2531
+ var FillFormFileSchema = zod.z.object({
2532
+ /** The file name, e.g. `"Some file.png"`. */
2533
+ name: zod.z.string(),
2534
+ /** The file contents as a data URL (e.g. `"data:image/png;base64,..."`). */
2535
+ content: zod.z.string()
2536
+ }).passthrough();
2537
+ var FillFormInstanceSchema = zod.z.object({
2538
+ /**
2539
+ * Answers keyed by element identifier. Values are strings/numbers for most
2540
+ * inputs, or an array of `{ name, content }` for `file` elements.
2541
+ */
2542
+ questionData: zod.z.record(
2543
+ zod.z.string(),
2544
+ zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean(), zod.z.array(FillFormFileSchema), zod.z.unknown()])
2545
+ ),
2546
+ /** Name of the client receiving the confirmation email. */
2547
+ client_name: zod.z.string().optional(),
2548
+ /** Email of the client receiving the confirmation email. */
2549
+ client_email: zod.z.string().optional(),
2550
+ /** Phone number of the client. */
2551
+ client_phone: zod.z.string().optional()
2552
+ }).passthrough();
2553
+ var FormsClient = class extends BaseResource {
2554
+ /** List the forms available to the user (offset-paginated). Honors the configured scope. */
2555
+ list(options) {
2556
+ return fetchOffsetPage(
2557
+ this.http,
2558
+ FormSchema,
2559
+ [this.scope(options), "forms"],
2560
+ void 0,
2561
+ options
2562
+ );
2563
+ }
2564
+ /** Retrieve all elements available for a form. Honors the configured scope. */
2565
+ getElements(formId, options) {
2566
+ return this.http.request({
2567
+ method: "GET",
2568
+ segments: [this.scope(options), "forms", formId, "elements"],
2569
+ dataSchema: zod.z.array(FormElementSchema),
2570
+ options
2571
+ });
2572
+ }
2573
+ /** List form instances (offset-paginated). Honors the configured scope. */
2574
+ listInstances(params = {}, options) {
2575
+ return fetchOffsetPage(
2576
+ this.http,
2577
+ FormInstanceListItemSchema,
2578
+ [this.scope(options), "forms", "instances"],
2579
+ params,
2580
+ options
2581
+ );
2582
+ }
2583
+ /** Retrieve a single form instance by id. Honors the configured scope. */
2584
+ getInstance(formInstanceId, options) {
2585
+ return this.http.request({
2586
+ method: "GET",
2587
+ segments: [this.scope(options), "forms", "instances", formInstanceId],
2588
+ dataSchema: FormInstanceSchema,
2589
+ options
2590
+ });
2591
+ }
2592
+ /** Fill (create) a form instance for a form. This endpoint has no scope segment. */
2593
+ fillInstance(formId, input, options) {
2594
+ const body = this.parseInput(FillFormInstanceSchema, input, "forms.fillInstance");
2595
+ return this.http.request({
2596
+ method: "POST",
2597
+ segments: ["forms", formId, "instances"],
2598
+ dataSchema: FillFormInstanceResultSchema,
2599
+ body,
2600
+ options
2601
+ });
2602
+ }
2603
+ /** List the ids of form instances connected to a sale. Honors the configured scope. */
2604
+ listInstancesBySale(saleId, options) {
2605
+ return this.http.request({
2606
+ method: "GET",
2607
+ segments: [this.scope(options), "forms", "instances", "sale", saleId],
2608
+ dataSchema: zod.z.array(idSchema),
2609
+ options
2610
+ });
2611
+ }
2612
+ /** Retrieve a form instance's PDF (base64 content). Honors the configured scope. */
2613
+ getInstancePdf(formInstanceId, options) {
2614
+ return this.http.request({
2615
+ method: "GET",
2616
+ segments: [this.scope(options), "forms", "instances", "pdf", formInstanceId],
2617
+ dataSchema: FormInstancePdfSchema,
2618
+ options
2619
+ });
2620
+ }
2621
+ /** List the available form statuses. Honors the configured scope. */
2622
+ listStatuses(params = {}, options) {
2623
+ return this.http.request({
2624
+ method: "GET",
2625
+ segments: [this.scope(options), "statuses"],
2626
+ dataSchema: zod.z.array(FormStatusSchema),
2627
+ query: params,
2628
+ options
2629
+ });
2630
+ }
2631
+ };
2632
+ var RelationListItemSchema = loose({
2633
+ id: idSchema,
2634
+ business: nullish(zod.z.union([zod.z.boolean(), zod.z.string(), zod.z.number()])),
2635
+ shared_with: nullish(zod.z.string()),
2636
+ organisation_id: nullish(idSchema),
2637
+ gender: nullish(zod.z.string()),
2638
+ firstname: nullish(zod.z.string()),
2639
+ lastname: nullish(zod.z.string()),
2640
+ birthdate: nullish(zod.z.string()),
2641
+ postcode: nullish(zod.z.string()),
2642
+ housenumber: nullish(zod.z.union([zod.z.string(), zod.z.number()])),
2643
+ suffix: nullish(zod.z.string()),
2644
+ streetname: nullish(zod.z.string()),
2645
+ city: nullish(zod.z.string()),
2646
+ email: nullish(zod.z.string()),
2647
+ phone: nullish(zod.z.string()),
2648
+ company_name: nullish(zod.z.string()),
2649
+ contact_person: nullish(zod.z.string()),
2650
+ coc: nullish(zod.z.string()),
2651
+ vat: nullish(zod.z.string()),
2652
+ created_at: nullish(zod.z.string()),
2653
+ updated_at: nullish(zod.z.string())
2654
+ });
2655
+ var RelationSchema = loose({
2656
+ id: idSchema,
2657
+ created_at: nullish(zod.z.string()),
2658
+ updated_at: nullish(zod.z.string()),
2659
+ customer: loose({
2660
+ gender: nullish(zod.z.string()),
2661
+ firstname: nullish(zod.z.string()),
2662
+ lastname: nullish(zod.z.string()),
2663
+ birthdate: nullish(zod.z.string()),
2664
+ email: nullish(zod.z.string()),
2665
+ phone: nullish(zod.z.string()),
2666
+ business: nullish(zod.z.union([zod.z.boolean(), zod.z.string(), zod.z.number()])),
2667
+ company_name: nullish(zod.z.string()),
2668
+ contact_person: nullish(zod.z.string()),
2669
+ coc: nullish(zod.z.string()),
2670
+ vat: nullish(zod.z.string()),
2671
+ address: addressSchema.optional()
2672
+ }).optional(),
2673
+ shared_with: nullish(zod.z.string()),
2674
+ organisation_id: nullish(idSchema),
2675
+ extrafields: zod.z.array(extraFieldSchema).optional()
2676
+ });
2677
+ var MutateRelationResultSchema = loose({ relation_id: idSchema });
2678
+ var RelationInputSchema = zod.z.object({
2679
+ visibility: zod.z.string().optional(),
2680
+ organisation_id: idSchema.optional(),
2681
+ user_id: idSchema.optional(),
2682
+ gender: zod.z.string().optional(),
2683
+ firstname: zod.z.string().optional(),
2684
+ lastname: zod.z.string().optional(),
2685
+ postcode: zod.z.string().optional(),
2686
+ housenumber: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
2687
+ suffix: zod.z.string().optional(),
2688
+ streetname: zod.z.string().optional(),
2689
+ city: zod.z.string().optional(),
2690
+ birthdate: zod.z.string().optional(),
2691
+ email: zod.z.string().optional(),
2692
+ phone: zod.z.string().optional(),
2693
+ business: zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean()]).optional(),
2694
+ company_name: zod.z.string().optional(),
2695
+ contact_person: zod.z.string().optional(),
2696
+ company_coc: zod.z.string().optional(),
2697
+ company_vat: zod.z.string().optional()
2698
+ }).passthrough();
2699
+ var RelationsClient = class extends BaseResource {
2700
+ /** List relations (offset-paginated). Honors the configured scope. */
2701
+ list(params = {}, options) {
2702
+ return fetchOffsetPage(
2703
+ this.http,
2704
+ RelationListItemSchema,
2705
+ [this.scope(options), "relations"],
2706
+ params,
2707
+ options
2708
+ );
2709
+ }
2710
+ /** Retrieve a single relation by id (always `account` scope). */
2711
+ get(relationId, options) {
2712
+ return this.http.request({
2713
+ method: "GET",
2714
+ segments: ["account", "relations", relationId],
2715
+ dataSchema: RelationSchema,
2716
+ options
2717
+ });
2718
+ }
2719
+ /** Create a relation. Honors the configured scope. */
2720
+ create(input, options) {
2721
+ const body = this.parseInput(RelationInputSchema, input, "relations.create");
2722
+ return this.http.request({
2723
+ method: "POST",
2724
+ segments: [this.scope(options), "relations"],
2725
+ dataSchema: MutateRelationResultSchema,
2726
+ body,
2727
+ options
2728
+ });
2729
+ }
2730
+ /** Update a relation by id (always `account` scope). */
2731
+ update(relationId, input, options) {
2732
+ const body = this.parseInput(RelationInputSchema, input, "relations.update");
2733
+ return this.http.request({
2734
+ method: "PUT",
2735
+ segments: ["account", "relations", relationId],
2736
+ dataSchema: MutateRelationResultSchema,
2737
+ body,
2738
+ options
2739
+ });
2740
+ }
2741
+ };
2742
+ var SupplierListItemSchema = loose({
2743
+ id: idSchema,
2744
+ name: nullish(zod.z.string()),
2745
+ text: nullish(zod.z.string()),
2746
+ identifier: nullish(zod.z.string()),
2747
+ description: nullish(zod.z.string()),
2748
+ active: nullish(boolishSchema)
2749
+ });
2750
+ var MediaBlobSchema = loose({
2751
+ extension: nullish(zod.z.string()),
2752
+ content: nullish(zod.z.string())
2753
+ });
2754
+ var SupplierSchema = loose({
2755
+ id: idSchema,
2756
+ name: nullish(zod.z.string()),
2757
+ text: nullish(zod.z.string()),
2758
+ identifier: nullish(zod.z.string()),
2759
+ description: nullish(zod.z.string()),
2760
+ confirmation_pdf_layout: nullish(zod.z.string()),
2761
+ contractor: nullish(zod.z.string()),
2762
+ company_name: nullish(zod.z.string()),
2763
+ contact_person: nullish(zod.z.string()),
2764
+ postcode: nullish(zod.z.string()),
2765
+ housenumber: nullish(zod.z.union([zod.z.string(), zod.z.number()])),
2766
+ suffix: nullish(zod.z.string()),
2767
+ streetname: nullish(zod.z.string()),
2768
+ city: nullish(zod.z.string()),
2769
+ email: nullish(zod.z.string()),
2770
+ phone: nullish(zod.z.string()),
2771
+ coc: nullish(zod.z.string()),
2772
+ vat: nullish(zod.z.string()),
2773
+ website: nullish(zod.z.string()),
2774
+ logo: nullish(MediaBlobSchema),
2775
+ created_at: nullish(zod.z.string()),
2776
+ updated_at: nullish(zod.z.string()),
2777
+ email_template: nullish(zod.z.string()),
2778
+ extrafields: zod.z.array(extraFieldSchema).optional()
2779
+ });
2780
+ var MutateSupplierResultSchema = loose({ supplier_id: idSchema });
2781
+ var SupplierInputSchema = zod.z.object({
2782
+ /** Name of the supplier. */
2783
+ name: zod.z.string().optional(),
2784
+ /** Unique identifier (slug) for the supplier. */
2785
+ identifier: zod.z.string().optional(),
2786
+ /** `0` = inactive, `1` = active. */
2787
+ active: zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean()]).optional(),
2788
+ description: zod.z.string().optional(),
2789
+ /** `"yes"` = is a contractor, `"no"` = not a contractor. */
2790
+ contractor: zod.z.string().optional(),
2791
+ company_name: zod.z.string().optional(),
2792
+ contact_person: zod.z.string().optional(),
2793
+ postcode: zod.z.string().optional(),
2794
+ housenumber: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
2795
+ suffix: zod.z.string().optional(),
2796
+ streetname: zod.z.string().optional(),
2797
+ city: zod.z.string().optional(),
2798
+ coc: zod.z.string().optional(),
2799
+ vat: zod.z.string().optional(),
2800
+ email: zod.z.string().optional(),
2801
+ phone: zod.z.string().optional(),
2802
+ website: zod.z.string().optional(),
2803
+ /** Logo as `{ content: base64, extension: "png"|"gif"|"jpg"|"jpeg" }`. */
2804
+ logo: zod.z.object({ content: zod.z.string().optional(), extension: zod.z.string().optional() }).passthrough().optional()
2805
+ }).passthrough();
2806
+ var SuppliersClient = class extends BaseResource {
2807
+ /** List suppliers with their basic details. Honors the configured scope. */
2808
+ list(options) {
2809
+ return this.http.request({
2810
+ method: "GET",
2811
+ segments: [this.scope(options), "suppliers"],
2812
+ dataSchema: zod.z.array(SupplierListItemSchema),
2813
+ options
2814
+ });
2815
+ }
2816
+ /** Retrieve a single supplier by id. Honors the configured scope. */
2817
+ get(supplierId, options) {
2818
+ return this.http.request({
2819
+ method: "GET",
2820
+ segments: [this.scope(options), "suppliers", supplierId],
2821
+ dataSchema: SupplierSchema,
2822
+ options
2823
+ });
2824
+ }
2825
+ /** Create a supplier (always `account` scope, admin only). */
2826
+ create(input, options) {
2827
+ const body = this.parseInput(SupplierInputSchema, input, "products.suppliers.create");
2828
+ return this.http.request({
2829
+ method: "POST",
2830
+ segments: ["account", "suppliers"],
2831
+ dataSchema: MutateSupplierResultSchema,
2832
+ body,
2833
+ options
2834
+ });
2835
+ }
2836
+ /** Update a supplier by id (always `account` scope, admin only). */
2837
+ update(supplierId, input, options) {
2838
+ const body = this.parseInput(SupplierInputSchema, input, "products.suppliers.update");
2839
+ return this.http.request({
2840
+ method: "PUT",
2841
+ segments: ["account", "suppliers", supplierId],
2842
+ dataSchema: MutateSupplierResultSchema,
2843
+ body,
2844
+ options
2845
+ });
2846
+ }
2847
+ /** Delete a supplier by id (always `account` scope, admin only). */
2848
+ delete(supplierId, options) {
2849
+ return this.http.request({
2850
+ method: "DELETE",
2851
+ segments: ["account", "suppliers", supplierId],
2852
+ dataSchema: MutateSupplierResultSchema,
2853
+ options
2854
+ });
2855
+ }
2856
+ };
2857
+ var ProductListItemSchema = loose({
2858
+ id: idSchema,
2859
+ name: nullish(zod.z.string()),
2860
+ identifier: nullish(zod.z.string()),
2861
+ supplier_id: nullish(idSchema),
2862
+ supplier_name: nullish(zod.z.string()),
2863
+ supplier_identifier: nullish(zod.z.string()),
2864
+ type: nullish(zod.z.string()),
2865
+ usp: nullish(zod.z.string()),
2866
+ description: nullish(zod.z.string()),
2867
+ cart_info: nullish(zod.z.string()),
2868
+ business: nullish(zod.z.union([zod.z.string(), zod.z.number()])),
2869
+ active: nullish(boolishSchema),
2870
+ valid_from: nullish(zod.z.string()),
2871
+ valid_till: nullish(zod.z.string()),
2872
+ created_at: nullish(zod.z.string()),
2873
+ updated_at: nullish(zod.z.string())
2874
+ });
2875
+ var ProductDocumentSchema = loose({
2876
+ name: nullish(zod.z.string()),
2877
+ location: nullish(zod.z.string())
2878
+ });
2879
+ var ProductSchema = loose({
2880
+ id: idSchema,
2881
+ name: nullish(zod.z.string()),
2882
+ identifier: nullish(zod.z.string()),
2883
+ main: nullish(zod.z.union([zod.z.number(), zod.z.string(), zod.z.boolean()])),
2884
+ type: nullish(zod.z.string()),
2885
+ image: nullish(MediaBlobSchema),
2886
+ usp: nullish(zod.z.string()),
2887
+ description: nullish(zod.z.string()),
2888
+ duration: nullish(zod.z.union([zod.z.string(), zod.z.number()])),
2889
+ business: nullish(zod.z.union([zod.z.string(), zod.z.number()])),
2890
+ retention: nullish(zod.z.union([zod.z.string(), zod.z.number()])),
2891
+ confirmation_pdf_layout: nullish(zod.z.string()),
2892
+ active: nullish(boolishSchema),
2893
+ price: nullish(zod.z.union([zod.z.string(), zod.z.number()])),
2894
+ price_action: nullish(zod.z.union([zod.z.string(), zod.z.number()])),
2895
+ price_action_type: nullish(zod.z.string()),
2896
+ price_action_value: nullish(zod.z.union([zod.z.string(), zod.z.number()])),
2897
+ price_monthly: nullish(zod.z.union([zod.z.string(), zod.z.number()])),
2898
+ price_monthly_action: nullish(zod.z.union([zod.z.string(), zod.z.number()])),
2899
+ price_monthly_action_type: nullish(zod.z.string()),
2900
+ price_monthly_action_value: nullish(zod.z.union([zod.z.string(), zod.z.number()])),
2901
+ valid_from: nullish(zod.z.string()),
2902
+ valid_till: nullish(zod.z.string()),
2903
+ created_at: nullish(zod.z.string()),
2904
+ updated_at: nullish(zod.z.string()),
2905
+ supplier_id: nullish(idSchema),
2906
+ supplier_name: nullish(zod.z.string()),
2907
+ supplier_identifier: nullish(zod.z.string()),
2908
+ customfields: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
2909
+ documents: zod.z.array(ProductDocumentSchema).optional()
2910
+ });
2911
+ var MutateProductResultSchema = loose({ product_id: idSchema });
2912
+ var ConnectOrganisationResultSchema = loose({
2913
+ organisation_id: idSchema,
2914
+ products: zod.z.array(idSchema)
2915
+ });
2916
+ var ConnectProductResultSchema = loose({
2917
+ product_id: idSchema,
2918
+ organisations: zod.z.array(idSchema)
2919
+ });
2920
+ var CreateProductInputSchema = zod.z.object({
2921
+ /** Name of the product (required). */
2922
+ name: zod.z.string(),
2923
+ /** Unique slug identifier for the product (required). */
2924
+ identifier: zod.z.string(),
2925
+ /** Product type identifier (required). */
2926
+ type: zod.z.string(),
2927
+ /** The supplier's id (required for main products). */
2928
+ supplier_id: idSchema.optional(),
2929
+ /** USP shown in the agent portal during a sale. */
2930
+ usp: zod.z.string().optional(),
2931
+ description: zod.z.string().optional(),
2932
+ /** Contract duration in months. */
2933
+ duration: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
2934
+ /** `1` = business, `0` = consumer, `2` = both (main products only). */
2935
+ business: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
2936
+ /** `0` = new customers, `1` = existing, `2` = both (required for main products). */
2937
+ retention: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
2938
+ /** `1` = active, `0` = inactive (required). */
2939
+ active: zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean()]),
2940
+ /** One-time price. */
2941
+ price: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
2942
+ /** One-time promotion price. */
2943
+ price_action: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
2944
+ /** Monthly price. */
2945
+ price_monthly: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
2946
+ /** Monthly promotion price. */
2947
+ price_monthly_action: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
2948
+ /** Number of months the promotion price applies. */
2949
+ price_monthly_action_value: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
2950
+ /** Start date from which the product can be sold. */
2951
+ valid_from: zod.z.string().optional(),
2952
+ /** End date until which the product can be sold. */
2953
+ valid_till: zod.z.string().optional(),
2954
+ /** Image as `{ content: base64, extension: "png"|"gif"|"jpg"|"jpeg" }`. */
2955
+ image: zod.z.object({ content: zod.z.string().optional(), extension: zod.z.string().optional() }).passthrough().optional(),
2956
+ /** Product documents to attach, as an array. */
2957
+ attachments: zod.z.array(zod.z.unknown()).optional()
2958
+ }).passthrough();
2959
+ var UpdateProductInputSchema = zod.z.object({
2960
+ name: zod.z.string().optional(),
2961
+ identifier: zod.z.string().optional(),
2962
+ type: zod.z.string().optional(),
2963
+ supplier_id: idSchema.optional(),
2964
+ usp: zod.z.string().optional(),
2965
+ description: zod.z.string().optional(),
2966
+ duration: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
2967
+ business: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
2968
+ retention: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
2969
+ active: zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean()]).optional(),
2970
+ price: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
2971
+ price_action: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
2972
+ price_monthly: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
2973
+ price_monthly_action: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
2974
+ price_monthly_action_value: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
2975
+ valid_from: zod.z.string().optional(),
2976
+ valid_till: zod.z.string().optional(),
2977
+ image: zod.z.object({ content: zod.z.string().optional(), extension: zod.z.string().optional() }).passthrough().optional(),
2978
+ attachments: zod.z.array(zod.z.unknown()).optional()
2979
+ }).passthrough();
2980
+ var ConnectOrganisationToProductsInputSchema = zod.z.object({
2981
+ /**
2982
+ * Product ids to connect. Omit to connect all available products; send an
2983
+ * empty array to disconnect all.
2984
+ */
2985
+ products: zod.z.array(idSchema).optional()
2986
+ }).passthrough();
2987
+ var ConnectProductToOrganisationsInputSchema = zod.z.object({
2988
+ /**
2989
+ * Organisation ids to connect. Omit to connect all available organisations;
2990
+ * send an empty array to disconnect all.
2991
+ */
2992
+ organisations: zod.z.array(idSchema).optional()
2993
+ }).passthrough();
2994
+ var ProductsClient = class extends BaseResource {
2995
+ constructor(http, config) {
2996
+ super(http, config);
2997
+ this.suppliers = new SuppliersClient(http, config);
2998
+ }
2999
+ /** List products with their basic details. Honors the configured scope. */
3000
+ list(params = {}, options) {
3001
+ return this.http.request({
3002
+ method: "GET",
3003
+ segments: [this.scope(options), "products"],
3004
+ dataSchema: zod.z.array(ProductListItemSchema),
3005
+ query: params,
3006
+ options
3007
+ });
3008
+ }
3009
+ /** Retrieve a single product by id. Honors the configured scope. */
3010
+ get(productId, options) {
3011
+ return this.http.request({
3012
+ method: "GET",
3013
+ segments: [this.scope(options), "products", productId],
3014
+ dataSchema: ProductSchema,
3015
+ options
3016
+ });
3017
+ }
3018
+ /** Create a product (always `account` scope, admin only). */
3019
+ create(input, options) {
3020
+ const body = this.parseInput(CreateProductInputSchema, input, "products.create");
3021
+ return this.http.request({
3022
+ method: "POST",
3023
+ segments: ["account", "products"],
3024
+ dataSchema: MutateProductResultSchema,
3025
+ body,
3026
+ options
3027
+ });
3028
+ }
3029
+ /** Update a product by id (always `account` scope, admin only). */
3030
+ update(productId, input, options) {
3031
+ const body = this.parseInput(UpdateProductInputSchema, input, "products.update");
3032
+ return this.http.request({
3033
+ method: "PUT",
3034
+ segments: ["account", "products", productId],
3035
+ dataSchema: MutateProductResultSchema,
3036
+ body,
3037
+ options
3038
+ });
3039
+ }
3040
+ /** Delete a product by id (always `account` scope, admin only). */
3041
+ delete(productId, options) {
3042
+ return this.http.request({
3043
+ method: "DELETE",
3044
+ segments: ["account", "products", productId],
3045
+ dataSchema: MutateProductResultSchema,
3046
+ options
3047
+ });
3048
+ }
3049
+ /**
3050
+ * Connect a set of products to an organisation so its users can sell them.
3051
+ * Always `account` scope (admin only). Omit `products` to connect all; pass
3052
+ * an empty array to disconnect all. Returns the connected product ids.
3053
+ */
3054
+ connectOrganisationToProducts(organisationId, input = {}, options) {
3055
+ const body = this.parseInput(
3056
+ ConnectOrganisationToProductsInputSchema,
3057
+ input,
3058
+ "products.connectOrganisationToProducts"
3059
+ );
3060
+ return this.http.request({
3061
+ method: "POST",
3062
+ segments: ["account", "connect-organisation-to-products", organisationId],
3063
+ dataSchema: ConnectOrganisationResultSchema,
3064
+ body,
3065
+ options
3066
+ });
3067
+ }
3068
+ /**
3069
+ * Connect a set of organisations to a product so their users can sell it.
3070
+ * Always `account` scope (admin only). Omit `organisations` to connect all;
3071
+ * pass an empty array to disconnect all. Returns the connected organisation ids.
3072
+ */
3073
+ connectProductToOrganisations(productId, input = {}, options) {
3074
+ const body = this.parseInput(
3075
+ ConnectProductToOrganisationsInputSchema,
3076
+ input,
3077
+ "products.connectProductToOrganisations"
3078
+ );
3079
+ return this.http.request({
3080
+ method: "POST",
3081
+ segments: ["account", "connect-product-to-organisations", productId],
3082
+ dataSchema: ConnectProductResultSchema,
3083
+ body,
3084
+ options
3085
+ });
3086
+ }
3087
+ };
3088
+ var TaskUserRefSchema = loose({
3089
+ id: nullish(idSchema),
3090
+ name: nullish(zod.z.string()),
3091
+ organisation: loose({
3092
+ id: nullish(idSchema),
3093
+ name: nullish(zod.z.string())
3094
+ }).optional(),
3095
+ team: loose({
3096
+ id: nullish(idSchema),
3097
+ name: nullish(zod.z.string())
3098
+ }).optional()
3099
+ });
3100
+ var TaskListItemSchema = loose({
3101
+ id: idSchema,
3102
+ title: nullish(zod.z.string()),
3103
+ type: nullish(zod.z.string()),
3104
+ status: nullish(zod.z.string()),
3105
+ planned_date: nullish(zod.z.string()),
3106
+ planned_time: nullish(zod.z.string()),
3107
+ end_time: nullish(zod.z.string()),
3108
+ assigned_user_id: nullish(idSchema),
3109
+ owner_user_id: nullish(idSchema),
3110
+ assigned_to: TaskUserRefSchema.optional(),
3111
+ owner: TaskUserRefSchema.optional(),
3112
+ description: nullish(zod.z.string()),
3113
+ remarks: nullish(zod.z.string()),
3114
+ location: nullish(zod.z.string()),
3115
+ lead_id: nullish(idSchema),
3116
+ relation_id: nullish(idSchema),
3117
+ completed_at: nullish(zod.z.string()),
3118
+ created_at: nullish(zod.z.string()),
3119
+ updated_at: nullish(zod.z.string())
3120
+ });
3121
+ var TaskSchema = loose({
3122
+ id: idSchema,
3123
+ title: nullish(zod.z.string()),
3124
+ type: nullish(zod.z.string()),
3125
+ status: nullish(zod.z.string()),
3126
+ description: nullish(zod.z.string()),
3127
+ remarks: nullish(zod.z.string()),
3128
+ location: nullish(zod.z.string()),
3129
+ planned_date: nullish(zod.z.string()),
3130
+ planned_time: nullish(zod.z.string()),
3131
+ end_time: nullish(zod.z.string()),
3132
+ assigned_user_id: nullish(idSchema),
3133
+ assigned_user: nullish(zod.z.string()),
3134
+ owner_user_id: nullish(idSchema),
3135
+ owner_user: nullish(zod.z.string()),
3136
+ assigned_to: TaskUserRefSchema.optional(),
3137
+ owner: TaskUserRefSchema.optional(),
3138
+ lead_id: nullish(idSchema),
3139
+ relation_id: nullish(idSchema),
3140
+ completed_at: nullish(zod.z.string()),
3141
+ created_at: nullish(zod.z.string()),
3142
+ updated_at: nullish(zod.z.string())
3143
+ });
3144
+ var MutateTaskResultSchema = loose({ task_id: idSchema });
3145
+ var TaskInputSchema = zod.z.object({
3146
+ /** The title of the task (required). */
3147
+ title: zod.z.string(),
3148
+ /** Task type: `default`, `appointment`, or `callback` (required). */
3149
+ type: zod.z.string(),
3150
+ /** Description of the task. */
3151
+ description: zod.z.string().optional(),
3152
+ /** Remarks (if any) for the task. */
3153
+ remarks: zod.z.string().optional(),
3154
+ /** The location where the task is planned to take place. */
3155
+ location: zod.z.string().optional(),
3156
+ /** The planned date of the task in `dd-mm-yyyy` format. */
3157
+ planned_date: zod.z.string().optional(),
3158
+ /** The planned start time of the task in `hh:mm` format. */
3159
+ planned_start_time: zod.z.string().optional(),
3160
+ /** The planned end time of the task in `hh:mm` format. */
3161
+ planned_end_time: zod.z.string().optional(),
3162
+ /** The ID of the user to assign the task to. */
3163
+ user_id: idSchema.optional(),
3164
+ /** The ID of the relation to attach the task to. */
3165
+ relation_id: idSchema.optional(),
3166
+ /** Whether the task is completed: `yes` or `no`. */
3167
+ completed: zod.z.union([zod.z.literal("yes"), zod.z.literal("no")]).optional()
3168
+ }).passthrough();
3169
+ var TasksClient = class extends BaseResource {
3170
+ /** List tasks (cursor-paginated). Honors the configured scope. */
3171
+ list(params = {}, options) {
3172
+ return fetchCursorPage(
3173
+ this.http,
3174
+ TaskListItemSchema,
3175
+ [this.scope(options), "tasks"],
3176
+ params,
3177
+ options
3178
+ );
3179
+ }
3180
+ /** Retrieve a single task by id. Honors the configured scope. */
3181
+ get(taskId, options) {
3182
+ return this.http.request({
3183
+ method: "GET",
3184
+ segments: [this.scope(options), "tasks", taskId],
3185
+ dataSchema: TaskSchema,
3186
+ options
3187
+ });
3188
+ }
3189
+ /** Create a task. Honors the configured scope. */
3190
+ create(input, options) {
3191
+ const body = this.parseInput(TaskInputSchema, input, "tasks.create");
3192
+ return this.http.request({
3193
+ method: "POST",
3194
+ segments: [this.scope(options), "tasks"],
3195
+ dataSchema: MutateTaskResultSchema,
3196
+ body,
3197
+ options
3198
+ });
3199
+ }
3200
+ /** Update a task by id. Honors the configured scope. */
3201
+ update(taskId, input, options) {
3202
+ const body = this.parseInput(TaskInputSchema, input, "tasks.update");
3203
+ return this.http.request({
3204
+ method: "PUT",
3205
+ segments: [this.scope(options), "tasks", taskId],
3206
+ dataSchema: MutateTaskResultSchema,
3207
+ body,
3208
+ options
3209
+ });
3210
+ }
3211
+ /** Delete a task by id (always `account` scope, admin only). */
3212
+ delete(taskId, options) {
3213
+ return this.http.request({
3214
+ method: "DELETE",
3215
+ segments: ["account", "tasks", taskId],
3216
+ dataSchema: MutateTaskResultSchema,
3217
+ options
3218
+ });
3219
+ }
3220
+ };
3221
+ var KNOWN_WEBHOOK_EVENTS = [
3222
+ "task.created",
3223
+ "offer.accepted",
3224
+ "offer.viewed",
3225
+ "sale.cancelled",
3226
+ "sale.deleted",
3227
+ "lead.created",
3228
+ "lead.updated",
3229
+ "lead.deleted",
3230
+ "lead.completed",
3231
+ "product.updated"
3232
+ ];
3233
+ var WebhookSubscriptionSchema = loose({
3234
+ uuid: zod.z.string(),
3235
+ event: zod.z.string(),
3236
+ target_url: zod.z.string(),
3237
+ subscribed_at: zod.z.string()
3238
+ });
3239
+ var SubscribeWebhookSchema = zod.z.object({
3240
+ /** The event to subscribe to, e.g. `"offer.accepted"`. */
3241
+ event: zod.z.string(),
3242
+ /** The URL Salesdock will POST the event payload to. */
3243
+ target_url: zod.z.string().url()
3244
+ }).passthrough();
3245
+ var WebhooksClient = class extends BaseResource {
3246
+ /** List the webhook event types you can subscribe to. */
3247
+ listEvents(options) {
3248
+ return this.http.request({
3249
+ method: "GET",
3250
+ segments: ["account", "webhooks", "events"],
3251
+ dataSchema: zod.z.array(zod.z.string()),
3252
+ options
3253
+ });
3254
+ }
3255
+ /** Subscribe a `target_url` to an event. */
3256
+ subscribe(input, options) {
3257
+ const body = this.parseInput(SubscribeWebhookSchema, input, "webhooks.subscribe");
3258
+ return this.http.request({
3259
+ method: "POST",
3260
+ segments: ["account", "webhooks"],
3261
+ dataSchema: WebhookSubscriptionSchema,
3262
+ body,
3263
+ options
3264
+ });
3265
+ }
3266
+ /** List your current webhook subscriptions. */
3267
+ listSubscriptions(options) {
3268
+ return this.http.request({
3269
+ method: "GET",
3270
+ segments: ["account", "webhooks"],
3271
+ dataSchema: zod.z.array(WebhookSubscriptionSchema),
3272
+ options
3273
+ });
3274
+ }
3275
+ /** Unsubscribe by subscription UUID. */
3276
+ unsubscribe(uuid, options) {
3277
+ return this.http.request({
3278
+ method: "DELETE",
3279
+ segments: ["account", "webhooks", uuid],
3280
+ dataSchema: zod.z.unknown(),
3281
+ options
3282
+ });
3283
+ }
3284
+ };
3285
+
3286
+ // src/client.ts
3287
+ var Salesdock = class {
3288
+ constructor(config) {
3289
+ this.config = resolveConfig(config);
3290
+ this.http = new HttpClient(this.config);
3291
+ this.sales = new SalesClient(this.http, this.config);
3292
+ this.dialer = new DialerClient(this.http, this.config);
3293
+ this.users = new UsersClient(this.http, this.config);
3294
+ this.commissions = new CommissionsClient(this.http, this.config);
3295
+ this.leads = new LeadsClient(this.http, this.config);
3296
+ this.forms = new FormsClient(this.http, this.config);
3297
+ this.relations = new RelationsClient(this.http, this.config);
3298
+ this.products = new ProductsClient(this.http, this.config);
3299
+ this.tasks = new TasksClient(this.http, this.config);
3300
+ this.webhooks = new WebhooksClient(this.http, this.config);
3301
+ }
3302
+ /**
3303
+ * Low-level escape hatch for endpoints (or query/body shapes) not covered by
3304
+ * a typed method. `segments` are the path parts after
3305
+ * `/api/{domain}/{version}/` and must include the scope segment yourself
3306
+ * (e.g. `["account", "sales", 440]`). The response `data` is returned as-is.
3307
+ *
3308
+ * @example
3309
+ * ```ts
3310
+ * const data = await sd.request("GET", ["account", "commissions", "outgoing"]);
3311
+ * ```
3312
+ */
3313
+ request(method, segments, init = {}) {
3314
+ return this.http.request({
3315
+ method,
3316
+ segments,
3317
+ dataSchema: zod.z.unknown(),
3318
+ query: init.query,
3319
+ body: init.body,
3320
+ options: init.options
3321
+ });
3322
+ }
3323
+ };
3324
+ /** Production base URL (`https://app.salesdock.nl`). */
3325
+ Salesdock.PRODUCTION_BASE_URL = PRODUCTION_BASE_URL;
3326
+ /** Staging base URL (`https://app-staging.salesdock.nl`). */
3327
+ Salesdock.STAGING_BASE_URL = STAGING_BASE_URL;
3328
+
3329
+ // src/core/base64.ts
3330
+ function decodeBase64(base64) {
3331
+ let normalized = base64.replace(/\s+/g, "").replace(/-/g, "+").replace(/_/g, "/");
3332
+ const remainder = normalized.length % 4;
3333
+ if (remainder === 2) normalized += "==";
3334
+ else if (remainder === 3) normalized += "=";
3335
+ const binary = atob(normalized);
3336
+ const len = binary.length;
3337
+ const bytes = new Uint8Array(len);
3338
+ for (let i = 0; i < len; i++) {
3339
+ bytes[i] = binary.charCodeAt(i);
3340
+ }
3341
+ return bytes;
3342
+ }
3343
+
3344
+ exports.AgreementListItemSchema = AgreementListItemSchema;
3345
+ exports.AgreementSchema = AgreementSchema;
3346
+ exports.BaseResource = BaseResource;
3347
+ exports.CommissionListSchema = CommissionListSchema;
3348
+ exports.CommissionSchema = CommissionSchema;
3349
+ exports.CommissionTotalsBreakdownSchema = CommissionTotalsBreakdownSchema;
3350
+ exports.CommissionTotalsSchema = CommissionTotalsSchema;
3351
+ exports.CommissionsClient = CommissionsClient;
3352
+ exports.ConceptFieldSchema = ConceptFieldSchema;
3353
+ exports.ConceptFieldsSchema = ConceptFieldsSchema;
3354
+ exports.ConceptLeadResultSchema = ConceptLeadResultSchema;
3355
+ exports.ConceptTransactionResultSchema = ConceptTransactionResultSchema;
3356
+ exports.ConceptTransactionSalesSchema = ConceptTransactionSalesSchema;
3357
+ exports.ConnectOrganisationResultSchema = ConnectOrganisationResultSchema;
3358
+ exports.ConnectOrganisationToProductsInputSchema = ConnectOrganisationToProductsInputSchema;
3359
+ exports.ConnectProductResultSchema = ConnectProductResultSchema;
3360
+ exports.ConnectProductToOrganisationsInputSchema = ConnectProductToOrganisationsInputSchema;
3361
+ exports.CreateConceptLeadSchema = CreateConceptLeadSchema;
3362
+ exports.CreateConceptTransactionSchema = CreateConceptTransactionSchema;
3363
+ exports.CreateConceptTransactionWithOptinSchema = CreateConceptTransactionWithOptinSchema;
3364
+ exports.CreateLeadAsAdminSchema = CreateLeadAsAdminSchema;
3365
+ exports.CreateLeadAsResellerSchema = CreateLeadAsResellerSchema;
3366
+ exports.CreateLeadFormInstanceResultSchema = CreateLeadFormInstanceResultSchema;
3367
+ exports.CreateLeadFormInstanceSchema = CreateLeadFormInstanceSchema;
3368
+ exports.CreateOptinInputSchema = CreateOptinInputSchema;
3369
+ exports.CreateProductInputSchema = CreateProductInputSchema;
3370
+ exports.CreateSaleResultSchema = CreateSaleResultSchema;
3371
+ exports.CursorPage = CursorPage;
3372
+ exports.DEFAULT_VERSION = DEFAULT_VERSION;
3373
+ exports.DefaultSaleInputSchema = DefaultSaleInputSchema;
3374
+ exports.DialerClient = DialerClient;
3375
+ exports.EnergyBeClient = EnergyBeClient;
3376
+ exports.EnergyBeSaleInputSchema = EnergyBeSaleInputSchema;
3377
+ exports.EnergyClient = EnergyClient;
3378
+ exports.EnergyNlClient = EnergyNlClient;
3379
+ exports.EnergyNlSaleInputSchema = EnergyNlSaleInputSchema;
3380
+ exports.EnergyProductSchema = EnergyProductSchema;
3381
+ exports.EnergyUsageEstimationSchema = EnergyUsageEstimationSchema;
3382
+ exports.FillFormFileSchema = FillFormFileSchema;
3383
+ exports.FillFormInstanceResultSchema = FillFormInstanceResultSchema;
3384
+ exports.FillFormInstanceSchema = FillFormInstanceSchema;
3385
+ exports.FlowListItemSchema = FlowListItemSchema;
3386
+ exports.FlowSchema = FlowSchema;
3387
+ exports.FormElementSchema = FormElementSchema;
3388
+ exports.FormInstanceListItemSchema = FormInstanceListItemSchema;
3389
+ exports.FormInstancePdfSchema = FormInstancePdfSchema;
3390
+ exports.FormInstanceRelationSchema = FormInstanceRelationSchema;
3391
+ exports.FormInstanceSchema = FormInstanceSchema;
3392
+ exports.FormSchema = FormSchema;
3393
+ exports.FormStatusSchema = FormStatusSchema;
3394
+ exports.FormsClient = FormsClient;
3395
+ exports.HeatPumpSaleInputSchema = HeatPumpSaleInputSchema;
3396
+ exports.HeatPumpsClient = HeatPumpsClient;
3397
+ exports.HostedVoiceClient = HostedVoiceClient;
3398
+ exports.HostedVoiceSaleInputSchema = HostedVoiceSaleInputSchema;
3399
+ exports.IncomingCommissionsClient = IncomingCommissionsClient;
3400
+ exports.InviteUserInputSchema = InviteUserInputSchema;
3401
+ exports.KNOWN_WEBHOOK_EVENTS = KNOWN_WEBHOOK_EVENTS;
3402
+ exports.LastSaleSchema = LastSaleSchema;
3403
+ exports.LeadActivitySchema = LeadActivitySchema;
3404
+ exports.LeadFormElementSchema = LeadFormElementSchema;
3405
+ exports.LeadFormPdfSchema = LeadFormPdfSchema;
3406
+ exports.LeadFormSchema = LeadFormSchema;
3407
+ exports.LeadHistoryEntrySchema = LeadHistoryEntrySchema;
3408
+ exports.LeadLabelSchema = LeadLabelSchema;
3409
+ exports.LeadListItemSchema = LeadListItemSchema;
3410
+ exports.LeadResultSchema = LeadResultSchema;
3411
+ exports.LeadSchema = LeadSchema;
3412
+ exports.LeadSourceSchema = LeadSourceSchema;
3413
+ exports.LeadStatusSchema = LeadStatusSchema;
3414
+ exports.LeadsClient = LeadsClient;
3415
+ exports.MediaBlobSchema = MediaBlobSchema;
3416
+ exports.MultiProductSaleInputSchema = MultiProductSaleInputSchema;
3417
+ exports.MutateLeadResultSchema = MutateLeadResultSchema;
3418
+ exports.MutateOrganisationResultSchema = MutateOrganisationResultSchema;
3419
+ exports.MutateProductResultSchema = MutateProductResultSchema;
3420
+ exports.MutateRelationResultSchema = MutateRelationResultSchema;
3421
+ exports.MutateSaleResultSchema = MutateSaleResultSchema;
3422
+ exports.MutateSupplierResultSchema = MutateSupplierResultSchema;
3423
+ exports.MutateTaskResultSchema = MutateTaskResultSchema;
3424
+ exports.OffsetPage = OffsetPage;
3425
+ exports.OptinChannelInputSchema = OptinChannelInputSchema;
3426
+ exports.OrganisationInputSchema = OrganisationInputSchema;
3427
+ exports.OrganisationListItemSchema = OrganisationListItemSchema;
3428
+ exports.OrganisationLogoInputSchema = OrganisationLogoInputSchema;
3429
+ exports.OrganisationLogoSchema = OrganisationLogoSchema;
3430
+ exports.OrganisationProductsSchema = OrganisationProductsSchema;
3431
+ exports.OrganisationSchema = OrganisationSchema;
3432
+ exports.OrganisationsClient = OrganisationsClient;
3433
+ exports.OutgoingCommissionsClient = OutgoingCommissionsClient;
3434
+ exports.PRODUCTION_BASE_URL = PRODUCTION_BASE_URL;
3435
+ exports.PanelsEstimationSchema = PanelsEstimationSchema;
3436
+ exports.ProductDocumentSchema = ProductDocumentSchema;
3437
+ exports.ProductListItemSchema = ProductListItemSchema;
3438
+ exports.ProductQuestionListItemSchema = ProductQuestionListItemSchema;
3439
+ exports.ProductQuestionSchema = ProductQuestionSchema;
3440
+ exports.ProductSchema = ProductSchema;
3441
+ exports.ProductsClient = ProductsClient;
3442
+ exports.RelationInputSchema = RelationInputSchema;
3443
+ exports.RelationListItemSchema = RelationListItemSchema;
3444
+ exports.RelationSchema = RelationSchema;
3445
+ exports.RelationsClient = RelationsClient;
3446
+ exports.SDK_VERSION = SDK_VERSION;
3447
+ exports.STAGING_BASE_URL = STAGING_BASE_URL;
3448
+ exports.SaleContractSchema = SaleContractSchema;
3449
+ exports.SaleDocumentSchema = SaleDocumentSchema;
3450
+ exports.SaleExportRowSchema = SaleExportRowSchema;
3451
+ exports.SaleHistoryEntrySchema = SaleHistoryEntrySchema;
3452
+ exports.SaleListItemSchema = SaleListItemSchema;
3453
+ exports.SaleOfLeadSchema = SaleOfLeadSchema;
3454
+ exports.SaleProductsSchema = SaleProductsSchema;
3455
+ exports.SaleSchema = SaleSchema;
3456
+ exports.SaleStatusSchema = SaleStatusSchema;
3457
+ exports.SaleViewUrlSchema = SaleViewUrlSchema;
3458
+ exports.SalesClient = SalesClient;
3459
+ exports.Salesdock = Salesdock;
3460
+ exports.SalesdockAuthenticationError = SalesdockAuthenticationError;
3461
+ exports.SalesdockConnectionError = SalesdockConnectionError;
3462
+ exports.SalesdockError = SalesdockError;
3463
+ exports.SalesdockForbiddenError = SalesdockForbiddenError;
3464
+ exports.SalesdockInvalidRequestError = SalesdockInvalidRequestError;
3465
+ exports.SalesdockMethodNotAllowedError = SalesdockMethodNotAllowedError;
3466
+ exports.SalesdockNotFoundError = SalesdockNotFoundError;
3467
+ exports.SalesdockRateLimitError = SalesdockRateLimitError;
3468
+ exports.SalesdockResponseValidationError = SalesdockResponseValidationError;
3469
+ exports.SalesdockServerError = SalesdockServerError;
3470
+ exports.SalesdockTimeoutError = SalesdockTimeoutError;
3471
+ exports.SalesdockValidationError = SalesdockValidationError;
3472
+ exports.SolarClient = SolarClient;
3473
+ exports.SolarComparePackageSchema = SolarComparePackageSchema;
3474
+ exports.SolarSaleInputSchema = SolarSaleInputSchema;
3475
+ exports.SubscribeWebhookSchema = SubscribeWebhookSchema;
3476
+ exports.SupplierInputSchema = SupplierInputSchema;
3477
+ exports.SupplierListItemSchema = SupplierListItemSchema;
3478
+ exports.SupplierSchema = SupplierSchema;
3479
+ exports.SuppliersClient = SuppliersClient;
3480
+ exports.TaskInputSchema = TaskInputSchema;
3481
+ exports.TaskListItemSchema = TaskListItemSchema;
3482
+ exports.TaskSchema = TaskSchema;
3483
+ exports.TaskUserRefSchema = TaskUserRefSchema;
3484
+ exports.TasksClient = TasksClient;
3485
+ exports.TelecomClient = TelecomClient;
3486
+ exports.TelecomCompareSchema = TelecomCompareSchema;
3487
+ exports.TelecomSaleInputSchema = TelecomSaleInputSchema;
3488
+ exports.TownshipSchema = TownshipSchema;
3489
+ exports.TownshipsClient = TownshipsClient;
3490
+ exports.UpdateEnergyProductInputSchema = UpdateEnergyProductInputSchema;
3491
+ exports.UpdateLeadAsAdminSchema = UpdateLeadAsAdminSchema;
3492
+ exports.UpdateLeadAsResellerSchema = UpdateLeadAsResellerSchema;
3493
+ exports.UpdateLeadStatusSchema = UpdateLeadStatusSchema;
3494
+ exports.UpdateProductInputSchema = UpdateProductInputSchema;
3495
+ exports.UpdateSaleFieldsInputSchema = UpdateSaleFieldsInputSchema;
3496
+ exports.UpdateSaleInputSchema = UpdateSaleInputSchema;
3497
+ exports.UserSchema = UserSchema;
3498
+ exports.UsersClient = UsersClient;
3499
+ exports.WebhookSubscriptionSchema = WebhookSubscriptionSchema;
3500
+ exports.WebhooksClient = WebhooksClient;
3501
+ exports.addressSchema = addressSchema;
3502
+ exports.boolishSchema = boolishSchema;
3503
+ exports.cursorPaginatedSchema = cursorPaginatedSchema;
3504
+ exports.customerSchema = customerSchema;
3505
+ exports.dateTimeSchema = dateTimeSchema;
3506
+ exports.decodeBase64 = decodeBase64;
3507
+ exports.envelopeSchema = envelopeSchema;
3508
+ exports.extraFieldSchema = extraFieldSchema;
3509
+ exports.idSchema = idSchema;
3510
+ exports.loose = loose;
3511
+ exports.nullish = nullish;
3512
+ exports.offsetPaginatedSchema = offsetPaginatedSchema;
3513
+ exports.paginationLinkSchema = paginationLinkSchema;
3514
+ exports.statusSchema = statusSchema;
3515
+ //# sourceMappingURL=index.cjs.map
3516
+ //# sourceMappingURL=index.cjs.map