@ikatec/digisac-api-sdk 2.2.1 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/apis/acceptanceTerms/types.d.ts +18 -2
  2. package/dist/apis/acceptanceTerms/types.d.ts.map +1 -1
  3. package/dist/apis/accounts/types.d.ts +2 -0
  4. package/dist/apis/accounts/types.d.ts.map +1 -1
  5. package/dist/apis/cards/types.d.ts +89 -7
  6. package/dist/apis/cards/types.d.ts.map +1 -1
  7. package/dist/apis/pipeline/types.d.ts +67 -3
  8. package/dist/apis/pipeline/types.d.ts.map +1 -1
  9. package/dist/apis/terms/TermsApi.cjs +34 -6
  10. package/dist/apis/terms/TermsApi.cjs.map +1 -1
  11. package/dist/apis/terms/TermsApi.d.ts +27 -6
  12. package/dist/apis/terms/TermsApi.d.ts.map +1 -1
  13. package/dist/apis/terms/TermsApi.mjs +34 -6
  14. package/dist/apis/terms/TermsApi.mjs.map +1 -1
  15. package/dist/apis/terms/types.d.ts +0 -14
  16. package/dist/apis/terms/types.d.ts.map +1 -1
  17. package/dist/core/BaseApiClient.cjs +26 -1
  18. package/dist/core/BaseApiClient.cjs.map +1 -1
  19. package/dist/core/BaseApiClient.d.ts.map +1 -1
  20. package/dist/core/BaseApiClient.mjs +26 -1
  21. package/dist/core/BaseApiClient.mjs.map +1 -1
  22. package/dist/incommingWebhooks/index.d.ts +3 -3
  23. package/dist/incommingWebhooks/index.d.ts.map +1 -1
  24. package/package.json +1 -1
  25. package/src/apis/acceptanceTerms/AcceptanceTermsApi.test.ts +96 -0
  26. package/src/apis/acceptanceTerms/types.ts +19 -2
  27. package/src/apis/accounts/types.ts +2 -0
  28. package/src/apis/cards/types.ts +104 -7
  29. package/src/apis/pipeline/types.ts +71 -3
  30. package/src/apis/terms/TermsApi.test.ts +56 -102
  31. package/src/apis/terms/TermsApi.ts +41 -12
  32. package/src/apis/terms/types.ts +0 -16
  33. package/src/core/BaseApiClient.test.ts +53 -0
  34. package/src/core/BaseApiClient.ts +37 -1
  35. package/src/incommingWebhooks/index.ts +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"BaseApiClient.cjs","names":[],"sources":["../../src/core/BaseApiClient.ts"],"sourcesContent":["import type { ApiClient, HttpMethod } from './ApiClient'\n\nexport interface ValidationError {\n path: string\n message: string\n code: string\n}\n\nexport class ApiError extends Error {\n public readonly errorClass?: string | undefined\n public readonly status?: number | undefined\n public readonly validationErrors: ValidationError[] | null\n\n constructor(\n message: string,\n errorClass?: string,\n status?: number,\n validationErrors: ValidationError[] | null = null,\n ) {\n super(message)\n this.name = 'ApiError'\n this.errorClass = errorClass\n this.status = status\n this.validationErrors = validationErrors\n }\n}\n\nexport class BaseApiClient implements ApiClient {\n protected readonly baseUrl: string\n protected accessToken: string | null = null\n\n constructor(baseUrl: string, accessToken?: string) {\n this.baseUrl = baseUrl.replace(/\\/$/, '')\n this.accessToken = accessToken || null\n }\n\n setAccessToken(accessToken: string): this {\n this.accessToken = accessToken\n return this\n }\n\n async request<TResponse = unknown, TBody = unknown>(\n method: HttpMethod,\n endpoint: string,\n body?: TBody,\n headers?: Record<string, string>,\n ): Promise<TResponse> {\n const url = `${this.baseUrl}/${endpoint.replace(/^\\//, '')}`\n\n const response = await fetch(url, {\n method,\n headers: {\n 'Content-Type': 'application/json',\n ...(this.accessToken && { Authorization: `Bearer ${this.accessToken}` }),\n ...headers,\n },\n ...(body !== undefined && { body: JSON.stringify(body) }),\n })\n\n return this.handleResponse<TResponse>(response)\n }\n\n protected async handleResponse<TResponse>(response: Response): Promise<TResponse> {\n if (!response.ok) {\n const contentType = response.headers.get('Content-Type')\n const isJson = contentType?.includes('application/json') ?? false\n\n let errorMessage = `HTTP Error ${response.status}: ${response.statusText}`\n let errorClass: string | undefined\n let validationErrors: ValidationError[] | null = null\n\n if (isJson) {\n try {\n const errorText = await response.text()\n if (errorText) {\n const errorData = JSON.parse(errorText)\n errorMessage = errorData.message || errorData.error || errorMessage\n errorClass = errorData.error\n validationErrors = errorData.validationErrors ?? null\n }\n } catch {\n // If JSON parsing fails, use the default error message\n }\n }\n\n throw new ApiError(errorMessage, errorClass, response.status, validationErrors)\n }\n\n // 204 No Content never has a body; short-circuit before reading the stream.\n if (response.status === 204) {\n return undefined as unknown as TResponse\n }\n\n // Read body as text once and treat an empty body as \"no content\" regardless of\n // Content-Type. Servers sometimes return 200 with Content-Type: application/json\n // and an empty body (e.g. POST endpoints whose framework keeps the default JSON\n // content-type even when nothing is written). `response.json()` would throw\n // \"Unexpected end of input\" in that case.\n const text = await response.text()\n if (!text) {\n return undefined as unknown as TResponse\n }\n\n const contentType = response.headers.get('Content-Type')\n const isJson = contentType?.includes('application/json') ?? false\n\n if (isJson) {\n return JSON.parse(text) as TResponse\n }\n\n try {\n return JSON.parse(text) as TResponse\n } catch {\n return text as unknown as TResponse\n }\n }\n\n get<TResponse = unknown>(endpoint: string, headers?: Record<string, string>): Promise<TResponse> {\n return this.request<TResponse>('GET', endpoint, undefined, headers)\n }\n\n post<TResponse = unknown, TBody = unknown>(\n endpoint: string,\n body?: TBody,\n headers?: Record<string, string>,\n ): Promise<TResponse> {\n return this.request<TResponse, TBody>('POST', endpoint, body, headers)\n }\n\n put<TResponse = unknown, TBody = unknown>(\n endpoint: string,\n body?: TBody,\n headers?: Record<string, string>,\n ): Promise<TResponse> {\n return this.request<TResponse, TBody>('PUT', endpoint, body, headers)\n }\n\n patch<TResponse = unknown, TBody = unknown>(\n endpoint: string,\n body?: TBody,\n headers?: Record<string, string>,\n ): Promise<TResponse> {\n return this.request<TResponse, TBody>('PATCH', endpoint, body, headers)\n }\n\n delete<TResponse = unknown>(\n endpoint: string,\n headers?: Record<string, string>,\n ): Promise<TResponse> {\n return this.request<TResponse>('DELETE', endpoint, undefined, headers)\n }\n}\n"],"mappings":";;;AAQA,IAAa,WAAb,cAA8B,MAAM;CAClC,AAAgB;CAChB,AAAgB;CAChB,AAAgB;CAEhB,YACE,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C,MAAI,CAAC,KACH;AAMF,MAHoB,SAAS,QAAQ,IAAI,eAAe,EAC5B,SAAS,mBAAmB,IAAI,MAG1D,QAAO,KAAK,MAAM,KAAK;AAGzB,MAAI;AACF,UAAO,KAAK,MAAM,KAAK;UACjB;AACN,UAAO;;;CAIX,IAAyB,UAAkB,SAAsD;AAC/F,SAAO,KAAK,QAAmB,OAAO,UAAU,QAAW,QAAQ;;CAGrE,KACE,UACA,MACA,SACoB;AACpB,SAAO,KAAK,QAA0B,QAAQ,UAAU,MAAM,QAAQ;;CAGxE,IACE,UACA,MACA,SACoB;AACpB,SAAO,KAAK,QAA0B,OAAO,UAAU,MAAM,QAAQ;;CAGvE,MACE,UACA,MACA,SACoB;AACpB,SAAO,KAAK,QAA0B,SAAS,UAAU,MAAM,QAAQ;;CAGzE,OACE,UACA,SACoB;AACpB,SAAO,KAAK,QAAmB,UAAU,UAAU,QAAW,QAAQ"}
