sgp-sdk 1.2.0 → 2.0.0-beta.2

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 (100) hide show
  1. package/CHANGELOG.md +234 -0
  2. package/COMPATIBILITY.md +231 -0
  3. package/MIGRATION.md +344 -0
  4. package/README.md +464 -265
  5. package/dist/address.d.ts +46 -0
  6. package/dist/annotation-selection.d.ts +32 -0
  7. package/dist/budget.d.ts +29 -0
  8. package/dist/classify.d.ts +15 -0
  9. package/dist/client.d.ts +938 -165
  10. package/dist/config.d.ts +115 -0
  11. package/dist/constants.d.ts +85 -0
  12. package/dist/document.d.ts +11 -0
  13. package/dist/effect.d.ts +22 -0
  14. package/dist/executor.d.ts +9 -0
  15. package/dist/exposure.d.ts +21 -0
  16. package/dist/guards.d.ts +2 -0
  17. package/dist/hooks.d.ts +16 -0
  18. package/dist/ids.d.ts +19 -0
  19. package/dist/index.d.ts +55 -49
  20. package/dist/index.js +3750 -1293
  21. package/dist/normalize.d.ts +9 -0
  22. package/dist/operation-sensitivity.d.ts +729 -0
  23. package/dist/operation.d.ts +145 -0
  24. package/dist/operations/catalogs-list-billing-profiles.d.ts +16 -0
  25. package/dist/operations/catalogs-list-nas.d.ts +25 -0
  26. package/dist/operations/catalogs-list-pops.d.ts +14 -0
  27. package/dist/operations/contracts-check-connection.d.ts +56 -0
  28. package/dist/operations/contracts-list-services.d.ts +103 -0
  29. package/dist/operations/contracts-list-status-reasons.d.ts +15 -0
  30. package/dist/operations/contracts-list.d.ts +52 -0
  31. package/dist/operations/contracts-update-status.d.ts +41 -0
  32. package/dist/operations/contracts-update.d.ts +39 -0
  33. package/dist/operations/coverage-check-address.d.ts +46 -0
  34. package/dist/operations/coverage-check.d.ts +43 -0
  35. package/dist/operations/coverage-list-gateways.d.ts +16 -0
  36. package/dist/operations/crm-contracts-create-by-cpf-cnpj.d.ts +97 -0
  37. package/dist/operations/crm-contracts-create.d.ts +221 -0
  38. package/dist/operations/crm-contracts-list.d.ts +50 -0
  39. package/dist/operations/crm-customers-create.d.ts +165 -0
  40. package/dist/operations/crm-customers-update-status.d.ts +41 -0
  41. package/dist/operations/customers-list.d.ts +104 -0
  42. package/dist/{endpoints/ura/lookup-customer.d.ts → operations/customers-search.d.ts} +56 -46
  43. package/dist/operations/documents-add.d.ts +29 -0
  44. package/dist/operations/documents-list.d.ts +31 -0
  45. package/dist/operations/experimental-annotations-list.d.ts +67 -0
  46. package/dist/operations/invoices-list.d.ts +148 -0
  47. package/dist/operations/maintenance-list.d.ts +35 -0
  48. package/dist/operations/occurrences-create.d.ts +125 -0
  49. package/dist/operations/occurrences-list-methods.d.ts +14 -0
  50. package/dist/operations/occurrences-list-types.d.ts +20 -0
  51. package/dist/operations/occurrences-list.d.ts +127 -0
  52. package/dist/{endpoints/ura/list-plans.d.ts → operations/plans-list.d.ts} +33 -23
  53. package/dist/operations/pre-registrations-create.d.ts +276 -0
  54. package/dist/operations/pre-registrations-list-due-days.d.ts +15 -0
  55. package/dist/operations/pre-registrations-list-plans.d.ts +24 -0
  56. package/dist/operations/pre-registrations-list-sellers.d.ts +16 -0
  57. package/dist/operations/services-add-generic.d.ts +52 -0
  58. package/dist/operations/services-add-tv.d.ts +47 -0
  59. package/dist/operations/services-change-plan.d.ts +40 -0
  60. package/dist/operations/services-remove-generic.d.ts +28 -0
  61. package/dist/operations/services-remove-tv.d.ts +29 -0
  62. package/dist/operations/work-orders-get.d.ts +99 -0
  63. package/dist/operations/work-orders-list-comments.d.ts +34 -0
  64. package/dist/operations/work-orders-list-reasons.d.ts +20 -0
  65. package/dist/operations/work-orders-list.d.ts +81 -0
  66. package/dist/path.d.ts +13 -0
  67. package/dist/raw-request.d.ts +26 -0
  68. package/dist/request.d.ts +28 -0
  69. package/dist/result.d.ts +113 -41
  70. package/dist/retry.d.ts +34 -0
  71. package/dist/sensitivity.d.ts +89 -4
  72. package/dist/tolerant.d.ts +21 -0
  73. package/dist/validation.d.ts +3 -0
  74. package/package.json +6 -3
  75. package/dist/endpoint.d.ts +0 -66
  76. package/dist/endpoints/crm/address.d.ts +0 -20
  77. package/dist/endpoints/crm/create-contract.d.ts +0 -109
  78. package/dist/endpoints/crm/create-customer.d.ts +0 -65
  79. package/dist/endpoints/crm/update-customer-status.d.ts +0 -43
  80. package/dist/endpoints/os/list-occurrence-reasons.d.ts +0 -24
  81. package/dist/endpoints/os/list-occurrence-types.d.ts +0 -25
  82. package/dist/endpoints/precadastro/list-due-days.d.ts +0 -19
  83. package/dist/endpoints/precadastro/list-sellers.d.ts +0 -21
  84. package/dist/endpoints/suporte/add-customer-document.d.ts +0 -24
  85. package/dist/endpoints/suporte/list-customer-documents.d.ts +0 -25
  86. package/dist/endpoints/ura/check-coverage.d.ts +0 -46
  87. package/dist/endpoints/ura/list-annotations.d.ts +0 -32
  88. package/dist/endpoints/ura/list-clients.d.ts +0 -58
  89. package/dist/endpoints/ura/list-contracts.d.ts +0 -45
  90. package/dist/endpoints/ura/list-invoices.d.ts +0 -107
  91. package/dist/endpoints/ura/list-nas.d.ts +0 -29
  92. package/dist/endpoints/ura/list-occurrence-methods.d.ts +0 -19
  93. package/dist/endpoints/ura/list-payment-carriers.d.ts +0 -20
  94. package/dist/endpoints/ura/list-pops.d.ts +0 -19
  95. package/dist/endpoints/ura/list-service-orders.d.ts +0 -64
  96. package/dist/endpoints/ura/open-ticket.d.ts +0 -81
  97. package/dist/errors.d.ts +0 -59
  98. package/dist/schema/parse.d.ts +0 -19
  99. package/dist/schema/paths.d.ts +0 -38
  100. package/dist/transport.d.ts +0 -65