1
+ {"version":3,"file":"BaseApiClient.cjs","names":[],"sources":["../../src/core/BaseApiClient.ts"],"sourcesContent":["import type { ApiClient, HttpMethod } from './ApiClient'\n\nexport interface ValidationError {\n path: string\n message: string\n code: string\n}\n\n/**\n * Digisac field errors: `{ errors: { <location>: { <field>: { messages: string[], types: string[] } } } }`,\n * where location is `body`, `params`, `query`, `headers` or `cookies` (backend `validate` middleware).\n */\ntype DigisacFieldErrors = Record<string, Record<string, { messages?: unknown; types?: unknown }>>\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\n/**\n * Flattens the Digisac `errors` object into `ValidationError[]` — one entry per message, with\n * `path` = `<location>.<field>` (e.g. `body.name`) and `code` = the rule type (e.g. `required`).\n * Returns `null` when the body carries no field errors.\n */\nfunction parseValidationErrors(errors: unknown): ValidationError[] | null {\n if (!isRecord(errors)) {\n return null\n }\n\n const parsed: ValidationError[] = []\n for (const [location, fields] of Object.entries(errors as DigisacFieldErrors)) {\n if (!isRecord(fields)) {\n continue\n }\n for (const [field, detail] of Object.entries(fields)) {\n const messages = Array.isArray(detail?.messages) ? detail.messages.map(String) : []\n const types = Array.isArray(detail?.types) ? detail.types.map(String) : []\n messages.forEach((message, index) => {\n parsed.push({ path: `${location}.${field}`, message, code: types[index] ?? types[0] ?? '' })\n })\n }\n }\n\n return parsed.length ? parsed : null\n}\n\nexport class ApiError extends Error {\n public readonly errorClass?: string | undefined\n public readonly status?: number | undefined\n public readonly validationErrors: ValidationError[] | null\n\n constructor(\n message: string,\n errorClass?: string,\n status?: number,\n validationErrors: ValidationError[] | null = null,\n ) {\n super(message)\n this.name = 'ApiError'\n this.errorClass = errorClass\n this.status = status\n this.validationErrors = validationErrors\n }\n}\n\nexport class BaseApiClient implements ApiClient {\n protected readonly baseUrl: string\n protected accessToken: string | null = null\n\n constructor(baseUrl: string, accessToken?: string) {\n this.baseUrl = baseUrl.replace(/\\/$/, '')\n this.accessToken = accessToken || null\n }\n\n setAccessToken(accessToken: string): this {\n this.accessToken = accessToken\n return this\n }\n\n async request<TResponse = unknown, TBody = unknown>(\n method: HttpMethod,\n endpoint: string,\n body?: TBody,\n headers?: Record<string, string>,\n ): Promise<TResponse> {\n const url = `${this.baseUrl}/${endpoint.replace(/^\\//, '')}`\n\n const response = await fetch(url, {\n method,\n headers: {\n 'Content-Type': 'application/json',\n ...(this.accessToken && { Authorization: `Bearer ${this.accessToken}` }),\n ...headers,\n },\n ...(body !== undefined && { body: JSON.stringify(body) }),\n })\n\n return this.handleResponse<TResponse>(response)\n }\n\n protected async handleResponse<TResponse>(response: Response): Promise<TResponse> {\n if (!response.ok) {\n const contentType = response.headers.get('Content-Type')\n const isJson = contentType?.includes('application/json') ?? false\n\n let errorMessage = `HTTP Error ${response.status}: ${response.statusText}`\n let errorClass: string | undefined\n let validationErrors: ValidationError[] | null = null\n\n if (isJson) {\n try {\n const errorText = await response.text()\n if (errorText) {\n const errorData = JSON.parse(errorText)\n errorMessage = errorData.message || errorData.error || errorMessage\n errorClass = errorData.error\n validationErrors = errorData.validationErrors ?? parseValidationErrors(errorData.errors)\n }\n } catch {\n // If JSON parsing fails, use the default error message\n }\n }\n\n throw new ApiError(errorMessage, errorClass, response.status, validationErrors)\n }\n\n // 204 No Content never has a body; short-circuit before reading the stream.\n if (response.status === 204) {\n return undefined as unknown as TResponse\n }\n\n // Read body as text once and treat an empty body as \"no content\" regardless of\n // Content-Type. Servers sometimes return 200 with Content-Type: application/json\n // and an empty body (e.g. POST endpoints whose framework keeps the default JSON\n // content-type even when nothing is written). `response.json()` would throw\n // \"Unexpected end of input\" in that case.\n const text = await response.text()\n if (!text) {\n return undefined as unknown as TResponse\n }\n\n const contentType = response.headers.get('Content-Type')\n const isJson = contentType?.includes('application/json') ?? false\n\n if (isJson) {\n return JSON.parse(text) as TResponse\n }\n\n try {\n return JSON.parse(text) as TResponse\n } catch {\n return text as unknown as TResponse\n }\n }\n\n get<TResponse = unknown>(endpoint: string, headers?: Record<string, string>): Promise<TResponse> {\n return this.request<TResponse>('GET', endpoint, undefined, headers)\n }\n\n post<TResponse = unknown, TBody = unknown>(\n endpoint: string,\n body?: TBody,\n headers?: Record<string, string>,\n ): Promise<TResponse> {\n return this.request<TResponse, TBody>('POST', endpoint, body, headers)\n }\n\n put<TResponse = unknown, TBody = unknown>(\n endpoint: string,\n body?: TBody,\n headers?: Record<string, string>,\n ): Promise<TResponse> {\n return this.request<TResponse, TBody>('PUT', endpoint, body, headers)\n }\n\n patch<TResponse = unknown, TBody = unknown>(\n endpoint: string,\n body?: TBody,\n headers?: Record<string, string>,\n ): Promise<TResponse> {\n return this.request<TResponse, TBody>('PATCH', endpoint, body, headers)\n }\n\n delete<TResponse = unknown>(\n endpoint: string,\n headers?: Record<string, string>,\n ): Promise<TResponse> {\n return this.request<TResponse>('DELETE', endpoint, undefined, headers)\n }\n}\n"],"mappings":";;;AAcA,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;;;;;;AAOtE,SA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;IAIrB,GAAG,CAAC,SAAS,GAAG,OAAO,EAAE,KAAK,GAAG,OAAO,EACtC,QAAQ,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE,KAAK,EACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,SAAS,CAAC;IAIrB,KAAK,CAAC,SAAS,GAAG,OAAO,EAAE,KAAK,GAAG,OAAO,EACxC,QAAQ,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE,KAAK,EACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,SAAS,CAAC;IAIrB,MAAM,CAAC,SAAS,GAAG,OAAO,EACxB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,SAAS,CAAC;CAGtB"}
@@ -1,4 +1,29 @@
1
1
  //#region src/core/BaseApiClient.ts
2
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
3
+ /**
4
+ * Flattens the Digisac `errors` object into `ValidationError[]` — one entry per message, with
5
+ * `path` = `<location>.<field>` (e.g. `body.name`) and `code` = the rule type (e.g. `required`).
6
+ * Returns `null` when the body carries no field errors.
7
+ */
8
+ function parseValidationErrors(errors) {
9
+ if (!isRecord(errors)) return null;
10
+ const parsed = [];
11
+ for (const [location, fields] of Object.entries(errors)) {
12
+ if (!isRecord(fields)) continue;
13
+ for (const [field, detail] of Object.entries(fields)) {
14
+ const messages = Array.isArray(detail?.messages) ? detail.messages.map(String) : [];
15
+ const types = Array.isArray(detail?.types) ? detail.types.map(String) : [];
16
+ messages.forEach((message, index) => {
17
+ parsed.push({
18
+ path: `${location}.${field}`,
19
+ message,
20
+ code: types[index] ?? types[0] ?? ""
21
+ });
22
+ });
23
+ }
24
+ }
25
+ return parsed.length ? parsed : null;
26
+ }
2
27
  var ApiError = class extends Error {
3
28
  errorClass;
4
29
  status;
@@ -47,7 +72,7 @@ var BaseApiClient = class {
47
72
  const errorData = JSON.parse(errorText);
48
73
  errorMessage = errorData.message || errorData.error || errorMessage;
49
74
  errorClass = errorData.error;
50
- validationErrors = errorData.validationErrors ?? null;
75
+ validationErrors = errorData.validationErrors ?? parseValidationErrors(errorData.errors);
51
76
  }
52
77
  } catch {}
53
78
  throw new ApiError(errorMessage, errorClass, response.status, validationErrors);