@@ -1,64 +0,0 @@
1
- import { z } from "zod";
2
- import type { EndpointDefinition } from "../../endpoint.js";
3
- /** Response of `POST /api/ura/ordemservico/list/`: one page of service orders (OS). */
4
- export declare const listServiceOrdersSchema: z.ZodObject<{
5
- paginacao: z.ZodObject<{
6
- offset: z.ZodNullable<z.ZodOptional<z.ZodNumber>>;
7
- limit: z.ZodNullable<z.ZodOptional<z.ZodNumber>>;
8
- parcial: z.ZodNullable<z.ZodOptional<z.ZodNumber>>;
9
- total: z.ZodNumber;
10
- }, z.core.$strip>;
11
- ordens_servicos: z.ZodArray<z.ZodObject<{
12
- id: z.ZodNumber;
13
- contrato: z.ZodNumber;
14
- status_id: z.ZodNumber;
15
- status: z.ZodString;
16
- tipo_id: z.ZodNumber;
17
- data_cadastro: z.ZodString;
18
- cliente: z.ZodNullable<z.ZodOptional<z.ZodString>>;
19
- contrato_status: z.ZodNullable<z.ZodOptional<z.ZodString>>;
20
- contrato_status_id: z.ZodNullable<z.ZodOptional<z.ZodNumber>>;
21
- ocorrencia: z.ZodNullable<z.ZodOptional<z.ZodString>>;
22
- hora_cadastro: z.ZodNullable<z.ZodOptional<z.ZodString>>;
23
- data_agendamento: z.ZodNullable<z.ZodOptional<z.ZodString>>;
24
- hora_agendamento: z.ZodNullable<z.ZodOptional<z.ZodString>>;
25
- data_finalizacao: z.ZodNullable<z.ZodOptional<z.ZodString>>;
26
- hora_finalizacao: z.ZodNullable<z.ZodOptional<z.ZodString>>;
27
- tipo: z.ZodNullable<z.ZodOptional<z.ZodString>>;
28
- motivo: z.ZodNullable<z.ZodOptional<z.ZodString>>;
29
- pop: z.ZodNullable<z.ZodOptional<z.ZodString>>;
30
- conteudo: z.ZodNullable<z.ZodOptional<z.ZodString>>;
31
- responsavel: z.ZodNullable<z.ZodOptional<z.ZodString>>;
32
- tecnicos_auxiliares: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodObject<{}, z.core.$strip>>>>;
33
- usuario: z.ZodNullable<z.ZodOptional<z.ZodString>>;
34
- usuario_finalizacao: z.ZodNullable<z.ZodOptional<z.ZodString>>;
35
- classificacoes: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodObject<{}, z.core.$strip>>>>;
36
- }, z.core.$strip>>;
37
- }, z.core.$strip>;
38
- /** Key fields of `ura/ordemservico/list`: required and strict; any mismatch is `SCHEMA_MISMATCH`. */
39
- export declare const listServiceOrdersKeyFields: readonly ["paginacao.total", "ordens_servicos", "ordens_servicos[].id", "ordens_servicos[].contrato", "ordens_servicos[].status_id", "ordens_servicos[].status", "ordens_servicos[].tipo_id", "ordens_servicos[].data_cadastro"];
40
- /** Normalized path of each service order in the `ura/ordemservico/list` response. */
41
- export declare const serviceOrderItemPath = "ordens_servicos[]";
42
- /** Keys of a service order holding secrets (none in `ura/ordemservico/list`). */
43
- export declare const serviceOrderSecretKeys: readonly [];
44
- /** Keys of a service order holding personal data: customer name and the free-text content. */
45
- export declare const serviceOrderPersonalKeys: readonly ["cliente", "conteudo"];
46
- /** Body parameters of `POST /api/ura/ordemservico/list/` (besides credentials); all optional filters and paging. */
47
- export interface ListServiceOrdersParams {
48
- offset?: number;
49
- limit?: number;
50
- /** ID of the occurrence (the OS). */
51
- ordem_servico?: number;
52
- /** Service order status ID. */
53
- status?: number;
54
- /** POP ID. */
55
- pop?: number;
56
- /** Occurrence reason ID. */
57
- motivo?: number;
58
- /** Contract ID. */
59
- contrato?: number;
60
- }
61
- /** Parsed response of `POST /api/ura/ordemservico/list/`. */
62
- export type ListServiceOrdersResponse = z.output<typeof listServiceOrdersSchema>;
63
- /** Definition of `POST /api/ura/ordemservico/list/`. */
64
- export declare const listServiceOrdersDefinition: EndpointDefinition<typeof listServiceOrdersSchema>;
@@ -1,81 +0,0 @@
1
- import { z } from "zod";
2
- import type { WriteEndpointDefinition } from "../../endpoint.js";
3
- /**
4
- * Success body of `POST /api/ura/chamado/`: `status` 1, the ticket protocol and the ID of the
5
- * occurrence, plus the contract and customer SGP echoes back. `status` 0 is SGP's refusal.
6
- */
7
- export declare const openTicketSchema: z.ZodObject<{
8
- status: z.ZodLiteral<1>;
9
- protocolo: z.ZodString;
10
- id: z.ZodNumber;
11
- contratoId: z.ZodNullable<z.ZodOptional<z.ZodNumber>>;
12
- razaoSocial: z.ZodNullable<z.ZodOptional<z.ZodString>>;
13
- cpfCnpj: z.ZodNullable<z.ZodOptional<z.ZodString>>;
14
- msg: z.ZodNullable<z.ZodOptional<z.ZodString>>;
15
- }, z.core.$strip>;
16
- /**
17
- * Key fields of `ura/chamado`: required and strict. A 2xx is only a success with `status` 1 and a
18
- * `protocolo`; anything else (e.g. `status` 0 with a `msg`) is `VALIDATION` with `outcome: "unknown"`.
19
- */
20
- export declare const openTicketKeyFields: readonly ["status", "protocolo", "id"];
21
- /** Normalized path of the opened ticket in the response (the root object). */
22
- export declare const ticketOpenedItemPath = "";
23
- /** Keys of the response holding secrets (none in `ura/chamado`). */
24
- export declare const ticketOpenedSecretKeys: readonly [];
25
- /** Keys of the response holding personal data: the customer's name and CPF/CNPJ. */
26
- export declare const ticketOpenedPersonalKeys: readonly ["razaoSocial", "cpfCnpj"];
27
- /** Parsed response of `POST /api/ura/chamado/`. */
28
- export type OpenTicketResponse = z.output<typeof openTicketSchema>;
29
- /**
30
- * Params of `POST /api/ura/chamado/`; only `contrato` is required. `contato_nome` and
31
- * `contato_telefone` are personal data.
32
- */
33
- export interface OpenTicketParams {
34
- /** Contract ID. */
35
- contrato: number;
36
- /** Content of the occurrence and the service order. */
37
- conteudo?: string;
38
- /** 1 removes SGP's default opening message ("via URA"). */
39
- conteudolimpo?: 0 | 1;
40
- observacao?: string;
41
- /** Occurrence type code (SGP's default is 5). */
42
- ocorrenciatipo?: number;
43
- /** Classification IDs linked to the occurrence. */
44
- tipoclassificacoes?: number[];
45
- /** Occurrence method code (see `ura.listOccurrenceMethods`). */
46
- metodo?: number;
47
- /** Sector ID. */
48
- setor?: number;
49
- /** Username shown as who opened the occurrence. */
50
- usuario?: string;
51
- /** Username of the occurrence's responsible. */
52
- responsaveloc?: string;
53
- contato_nome?: string;
54
- contato_telefone?: string;
55
- /** 1 does not open a service order. */
56
- desativa_os?: 0 | 1;
57
- /** 1 creates the occurrence and the service order already closed. */
58
- status_encerrado?: 0 | 1;
59
- /** 1 notifies the customer of the closing, when created already closed. */
60
- notificar_cliente?: 0 | 1;
61
- /** Service order reason code; each SGP instance has its own (see `os.listOccurrenceReasons`). */
62
- motivoos?: number;
63
- /** Classification IDs linked to the service order. */
64
- motivoclassificacoes?: number[];
65
- /** Username of the service order's responsible technician. */
66
- responsavel?: string;
67
- /** Usernames of the auxiliary technicians. */
68
- tecnicos?: string[];
69
- /** Schedules the occurrence and the service order: `"AAAA-MM-DD HH:MM"`. */
70
- data_hora_agendamento?: string;
71
- /** 1 warns the responsible technician of the new service order; needs `data_hora_agendamento` and a messaging gateway in SGP. */
72
- sms_tecnico?: 0 | 1;
73
- /** With `servico_id`, links a specific contract service to the occurrence. */
74
- tipo_servico?: "internet" | "telefonia" | "tv" | "multimidia" | "generico";
75
- /** ID of the contract's service; use with `tipo_servico`. */
76
- servico_id?: number;
77
- /** ID of the company to link. */
78
- empresa_id?: number;
79
- }
80
- /** Definition of `POST /api/ura/chamado/` (trailing slash required by the token whitelist). */
81
- export declare const openTicketDefinition: WriteEndpointDefinition<typeof openTicketSchema>;
package/dist/errors.d.ts DELETED
@@ -1,59 +0,0 @@
1
- import type { SgpError, SgpErrorCode, SgpWriteError } from "./result.js";
2
- /** SGP `detail` for 401/403 caused by wrong token/app credentials. */
3
- export declare const DETAIL_UNAUTHORIZED = "Credenciais de autentica\u00E7\u00E3o incorretas.";
4
- /** SGP `detail` for 401/403 when the app has no permission for the route (credentials "not provided"). */
5
- export declare const DETAIL_ROUTE_NOT_ALLOWED = "As credenciais de autentica\u00E7\u00E3o n\u00E3o foram fornecidas.";
6
- /** `message` of a write whose 2xx answer does not confirm it: the write may have been applied. */
7
- export declare const MESSAGE_WRITE_NOT_CONFIRMED = "SGP answered with a success status but the response does not confirm the write; it may have been applied.";
8
- /** `message` of a write SGP answered with its generic exception wrapper (a 4xx `errors` list): it may have been applied. */
9
- export declare const MESSAGE_WRITE_FAILED_GENERICALLY = "SGP reported an error while processing the write; it may have been applied.";
10
- /** `message` of a request the SDK refused before sending it (nothing left the process). */
11
- export declare const MESSAGE_REJECTED_LOCALLY = "The SDK rejected the request before sending it.";
12
- /**
13
- * Reads the SGP error text from a response body: a string `detail`, else a non-empty string `msg`,
14
- * else `errors`, else a non-empty string `error` (see {@link mapHttpFailure}). `undefined` when the
15
- * body carries none.
16
- */
17
- export declare const readSgpDetail: (body: unknown) => string | undefined;
18
- /**
19
- * Whether the body is SGP's generic exception wrapper: `errors` is an array (e.g.
20
- * `{"errors":["Ocorreu um erro: ..."]}`), as opposed to an object of field messages.
21
- */
22
- export declare const hasErrorList: (body: unknown) => boolean;
23
- /**
24
- * Builds a normalized error with the SDK-authored message for `code`, or with `message` when given.
25
- *
26
- * The `detail` key is omitted when `detail` is undefined.
27
- */
28
- export declare const createError: (code: SgpErrorCode, status: number, endpoint: string, detail?: string, message?: string) => SgpError;
29
- /**
30
- * Maps a non-2xx SGP response to a normalized error.
31
- *
32
- * `detail` is read from the first of these that yields text: a string `detail` (SGP's DRF message),
33
- * a non-empty string `msg` (e.g. `{"msg":"Informe um Raio válido."}`), then `errors` (the CRM format):
34
- * an array of strings joined by `"; "`, or an object of string values as `"key: value"` joined by
35
- * `"; "` in key order. Non-string items and values are ignored. Last, a non-empty string `error`
36
- * (e.g. `{"error":"Cadastro não encontrado"}`, a 404 on CRM routes). A body with none of these
37
- * leaves `detail` undefined. The raw body is never retained.
38
- */
39
- export declare const mapHttpFailure: (status: number, body: unknown, endpoint: string) => SgpError;
40
- /**
41
- * Maps an exception thrown by `fetch` to a normalized error (status 0).
42
- *
43
- * `TimeoutError` and `AbortError` become `TIMEOUT`; anything else becomes `NETWORK`.
44
- * The cause's message is never copied, since it can embed the request URL with credentials.
45
- */
46
- export declare const mapFetchFailure: (cause: unknown, endpoint: string) => SgpError;
47
- /**
48
- * Tags a failed write with whether SGP applied it: `"not_applied"` for a 4xx (SGP rejected the
49
- * request) and for a `VALIDATION` with status 0 (rejected locally, nothing was sent), `"unknown"`
50
- * for anything else (timeout/network, 5xx, 2xx that failed validation, 1xx/3xx).
51
- *
52
- * `isErrorListBody` (the {@link hasErrorList} result for the response body) marks a 4xx body that is
53
- * SGP's generic exception wrapper: SGP may have failed after applying part of the write, so that 4xx
54
- * is `"unknown"` too and carries {@link MESSAGE_WRITE_FAILED_GENERICALLY} as its `message`, except
55
- * 401/403/404/405/422, which stay `"not_applied"`. Omit it when the body is not known.
56
- *
57
- * Returns a new object; the input is not mutated.
58
- */
59
- export declare const toWriteError: (error: SgpError, isErrorListBody?: boolean) => SgpWriteError;
@@ -1,19 +0,0 @@
1
- import type { z } from "zod";
2
- import type { SgpResult } from "../result.js";
3
- /**
4
- * Validates an SGP response body, tolerating type drift in non-key fields.
5
- *
6
- * 1. Parses with `schema` (unknown keys are stripped at every level). Success → `data`.
7
- * 2. Otherwise picks, per issue, the property to remove: the property the issue points at or, when
8
- * the issue sits on an array element, the nearest enclosing object property (the whole array
9
- * field, e.g. `clientes[0].contatos.telefones`). If none exists, or it is a key field or an
10
- * ancestor of one (`keyFields`, normalized paths like `clientes[].id`) → `SCHEMA_MISMATCH`.
11
- * That property is the issue's own path or a prefix of it, so every issue on a key field or on
12
- * an ancestor of one ends here.
13
- * 3. Removes those properties from a clone of `input` and parses exactly once more. Success →
14
- * `data` plus one `SchemaWarning` per issue, with the precise issue location
15
- * (e.g. `clientes[0].contatos.telefones[0]`) and type names only. Failure → `SCHEMA_MISMATCH`.
16
- *
17
- * `SCHEMA_MISMATCH.detail` lists the failing normalized paths (`(root)` for the body itself), never values.
18
- */
19
- export declare const parseResponse: <S extends z.ZodType>(schema: S, keyFields: readonly string[], input: unknown, endpoint: string) => SgpResult<z.output<S>>;
@@ -1,38 +0,0 @@
1
- /**
2
- * Joins a Zod issue path with array indices collapsed to `[]`, the form used by `keyFields`.
3
- *
4
- * `["contratos", 0, "contratoId"]` → `"contratos[].contratoId"`; `[0, "id"]` → `"[].id"`; `[]` → `""`.
5
- */
6
- export declare const normalizePath: (path: ReadonlyArray<PropertyKey>) => string;
7
- /**
8
- * Joins a Zod issue path keeping the real array indices, the form used in `SchemaWarning.path`.
9
- *
10
- * `["clientes", 0, "sexo"]` → `"clientes[0].sexo"`.
11
- */
12
- export declare const formatPath: (path: ReadonlyArray<PropertyKey>) => string;
13
- /**
14
- * Tells whether a raw Zod issue path is a key field or an ancestor of one.
15
- *
16
- * Segments are compared as they are, never joined into a string, so a data-defined property name
17
- * holding `.`, `[` or `]` stays one segment. The root (`[]`) is an ancestor of every key.
18
- * A numeric segment matches only a `[]` key segment. A string segment matches a `*` key segment
19
- * (any name, the empty one included) or an equal name, never `[]`: `["[].*"]` covers `[0, "Geogrid"]`
20
- * and `[0, "Geo.grid"]` (data-defined names), but not what sits below them.
21
- */
22
- export declare const isKeyPathOf: (path: ReadonlyArray<PropertyKey>, keyFields: readonly string[]) => boolean;
23
- /**
24
- * Tells whether a normalized path is a key field or an ancestor of one.
25
- *
26
- * The root (`""`) is an ancestor of every key. `"cliente"` is not an ancestor of `"clientes[].id"`.
27
- * A `*` segment in a key matches exactly one property name, never an array index: `"[].*"` covers
28
- * `"[].SGPMaps"` and `"[].Geogrid"` (data-defined names), but not what sits below them.
29
- */
30
- export declare const isKeyPath: (path: string, keyFields: readonly string[]) => boolean;
31
- /** Reads the value at `path`, or `undefined` when any step is missing or not indexable. */
32
- export declare const valueAt: (input: unknown, path: ReadonlyArray<PropertyKey>) => unknown;
33
- /**
34
- * Names the type of the value at `path`; never returns the value itself.
35
- *
36
- * One of `"string" | "number" | "boolean" | "null" | "undefined" | "array" | "object"` for JSON input.
37
- */
38
- export declare const typeNameAt: (input: unknown, path: ReadonlyArray<PropertyKey>) => string;
@@ -1,65 +0,0 @@
1
- import type { SgpError } from "./result.js";
2
- /** Default request timeout in milliseconds. */
3
- export declare const DEFAULT_TIMEOUT_MS = 20000;
4
- /** Connection settings shared by every SDK method. */
5
- export interface SgpClientConfig {
6
- baseUrl: string;
7
- token: string;
8
- app: string;
9
- /** Request timeout in milliseconds. Defaults to {@link DEFAULT_TIMEOUT_MS}. */
10
- timeoutMs?: number;
11
- /** Custom `fetch`, mainly for tests. Defaults to the global `fetch`. */
12
- fetch?: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
13
- }
14
- /**
15
- * A request parameter value. Arrays and objects are only valid on POST/PUT; `undefined` object keys
16
- * are omitted at any depth.
17
- */
18
- export type ParamValue = string | number | boolean | null | readonly ParamValue[] | {
19
- readonly [key: string]: ParamValue | undefined;
20
- };
21
- /** A file sent as one part of a multipart request. */
22
- export interface SgpFile {
23
- data: Blob | Uint8Array | ArrayBuffer;
24
- filename: string;
25
- /** MIME type of the part. Defaults to the `type` of a `Blob`; none for bytes. */
26
- contentType?: string;
27
- }
28
- /**
29
- * One SGP request; `path` starts with `/` and may hold `{name}` placeholders filled from
30
- * `pathParams`. `params` with `undefined` values are dropped. POST/PUT with `files` is sent as
31
- * multipart; otherwise as JSON.
32
- */
33
- export interface RequestSpec {
34
- method: "GET" | "POST" | "PUT";
35
- path: string;
36
- pathParams?: Record<string, string | number>;
37
- params?: Record<string, ParamValue | undefined>;
38
- files?: Record<string, SgpFile>;
39
- }
40
- /**
41
- * Parsed JSON body of a 2xx response with its HTTP status, or the normalized failure.
42
- * `hasErrorList` is set on a non-2xx answer: its JSON body is SGP's generic exception wrapper
43
- * (`errors` is an array). The body itself is never kept.
44
- */
45
- export type RawResponse = {
46
- ok: true;
47
- body: unknown;
48
- status: number;
49
- } | {
50
- ok: false;
51
- error: SgpError;
52
- hasErrorList?: boolean;
53
- };
54
- /**
55
- * Sends one request to SGP and returns the parsed JSON body or a normalized error.
56
- *
57
- * GET sends `token` and `app` in the query string and only accepts primitive params; POST/PUT send
58
- * them in a JSON body, or as multipart fields when `files` is set. A 2xx response with an empty
59
- * body yields `body: null`. The success result carries the real 2xx `status`. Redirects are never
60
- * followed (`redirect: "manual"`): a 3xx comes back as an `UNKNOWN` error with its status.
61
- * Never throws: invalid path params or structured GET params (`VALIDATION`, status 0, no request
62
- * sent), network failures, timeouts, non-2xx statuses and non-JSON 2xx bodies all come back as
63
- * `{ ok: false, error }`, where `error.endpoint` is `spec.path` (the template) only.
64
- */
65
- export declare const sendRequest: (config: SgpClientConfig, spec: RequestSpec) => Promise<RawResponse>;