@@ -1 +1 @@
1
- {"version":3,"file":"BaseApiClient.mjs","names":[],"sources":["../../src/core/BaseApiClient.ts"],"sourcesContent":["import type { ApiClient, HttpMethod } from './ApiClient'\n\nexport interface ValidationError {\n path: string\n message: string\n code: string\n}\n\nexport class ApiError extends Error {\n public readonly errorClass?: string | undefined\n public readonly status?: number | undefined\n public readonly validationErrors: ValidationError[] | null\n\n constructor(\n message: string,\n errorClass?: string,\n status?: number,\n validationErrors: ValidationError[] | null = null,\n ) {\n super(message)\n this.name = 'ApiError'\n this.errorClass = errorClass\n this.status = status\n this.validationErrors = validationErrors\n }\n}\n\nexport class BaseApiClient implements ApiClient {\n protected readonly baseUrl: string\n protected accessToken: string | null = null\n\n constructor(baseUrl: string, accessToken?: string) {\n this.baseUrl = baseUrl.replace(/\\/$/, '')\n this.accessToken = accessToken || null\n }\n\n setAccessToken(accessToken: string): this {\n this.accessToken = accessToken\n return this\n }\n\n async request<TResponse = unknown, TBody = unknown>(\n method: HttpMethod,\n endpoint: string,\n body?: TBody,\n headers?: Record<string, string>,\n ): Promise<TResponse> {\n const url = `${this.baseUrl}/${endpoint.replace(/^\\//, '')}`\n\n const response = await fetch(url, {\n method,\n headers: {\n 'Content-Type': 'application/json',\n ...(this.accessToken && { Authorization: `Bearer ${this.accessToken}` }),\n ...headers,\n },\n ...(body !== undefined && { body: JSON.stringify(body) }),\n })\n\n return this.handleResponse<TResponse>(response)\n }\n\n protected async handleResponse<TResponse>(response: Response): Promise<TResponse> {\n if (!response.ok) {\n const contentType = response.headers.get('Content-Type')\n const isJson = contentType?.includes('application/json') ?? false\n\n let errorMessage = `HTTP Error ${response.status}: ${response.statusText}`\n let errorClass: string | undefined\n let validationErrors: ValidationError[] | null = null\n\n if (isJson) {\n try {\n const errorText = await response.text()\n if (errorText) {\n const errorData = JSON.parse(errorText)\n errorMessage = errorData.message || errorData.error || errorMessage\n errorClass = errorData.error\n validationErrors = errorData.validationErrors ?? null\n }\n } catch {\n // If JSON parsing fails, use the default error message\n }\n }\n\n throw new ApiError(errorMessage, errorClass, response.status, validationErrors)\n }\n\n // 204 No Content never has a body; short-circuit before reading the stream.\n if (response.status === 204) {\n return undefined as unknown as TResponse\n }\n\n // Read body as text once and treat an empty body as \"no content\" regardless of\n // Content-Type. Servers sometimes return 200 with Content-Type: application/json\n // and an empty body (e.g. POST endpoints whose framework keeps the default JSON\n // content-type even when nothing is written). `response.json()` would throw\n // \"Unexpected end of input\" in that case.\n const text = await response.text()\n if (!text) {\n return undefined as unknown as TResponse\n }\n\n const contentType = response.headers.get('Content-Type')\n const isJson = contentType?.includes('application/json') ?? false\n\n if (isJson) {\n return JSON.parse(text) as TResponse\n }\n\n try {\n return JSON.parse(text) as TResponse\n } catch {\n return text as unknown as TResponse\n }\n }\n\n get<TResponse = unknown>(endpoint: string, headers?: Record<string, string>): Promise<TResponse> {\n return this.request<TResponse>('GET', endpoint, undefined, headers)\n }\n\n post<TResponse = unknown, TBody = unknown>(\n endpoint: string,\n body?: TBody,\n headers?: Record<string, string>,\n ): Promise<TResponse> {\n return this.request<TResponse, TBody>('POST', endpoint, body, headers)\n }\n\n put<TResponse = unknown, TBody = unknown>(\n endpoint: string,\n body?: TBody,\n headers?: Record<string, string>,\n ): Promise<TResponse> {\n return this.request<TResponse, TBody>('PUT', endpoint, body, headers)\n }\n\n patch<TResponse = unknown, TBody = unknown>(\n endpoint: string,\n body?: TBody,\n headers?: Record<string, string>,\n ): Promise<TResponse> {\n return this.request<TResponse, TBody>('PATCH', endpoint, body, headers)\n }\n\n delete<TResponse = unknown>(\n endpoint: string,\n headers?: Record<string, string>,\n ): Promise<TResponse> {\n return this.request<TResponse>('DELETE', endpoint, undefined, headers)\n }\n}\n"],"mappings":";AAQA,IAAa,WAAb,cAA8B,MAAM;CAClC,AAAgB;CAChB,AAAgB;CAChB,AAAgB;CAEhB,YACE,SACA,YACA,QACA,mBAA6C,MAC7C;AACA,QAAM,QAAQ;AACd,OAAK,OAAO;AACZ,OAAK,aAAa;AAClB,OAAK,SAAS;AACd,OAAK,mBAAmB;;;AAI5B,IAAa,gBAAb,MAAgD;CAC9C,AAAmB;CACnB,AAAU,cAA6B;CAEvC,YAAY,SAAiB,aAAsB;AACjD,OAAK,UAAU,QAAQ,QAAQ,OAAO,GAAG;AACzC,OAAK,cAAc,eAAe;;CAGpC,eAAe,aAA2B;AACxC,OAAK,cAAc;AACnB,SAAO;;CAGT,MAAM,QACJ,QACA,UACA,MACA,SACoB;EACpB,MAAM,MAAM,GAAG,KAAK,QAAQ,GAAG,SAAS,QAAQ,OAAO,GAAG;EAE1D,MAAM,WAAW,MAAM,MAAM,KAAK;GAChC;GACA,SAAS;IACP,gBAAgB;IAChB,GAAI,KAAK,eAAe,EAAE,eAAe,UAAU,KAAK,eAAe;IACvE,GAAG;IACJ;GACD,GAAI,SAAS,UAAa,EAAE,MAAM,KAAK,UAAU,KAAK,EAAE;GACzD,CAAC;AAEF,SAAO,KAAK,eAA0B,SAAS;;CAGjD,MAAgB,eAA0B,UAAwC;AAChF,MAAI,CAAC,SAAS,IAAI;GAEhB,MAAM,SADc,SAAS,QAAQ,IAAI,eAAe,EAC5B,SAAS,mBAAmB,IAAI;GAE5D,IAAI,eAAe,cAAc,SAAS,OAAO,IAAI,SAAS;GAC9D,IAAI;GACJ,IAAI,mBAA6C;AAEjD,OAAI,OACF,KAAI;IACF,MAAM,YAAY,MAAM,SAAS,MAAM;AACvC,QAAI,WAAW;KACb,MAAM,YAAY,KAAK,MAAM,UAAU;AACvC,oBAAe,UAAU,WAAW,UAAU,SAAS;AACvD,kBAAa,UAAU;AACvB,wBAAmB,UAAU,oBAAoB;;WAE7C;AAKV,SAAM,IAAI,SAAS,cAAc,YAAY,SAAS,QAAQ,iBAAiB;;AAIjF,MAAI,SAAS,WAAW,IACtB;EAQF,MAAM,OAAO,MAAM,SAAS,MAAM;AAClC,MAAI,CAAC,KACH;AAMF,MAHoB,SAAS,QAAQ,IAAI,eAAe,EAC5B,SAAS,mBAAmB,IAAI,MAG1D,QAAO,KAAK,MAAM,KAAK;AAGzB,MAAI;AACF,UAAO,KAAK,MAAM,KAAK;UACjB;AACN,UAAO;;;CAIX,IAAyB,UAAkB,SAAsD;AAC/F,SAAO,KAAK,QAAmB,OAAO,UAAU,QAAW,QAAQ;;CAGrE,KACE,UACA,MACA,SACoB;AACpB,SAAO,KAAK,QAA0B,QAAQ,UAAU,MAAM,QAAQ;;CAGxE,IACE,UACA,MACA,SACoB;AACpB,SAAO,KAAK,QAA0B,OAAO,UAAU,MAAM,QAAQ;;CAGvE,MACE,UACA,MACA,SACoB;AACpB,SAAO,KAAK,QAA0B,SAAS,UAAU,MAAM,QAAQ;;CAGzE,OACE,UACA,SACoB;AACpB,SAAO,KAAK,QAAmB,UAAU,UAAU,QAAW,QAAQ"}
1
+ {"version":3,"file":"BaseApiClient.mjs","names":[],"sources":["../../src/core/BaseApiClient.ts"],"sourcesContent":["import type { ApiClient, HttpMethod } from './ApiClient'\n\nexport interface ValidationError {\n path: string\n message: string\n code: string\n}\n\n/**\n * Digisac field errors: `{ errors: { <location>: { <field>: { messages: string[], types: string[] } } } }`,\n * where location is `body`, `params`, `query`, `headers` or `cookies` (backend `validate` middleware).\n */\ntype DigisacFieldErrors = Record<string, Record<string, { messages?: unknown; types?: unknown }>>\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\n/**\n * Flattens the Digisac `errors` object into `ValidationError[]` — one entry per message, with\n * `path` = `<location>.<field>` (e.g. `body.name`) and `code` = the rule type (e.g. `required`).\n * Returns `null` when the body carries no field errors.\n */\nfunction parseValidationErrors(errors: unknown): ValidationError[] | null {\n if (!isRecord(errors)) {\n return null\n }\n\n const parsed: ValidationError[] = []\n for (const [location, fields] of Object.entries(errors as DigisacFieldErrors)) {\n if (!isRecord(fields)) {\n continue\n }\n for (const [field, detail] of Object.entries(fields)) {\n const messages = Array.isArray(detail?.messages) ? detail.messages.map(String) : []\n const types = Array.isArray(detail?.types) ? detail.types.map(String) : []\n messages.forEach((message, index) => {\n parsed.push({ path: `${location}.${field}`, message, code: types[index] ?? types[0] ?? '' })\n })\n }\n }\n\n return parsed.length ? parsed : null\n}\n\nexport class ApiError extends Error {\n public readonly errorClass?: string | undefined\n public readonly status?: number | undefined\n public readonly validationErrors: ValidationError[] | null\n\n constructor(\n message: string,\n errorClass?: string,\n status?: number,\n validationErrors: ValidationError[] | null = null,\n ) {\n super(message)\n this.name = 'ApiError'\n this.errorClass = errorClass\n this.status = status\n this.validationErrors = validationErrors\n }\n}\n\nexport class BaseApiClient implements ApiClient {\n protected readonly baseUrl: string\n protected accessToken: string | null = null\n\n constructor(baseUrl: string, accessToken?: string) {\n this.baseUrl = baseUrl.replace(/\\/$/, '')\n this.accessToken = accessToken || null\n }\n\n setAccessToken(accessToken: string): this {\n this.accessToken = accessToken\n return this\n }\n\n async request<TResponse = unknown, TBody = unknown>(\n method: HttpMethod,\n endpoint: string,\n body?: TBody,\n headers?: Record<string, string>,\n ): Promise<TResponse> {\n const url = `${this.baseUrl}/${endpoint.replace(/^\\//, '')}`\n\n const response = await fetch(url, {\n method,\n headers: {\n 'Content-Type': 'application/json',\n ...(this.accessToken && { Authorization: `Bearer ${this.accessToken}` }),\n ...headers,\n },\n ...(body !== undefined && { body: JSON.stringify(body) }),\n })\n\n return this.handleResponse<TResponse>(response)\n }\n\n protected async handleResponse<TResponse>(response: Response): Promise<TResponse> {\n if (!response.ok) {\n const contentType = response.headers.get('Content-Type')\n const isJson = contentType?.includes('application/json') ?? false\n\n let errorMessage = `HTTP Error ${response.status}: ${response.statusText}`\n let errorClass: string | undefined\n let validationErrors: ValidationError[] | null = null\n\n if (isJson) {\n try {\n const errorText = await response.text()\n if (errorText) {\n const errorData = JSON.parse(errorText)\n errorMessage = errorData.message || errorData.error || errorMessage\n errorClass = errorData.error\n validationErrors = errorData.validationErrors ?? parseValidationErrors(errorData.errors)\n }\n } catch {\n // If JSON parsing fails, use the default error message\n }\n }\n\n throw new ApiError(errorMessage, errorClass, response.status, validationErrors)\n }\n\n // 204 No Content never has a body; short-circuit before reading the stream.\n if (response.status === 204) {\n return undefined as unknown as TResponse\n }\n\n // Read body as text once and treat an empty body as \"no content\" regardless of\n // Content-Type. Servers sometimes return 200 with Content-Type: application/json\n // and an empty body (e.g. POST endpoints whose framework keeps the default JSON\n // content-type even when nothing is written). `response.json()` would throw\n // \"Unexpected end of input\" in that case.\n const text = await response.text()\n if (!text) {\n return undefined as unknown as TResponse\n }\n\n const contentType = response.headers.get('Content-Type')\n const isJson = contentType?.includes('application/json') ?? false\n\n if (isJson) {\n return JSON.parse(text) as TResponse\n }\n\n try {\n return JSON.parse(text) as TResponse\n } catch {\n return text as unknown as TResponse\n }\n }\n\n get<TResponse = unknown>(endpoint: string, headers?: Record<string, string>): Promise<TResponse> {\n return this.request<TResponse>('GET', endpoint, undefined, headers)\n }\n\n post<TResponse = unknown, TBody = unknown>(\n endpoint: string,\n body?: TBody,\n headers?: Record<string, string>,\n ): Promise<TResponse> {\n return this.request<TResponse, TBody>('POST', endpoint, body, headers)\n }\n\n put<TResponse = unknown, TBody = unknown>(\n endpoint: string,\n body?: TBody,\n headers?: Record<string, string>,\n ): Promise<TResponse> {\n return this.request<TResponse, TBody>('PUT', endpoint, body, headers)\n }\n\n patch<TResponse = unknown, TBody = unknown>(\n endpoint: string,\n body?: TBody,\n headers?: Record<string, string>,\n ): Promise<TResponse> {\n return this.request<TResponse, TBody>('PATCH', endpoint, body, headers)\n }\n\n delete<TResponse = unknown>(\n endpoint: string,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,IACE,UACA,MACA,SACoB;AACpB,SAAO,KAAK,QAA0B,OAAO,UAAU,MAAM,QAAQ;;CAGvE,MACE,UACA,MACA,SACoB;AACpB,SAAO,KAAK,QAA0B,SAAS,UAAU,MAAM,QAAQ;;CAGzE,OACE,UACA,SACoB;AACpB,SAAO,KAAK,QAAmB,UAAU,UAAU,QAAW,QAAQ"}
@@ -5,7 +5,7 @@ import type { Department, DepartmentRelationships } from '../apis/departments';
5
5
  import type { Message, MessageRelationships } from '../apis/messages';
6
6
  import type { Organization, OrganizationRelationships } from '../apis/organizations';
7
7
  import type { Person, PersonRelationships } from '../apis/people';
8
- import type { Pipeline, PipelineRelationships } from '../apis/pipeline';
8
+ import type { PipelineRecord } from '../apis/pipeline';
9
9
  import type { QuickReply, QuickReplyRelationships } from '../apis/quickReplies';
10
10
  import type { Role, RoleRelationships } from '../apis/roles';
11
11
  import type { Service, ServiceRelationships } from '../apis/services';
@@ -66,8 +66,8 @@ export interface WebhookEventPayloadMap {
66
66
  'campaign.created': Omit<Campaign, CampaignRelationships>;
67
67
  'campaign.updated': Omit<Campaign, CampaignRelationships>;
68
68
  'campaign.destroyed': Omit<Campaign, CampaignRelationships>;
69
- 'pipeline.created': Omit<Pipeline, PipelineRelationships>;
70
- 'pipeline.updated': Omit<Pipeline, PipelineRelationships>;
69
+ 'pipeline.created': PipelineRecord;
70
+ 'pipeline.updated': PipelineRecord;
71
71
  }
72
72
  export type WebhookPayload<E extends WebhookEvent = WebhookEvent> = {
73
73
  event: E;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/incommingWebhooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AACxE,OAAO,KAAK,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,C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isac-api-sdk",
3
- "version": "2.2.1",
3
+ "version": "3.1.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -0,0 +1,96 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest'
2
+ import { AcceptanceTermsApi } from './AcceptanceTermsApi'
3
+ import type { ApiClient } from '../../core/ApiClient'
4
+ import type {
5
+ AcceptanceTerm,
6
+ CreateAcceptanceTermPayload,
7
+ UpdateAcceptanceTermPayload,
8
+ } from './types'
9
+
10
+ // ── Mock client factory ──────────────────────────────────────────────
11
+
12
+ function createMockClient(): ApiClient {
13
+ return {
14
+ setAccessToken: vi.fn().mockReturnThis(),
15
+ request: vi.fn(),
16
+ get: vi.fn(),
17
+ post: vi.fn(),
18
+ put: vi.fn(),
19
+ patch: vi.fn(),
20
+ delete: vi.fn(),
21
+ }
22
+ }
23
+
24
+ // ── Fixtures ─────────────────────────────────────────────────────────
25
+
26
+ const term: AcceptanceTerm = {
27
+ id: 'at-1',
28
+ name: 'LGPD',
29
+ textField: 'Ao continuar, você concorda...',
30
+ accountId: 'acc-1',
31
+ fileId: null,
32
+ createdAt: '2024-01-01T00:00:00Z',
33
+ updatedAt: '2024-01-01T00:00:00Z',
34
+ deletedAt: null,
35
+ }
36
+
37
+ const upload = { base64: 'JVBERi0xLjQ=', name: 'termo.pdf', mimetype: 'application/pdf' }
38
+
39
+ // ── Tests ────────────────────────────────────────────────────────────
40
+
41
+ describe('AcceptanceTermsApi', () => {
42
+ let client: ReturnType<typeof createMockClient>
43
+ let api: AcceptanceTermsApi
44
+
45
+ beforeEach(() => {
46
+ client = createMockClient()
47
+ api = new AcceptanceTermsApi(client)
48
+ })
49
+
50
+ describe('create', () => {
51
+ it('sends the inline file upload in the body', async () => {
52
+ vi.mocked(client.post).mockResolvedValue({ ...term, fileId: 'file-1' })
53
+ const body: CreateAcceptanceTermPayload = { name: 'LGPD', textField: 'Texto', file: upload }
54
+ await api.create(body)
55
+ expect(client.post).toHaveBeenCalledWith('/acceptance-terms', body, undefined)
56
+ })
57
+
58
+ it('creates a term without attachment', async () => {
59
+ vi.mocked(client.post).mockResolvedValue(term)
60
+ const result = await api.create({ name: 'LGPD', textField: 'Texto' })
61
+ expect(client.post).toHaveBeenCalledWith(
62
+ '/acceptance-terms',
63
+ { name: 'LGPD', textField: 'Texto' },
64
+ undefined,
65
+ )
66
+ expect(result.fileId).toBeNull()
67
+ })
68
+ })
69
+
70
+ describe('updateById', () => {
71
+ it('sends a new file upload', async () => {
72
+ vi.mocked(client.put).mockResolvedValue(term)
73
+ const body: UpdateAcceptanceTermPayload = { name: 'LGPD v2', file: upload }
74
+ await api.updateById('at-1', body)
75
+ expect(client.put).toHaveBeenCalledWith('/acceptance-terms/at-1', body, undefined)
76
+ })
77
+
78
+ it('sends an empty file object to remove the attachment', async () => {
79
+ vi.mocked(client.put).mockResolvedValue(term)
80
+ const body: UpdateAcceptanceTermPayload = { name: 'LGPD', textField: 'Texto', file: {} }
81
+ await api.updateById('at-1', body)
82
+ expect(client.put).toHaveBeenCalledWith('/acceptance-terms/at-1', body, undefined)
83
+ })
84
+ })
85
+
86
+ describe('getById', () => {
87
+ it('includes the file relationship', async () => {
88
+ vi.mocked(client.get).mockResolvedValue({ ...term, file: null })
89
+ const result = await api.getById('at-1', { include: ['file'] })
90
+ const url = vi.mocked(client.get).mock.calls[0][0] as string
91
+ expect(url).toContain('/acceptance-terms/at-1?')
92
+ expect(url).toContain('include')
93
+ expect(result.file).toBeNull()
94
+ })
95
+ })
96
+ })
@@ -6,25 +6,42 @@ export type AcceptanceTerm = {
6
6
  name: string
7
7
  textField: string
8
8
  accountId: string
9
- fileId: string
9
+ /** `null` when the term has no attachment. */
10
+ fileId: string | null
10
11
  createdAt: string
11
12
  updatedAt: string
12
13
  deletedAt: string | null
13
14
  // relationships
14
15
  account?: Account
15
- file?: File
16
+ /** Present with `include: ['file']`; `null` when the term has no attachment. */
17
+ file?: File | null
16
18
  }
17
19
 
18
20
  export type AcceptanceTermRelationships = 'account' | 'file'
19
21
 
22
+ /** Attachment sent inline with the term. `base64` is the raw file content, without the data-URI prefix. */
23
+ export type AcceptanceTermFileUpload = {
24
+ base64: string
25
+ name: string
26
+ mimetype: string
27
+ }
28
+
20
29
  export type CreateAcceptanceTermPayload = {
21
30
  name: string
22
31
  fileId?: string
23
32
  textField?: string
33
+ /** Uploads and attaches a file to the new term. */
34
+ file?: AcceptanceTermFileUpload
24
35
  }
25
36
 
26
37
  export type UpdateAcceptanceTermPayload = {
27
38
  name?: string
28
39
  fileId?: string
29
40
  textField?: string
41
+ /**
42
+ * Replaces the attachment with a new upload, or removes it when `{}` is sent. Omitting `file`
43
+ * currently makes the backend persist the update and then answer 500 (SD-2285) — send `file`
44
+ * explicitly on every update.
45
+ */
46
+ file?: AcceptanceTermFileUpload | Record<string, never>
30
47
  }
@@ -131,6 +131,8 @@ export type AccountSettings = {
131
131
  timezone?: string
132
132
  /** Requires agents to select a topic when closing a ticket. */
133
133
  topicRequired?: boolean
134
+ /** Requires agents to fill in the summary when closing a ticket. */
135
+ summaryRequired?: boolean
134
136
  /** Enables visibility of tags in the chat interface. */
135
137
  showTagsInChat?: boolean
136
138
  /** Enables the ticket (SAC) functionality for the account. */
@@ -1,14 +1,79 @@
1
1
  import type { Contact } from '../contacts/types'
2
- import type { Pipeline } from '../pipeline/types'
2
+ import type {
3
+ Pipeline,
4
+ PipelineStage,
5
+ PipelineStageReason,
6
+ PipelineStageStatus,
7
+ } from '../pipeline/types'
3
8
  import type { User } from '../users/types'
4
9
 
10
+ type NamedRef = { id: string; name: string }
11
+
12
+ /** One entry of the card history — written on create and on every stage/status/owner change. */
13
+ export type CardMovement = {
14
+ id: string
15
+ cardId: string
16
+ accountId: string
17
+ /** The user who made the change (the requester), not the card owner. */
18
+ userId: string
19
+ pipelineId: string
20
+ fromPipelineId: string | null
21
+ toPipelineId: string | null
22
+ fromPipelineStageId: string | null
23
+ toPipelineStageId: string | null
24
+ fromStageStatusId: string | null
25
+ toStageStatusId: string | null
26
+ fromOwnerId: string | null
27
+ toOwnerId: string | null
28
+ createdAt: string
29
+ // relationships (GET /cards/{id})
30
+ user?: NamedRef | null
31
+ from_pipeline?: NamedRef | null
32
+ to_pipeline?: NamedRef | null
33
+ from_pipeline_stage?: NamedRef | null
34
+ to_pipeline_stage?: NamedRef | null
35
+ from_stage_status?: NamedRef | null
36
+ to_stage_status?: NamedRef | null
37
+ from_owner?: NamedRef | null
38
+ to_owner?: NamedRef | null
39
+ }
40
+
41
+ export type CardProduct = {
42
+ id: string
43
+ cardId: string
44
+ name: string
45
+ /** Quantity (the backend column is spelled `ammount`). */
46
+ ammount: number
47
+ value: number
48
+ createdAt: string
49
+ updatedAt: string
50
+ }
51
+
52
+ export type CardComment = {
53
+ id: string
54
+ cardId: string
55
+ userId: string | null
56
+ comment: string | null
57
+ createdAt: string
58
+ updatedAt: string
59
+ user?: User | null
60
+ files?: Record<string, unknown>[]
61
+ }
62
+
63
+ /**
64
+ * A sales funnel card (opportunity).
65
+ *
66
+ * `create` and `updateById` answer the raw entity (with `updatedAt`/`archivedAt`). `getMany` and
67
+ * `getById` go through the backend transformer: no `updatedAt`/`archivedAt`, plus `url`,
68
+ * `lastMessage` and `totalValue`; `getById` also joins the relationships below.
69
+ */
5
70
  export type Card = {
6
71
  id: string
7
72
  title: string
8
73
  description: string | null
74
+ /** Position in the stage — set by the backend to the number of cards already in it. */
9
75
  order: number | null
10
76
  isArchived: boolean
11
- archivedAt: string | null
12
77
  success: boolean | null
13
78
  finishedAt: string | null
14
79
  organization: string | null
@@ -23,41 +88,73 @@ export type Card = {
23
88
  reasonId: string | null
24
89
  ownerId: string | null
25
90
  createdAt: string
26
- updatedAt: string
91
+ /** Only on create/update answers. */
92
+ updatedAt?: string
93
+ /** Only on create/update answers. */
94
+ archivedAt?: string | null
95
+ /** Only on getMany/getById answers (contact avatar URL, or empty string). */
96
+ url?: unknown
97
+ /** Only on getMany/getById answers (contact last message, or empty string). */
98
+ lastMessage?: unknown
99
+ /** Only on getMany/getById answers: sum of the products (`ammount * value`). */
100
+ totalValue?: number
27
101
  // relationships
28
102
  contact?: Contact | null
29
103
  owner?: User | null
30
104
  pipeline?: Pipeline
105
+ pipeline_stage?: PipelineStage | null
106
+ stage_status?: PipelineStageStatus | null
107
+ stage_reason?: PipelineStageReason | null
108
+ movements?: CardMovement[]
109
+ products?: CardProduct[]
110
+ comments?: CardComment[]
31
111
  }
32
112
 
33
- export type CardRelationships = 'contact' | 'owner' | 'pipeline'
113
+ export type CardRelationships =
114
+ | 'contact'
115
+ | 'owner'
116
+ | 'pipeline'
117
+ | 'pipeline_stage'
118
+ | 'stage_status'
119
+ | 'stage_reason'
120
+ | 'movements'
121
+ | 'products'
122
+ | 'comments'
34
123
 
35
124
  export type CreateCardPayload = {
125
+ /** Up to 255 characters. */
36
126
  title: string
37
127
  pipelineId: string
38
- contactId?: string
39
- pipelineStageId?: string
128
+ contactId: string
129
+ /** Must be a stage of `pipelineId`. */
130
+ pipelineStageId: string
40
131
  description?: string
132
+ ownerId?: string
133
+ statusId?: string
134
+ reasonId?: string
41
135
  organization?: string
42
136
  organizationSegment?: string
43
137
  originChannel?: string
44
138
  originCampaign?: string
45
- ownerId?: string
46
139
  }
47
140
 
48
141
  export type UpdateCardPayload = {
49
142
  title?: string
50
143
  description?: string | null
51
144
  contactId?: string | null
145
+ /** Moves the card to another pipeline (send the target `pipelineStageId` along). */
146
+ pipelineId?: string
52
147
  pipelineStageId?: string | null
53
148
  statusId?: string | null
54
149
  reasonId?: string | null
55
150
  ownerId?: string | null
151
+ order?: number
56
152
  organization?: string | null
57
153
  organizationSegment?: string | null
58
154
  originChannel?: string | null
59
155
  originCampaign?: string | null
60
156
  isArchived?: boolean
157
+ /** Marks the card as won (`true`) or lost (`false`); the backend fills `finishedAt`. */
61
158
  success?: boolean | null
62
159
  finishedAt?: string | null
63
160
  }
@@ -1,6 +1,50 @@
1
1
  import type { Department } from '../departments/types'
2
2
 
3
- export type Pipeline = {
3
+ export type PipelineStageStatus = {
4
+ id: string
5
+ /** The default "Finalizados" stage carries `STATUS_WON` and `STATUS_LOOSE`. */
6
+ name: string
7
+ position: number
8
+ pipelineId: string
9
+ stageId: string
10
+ accountId: string
11
+ createdAt: string
12
+ updatedAt: string
13
+ deletedAt: string | null
14
+ }
15
+
16
+ export type PipelineStageReason = {
17
+ id: string
18
+ name: string
19
+ position: number
20
+ isWon: boolean
21
+ pipelineId: string
22
+ stageId: string
23
+ accountId: string
24
+ createdAt: string
25
+ updatedAt: string
26
+ }
27
+
28
+ export type PipelineStage = {
29
+ id: string
30
+ name: string
31
+ position: number
32
+ pipelineId: string
33
+ accountId: string
34
+ createdAt: string
35
+ updatedAt: string
36
+ deletedAt: string | null
37
+ statuses?: PipelineStageStatus[]
38
+ reasons?: PipelineStageReason[]
39
+ /** Card totals — present on create/update/getById, absent on the listing `include`. */
40
+ totalCards?: number
41
+ totalCardsValue?: number
42
+ totalWonCardsValue?: number
43
+ totalLostCardsValue?: number
44
+ }
45
+
46
+ /** The pipeline row as stored — what the webhook events (`pipeline.created`/`.updated`) carry. */
47
+ export type PipelineRecord = {
4
48
  id: string
5
49
  name: string
6
50
  goBack: boolean
@@ -10,20 +54,44 @@ export type Pipeline = {
10
54
  createdAt: string
11
55
  updatedAt: string
12
56
  deletedAt: string | null
57
+ }
58
+
59
+ /**
60
+ * A sales funnel pipeline.
61
+ *
62
+ * `create`, `updateById` and `getById` answer the full entity, always with `stages`. The listing
63
+ * (`getMany`) goes through the backend transformer and only carries `id`, `name`, `goBack` and
64
+ * `archivedAt` (plus the included relationships) — hence the optional fields below.
65
+ */
66
+ export type Pipeline = {
67
+ id: string
68
+ name: string
69
+ goBack: boolean
70
+ archivedAt: string | null
71
+ accountId?: string
72
+ permissionToViewCard?: boolean | null
73
+ createdAt?: string
74
+ updatedAt?: string
75
+ deletedAt?: string | null
13
76
  // relationships
77
+ stages?: PipelineStage[]
14
78
  departments?: Department[]
15
79
  }
16
80
 
17
- export type PipelineRelationships = 'departments'
81
+ export type PipelineRelationships = 'departments' | 'stages'
18
82
 
19
83
  export type CreatePipelinePayload = {
84
+ /** Up to 100 characters; must be unique in the account. */
20
85
  name: string
86
+ /** `false` = only move forward, `true` = move forward and backward. */
21
87
  goBack?: boolean
88
+ /** When `true`, non-admin users only see the cards they own. */
22
89
  permissionToViewCard?: boolean
23
90
  }
24
91
 
25
92
  export type UpdatePipelinePayload = {
26
- name?: string
93
+ /** Required by the backend on every update (400 `required` otherwise). */
94
+ name: string
27
95
  goBack?: boolean
28
96
  permissionToViewCard?: boolean | null
29
97
  }