@greensecurity/javascript-sdk 0.16.0 → 0.18.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 (169) hide show
  1. package/REACT_QUERY.md +68 -30
  2. package/README.md +43 -0
  3. package/bin/mcp-server.js +731 -52
  4. package/bin/mcp-server.js.map +29 -19
  5. package/funcs/organizationsListOrSearchFacilities.d.ts +4 -1
  6. package/funcs/organizationsListOrSearchFacilities.d.ts.map +1 -1
  7. package/funcs/organizationsListOrSearchFacilities.js +46 -9
  8. package/funcs/organizationsListOrSearchFacilities.js.map +1 -1
  9. package/funcs/supportArticlesGetSupportArticle.js +1 -1
  10. package/funcs/supportArticlesGetSupportArticle.js.map +1 -1
  11. package/funcs/supportArticlesListOrSearchSupportArticles.d.ts +4 -1
  12. package/funcs/supportArticlesListOrSearchSupportArticles.d.ts.map +1 -1
  13. package/funcs/supportArticlesListOrSearchSupportArticles.js +42 -7
  14. package/funcs/supportArticlesListOrSearchSupportArticles.js.map +1 -1
  15. package/funcs/vendorsExpediteTimeRemaining.d.ts +17 -0
  16. package/funcs/vendorsExpediteTimeRemaining.d.ts.map +1 -0
  17. package/funcs/vendorsExpediteTimeRemaining.js +120 -0
  18. package/funcs/vendorsExpediteTimeRemaining.js.map +1 -0
  19. package/funcs/vendorsListVendorInvoices.d.ts +24 -0
  20. package/funcs/vendorsListVendorInvoices.d.ts.map +1 -0
  21. package/funcs/vendorsListVendorInvoices.js +166 -0
  22. package/funcs/vendorsListVendorInvoices.js.map +1 -0
  23. package/funcs/vendorsListVendorJobTitles.d.ts +4 -1
  24. package/funcs/vendorsListVendorJobTitles.d.ts.map +1 -1
  25. package/funcs/vendorsListVendorJobTitles.js +39 -6
  26. package/funcs/vendorsListVendorJobTitles.js.map +1 -1
  27. package/jsr.json +1 -1
  28. package/lib/config.d.ts +3 -3
  29. package/lib/config.js +3 -3
  30. package/mcp-server/extensions.d.ts +9 -0
  31. package/mcp-server/extensions.d.ts.map +1 -0
  32. package/mcp-server/extensions.js +6 -0
  33. package/mcp-server/extensions.js.map +1 -0
  34. package/mcp-server/mcp-server.js +1 -1
  35. package/mcp-server/resources.d.ts +9 -4
  36. package/mcp-server/resources.d.ts.map +1 -1
  37. package/mcp-server/resources.js +36 -9
  38. package/mcp-server/resources.js.map +1 -1
  39. package/mcp-server/server.d.ts.map +1 -1
  40. package/mcp-server/server.js +10 -1
  41. package/mcp-server/server.js.map +1 -1
  42. package/mcp-server/tools/organizationsListOrSearchFacilities.js +1 -1
  43. package/mcp-server/tools/organizationsListOrSearchFacilities.js.map +1 -1
  44. package/mcp-server/tools/supportArticlesListOrSearchSupportArticles.js +1 -1
  45. package/mcp-server/tools/supportArticlesListOrSearchSupportArticles.js.map +1 -1
  46. package/mcp-server/tools/vendorsExpediteTimeRemaining.d.ts +8 -0
  47. package/mcp-server/tools/vendorsExpediteTimeRemaining.d.ts.map +1 -0
  48. package/mcp-server/tools/vendorsExpediteTimeRemaining.js +64 -0
  49. package/mcp-server/tools/vendorsExpediteTimeRemaining.js.map +1 -0
  50. package/mcp-server/tools/vendorsListVendorInvoices.d.ts +8 -0
  51. package/mcp-server/tools/vendorsListVendorInvoices.d.ts.map +1 -0
  52. package/mcp-server/tools/vendorsListVendorInvoices.js +68 -0
  53. package/mcp-server/tools/vendorsListVendorInvoices.js.map +1 -0
  54. package/mcp-server/tools/vendorsListVendorJobTitles.js +1 -1
  55. package/mcp-server/tools/vendorsListVendorJobTitles.js.map +1 -1
  56. package/models/components/expand.d.ts +3 -0
  57. package/models/components/expand.d.ts.map +1 -1
  58. package/models/components/expand.js +1 -0
  59. package/models/components/expand.js.map +1 -1
  60. package/models/components/index.d.ts +2 -0
  61. package/models/components/index.d.ts.map +1 -1
  62. package/models/components/index.js +2 -0
  63. package/models/components/index.js.map +1 -1
  64. package/models/components/invoice.d.ts +43 -0
  65. package/models/components/invoice.d.ts.map +1 -0
  66. package/models/components/invoice.js +91 -0
  67. package/models/components/invoice.js.map +1 -0
  68. package/models/components/invoiceitem.d.ts +40 -0
  69. package/models/components/invoiceitem.d.ts.map +1 -0
  70. package/models/components/invoiceitem.js +94 -0
  71. package/models/components/invoiceitem.js.map +1 -0
  72. package/models/operations/expeditetimeremaining.d.ts +60 -0
  73. package/models/operations/expeditetimeremaining.d.ts.map +1 -0
  74. package/models/operations/expeditetimeremaining.js +113 -0
  75. package/models/operations/expeditetimeremaining.js.map +1 -0
  76. package/models/operations/index.d.ts +2 -0
  77. package/models/operations/index.d.ts.map +1 -1
  78. package/models/operations/index.js +2 -0
  79. package/models/operations/index.js.map +1 -1
  80. package/models/operations/listorsearchfacilities.d.ts +25 -0
  81. package/models/operations/listorsearchfacilities.d.ts.map +1 -1
  82. package/models/operations/listorsearchfacilities.js +36 -1
  83. package/models/operations/listorsearchfacilities.js.map +1 -1
  84. package/models/operations/listorsearchsupportarticles.d.ts +25 -0
  85. package/models/operations/listorsearchsupportarticles.d.ts.map +1 -1
  86. package/models/operations/listorsearchsupportarticles.js +36 -1
  87. package/models/operations/listorsearchsupportarticles.js.map +1 -1
  88. package/models/operations/listvendorinvoices.d.ts +116 -0
  89. package/models/operations/listvendorinvoices.d.ts.map +1 -0
  90. package/models/operations/listvendorinvoices.js +155 -0
  91. package/models/operations/listvendorinvoices.js.map +1 -0
  92. package/models/operations/listvendorjobtitles.d.ts +25 -0
  93. package/models/operations/listvendorjobtitles.d.ts.map +1 -1
  94. package/models/operations/listvendorjobtitles.js +36 -1
  95. package/models/operations/listvendorjobtitles.js.map +1 -1
  96. package/package.json +1 -1
  97. package/react-query/index.d.ts +2 -0
  98. package/react-query/index.d.ts.map +1 -1
  99. package/react-query/index.js +2 -0
  100. package/react-query/index.js.map +1 -1
  101. package/react-query/organizationsListOrSearchFacilities.d.ts +54 -3
  102. package/react-query/organizationsListOrSearchFacilities.d.ts.map +1 -1
  103. package/react-query/organizationsListOrSearchFacilities.js +89 -0
  104. package/react-query/organizationsListOrSearchFacilities.js.map +1 -1
  105. package/react-query/supportArticlesListOrSearchSupportArticles.d.ts +28 -3
  106. package/react-query/supportArticlesListOrSearchSupportArticles.d.ts.map +1 -1
  107. package/react-query/supportArticlesListOrSearchSupportArticles.js +58 -0
  108. package/react-query/supportArticlesListOrSearchSupportArticles.js.map +1 -1
  109. package/react-query/vendorsExpediteTimeRemaining.d.ts +30 -0
  110. package/react-query/vendorsExpediteTimeRemaining.d.ts.map +1 -0
  111. package/react-query/vendorsExpediteTimeRemaining.js +96 -0
  112. package/react-query/vendorsExpediteTimeRemaining.js.map +1 -0
  113. package/react-query/vendorsListVendorInvoices.d.ts +96 -0
  114. package/react-query/vendorsListVendorInvoices.d.ts.map +1 -0
  115. package/react-query/vendorsListVendorInvoices.js +178 -0
  116. package/react-query/vendorsListVendorInvoices.js.map +1 -0
  117. package/react-query/vendorsListVendorJobTitles.d.ts +28 -3
  118. package/react-query/vendorsListVendorJobTitles.d.ts.map +1 -1
  119. package/react-query/vendorsListVendorJobTitles.js +59 -0
  120. package/react-query/vendorsListVendorJobTitles.js.map +1 -1
  121. package/sdk/organizations.d.ts +4 -1
  122. package/sdk/organizations.d.ts.map +1 -1
  123. package/sdk/organizations.js +2 -1
  124. package/sdk/organizations.js.map +1 -1
  125. package/sdk/supportarticles.d.ts +4 -1
  126. package/sdk/supportarticles.d.ts.map +1 -1
  127. package/sdk/supportarticles.js +2 -1
  128. package/sdk/supportarticles.js.map +1 -1
  129. package/sdk/vendors.d.ts +24 -1
  130. package/sdk/vendors.d.ts.map +1 -1
  131. package/sdk/vendors.js +26 -1
  132. package/sdk/vendors.js.map +1 -1
  133. package/src/__tests__/supportarticles.test.ts +2 -1
  134. package/src/__tests__/vendors.test.ts +58 -1
  135. package/src/funcs/organizationsListOrSearchFacilities.ts +116 -42
  136. package/src/funcs/supportArticlesGetSupportArticle.ts +1 -1
  137. package/src/funcs/supportArticlesListOrSearchSupportArticles.ts +100 -31
  138. package/src/funcs/vendorsExpediteTimeRemaining.ts +171 -0
  139. package/src/funcs/vendorsListVendorInvoices.ts +255 -0
  140. package/src/funcs/vendorsListVendorJobTitles.ts +101 -33
  141. package/src/lib/config.ts +3 -3
  142. package/src/mcp-server/extensions.ts +13 -0
  143. package/src/mcp-server/mcp-server.ts +1 -1
  144. package/src/mcp-server/resources.ts +75 -14
  145. package/src/mcp-server/server.ts +20 -1
  146. package/src/mcp-server/tools/organizationsListOrSearchFacilities.ts +1 -1
  147. package/src/mcp-server/tools/supportArticlesListOrSearchSupportArticles.ts +1 -1
  148. package/src/mcp-server/tools/vendorsExpediteTimeRemaining.ts +37 -0
  149. package/src/mcp-server/tools/vendorsListVendorInvoices.ts +41 -0
  150. package/src/mcp-server/tools/vendorsListVendorJobTitles.ts +1 -1
  151. package/src/models/components/expand.ts +1 -0
  152. package/src/models/components/index.ts +2 -0
  153. package/src/models/components/invoice.ts +99 -0
  154. package/src/models/components/invoiceitem.ts +98 -0
  155. package/src/models/operations/expeditetimeremaining.ts +152 -0
  156. package/src/models/operations/index.ts +2 -0
  157. package/src/models/operations/listorsearchfacilities.ts +72 -0
  158. package/src/models/operations/listorsearchsupportarticles.ts +75 -0
  159. package/src/models/operations/listvendorinvoices.ts +252 -0
  160. package/src/models/operations/listvendorjobtitles.ts +68 -0
  161. package/src/react-query/index.ts +2 -0
  162. package/src/react-query/organizationsListOrSearchFacilities.ts +179 -1
  163. package/src/react-query/supportArticlesListOrSearchSupportArticles.ts +149 -1
  164. package/src/react-query/vendorsExpediteTimeRemaining.ts +165 -0
  165. package/src/react-query/vendorsListVendorInvoices.ts +364 -0
  166. package/src/react-query/vendorsListVendorJobTitles.ts +149 -1
  167. package/src/sdk/organizations.ts +5 -2
  168. package/src/sdk/supportarticles.ts +8 -2
  169. package/src/sdk/vendors.ts +47 -2
@@ -3,6 +3,7 @@
3
3
  */
4
4
 
5
5
  import { GreenSecurityCore } from "../core.js";
6
+ import { dlv } from "../lib/dlv.js";
6
7
  import { encodeFormQuery } from "../lib/encodings.js";
7
8
  import * as M from "../lib/matchers.js";
8
9
  import { compactMap } from "../lib/primitives.js";
@@ -22,6 +23,12 @@ import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
22
23
  import * as operations from "../models/operations/index.js";
23
24
  import { APICall, APIPromise } from "../types/async.js";
24
25
  import { Result } from "../types/fp.js";
26
+ import {
27
+ createPageIterator,
28
+ haltIterator,
29
+ PageIterator,
30
+ Paginator,
31
+ } from "../types/operations.js";
25
32
 
26
33
  /**
27
34
  * List or search support articles
@@ -34,15 +41,18 @@ export function supportArticlesListOrSearchSupportArticles(
34
41
  request: operations.ListOrSearchSupportArticlesRequest,
35
42
  options?: RequestOptions,
36
43
  ): APIPromise<
37
- Result<
38
- operations.ListOrSearchSupportArticlesListOrSearchArticlesOk,
39
- | APIError
40
- | SDKValidationError
41
- | UnexpectedClientError
42
- | InvalidRequestError
43
- | RequestAbortedError
44
- | RequestTimeoutError
45
- | ConnectionError
44
+ PageIterator<
45
+ Result<
46
+ operations.ListOrSearchSupportArticlesResponse,
47
+ | APIError
48
+ | SDKValidationError
49
+ | UnexpectedClientError
50
+ | InvalidRequestError
51
+ | RequestAbortedError
52
+ | RequestTimeoutError
53
+ | ConnectionError
54
+ >,
55
+ { page: number }
46
56
  >
47
57
  > {
48
58
  return new APIPromise($do(
@@ -58,15 +68,18 @@ async function $do(
58
68
  options?: RequestOptions,
59
69
  ): Promise<
60
70
  [
61
- Result<
62
- operations.ListOrSearchSupportArticlesListOrSearchArticlesOk,
63
- | APIError
64
- | SDKValidationError
65
- | UnexpectedClientError
66
- | InvalidRequestError
67
- | RequestAbortedError
68
- | RequestTimeoutError
69
- | ConnectionError
71
+ PageIterator<
72
+ Result<
73
+ operations.ListOrSearchSupportArticlesResponse,
74
+ | APIError
75
+ | SDKValidationError
76
+ | UnexpectedClientError
77
+ | InvalidRequestError
78
+ | RequestAbortedError
79
+ | RequestTimeoutError
80
+ | ConnectionError
81
+ >,
82
+ { page: number }
70
83
  >,
71
84
  APICall,
72
85
  ]
@@ -78,7 +91,7 @@ async function $do(
78
91
  "Input validation failed",
79
92
  );
80
93
  if (!parsed.ok) {
81
- return [parsed, { status: "invalid" }];
94
+ return [haltIterator(parsed), { status: "invalid" }];
82
95
  }
83
96
  const payload = parsed.value;
84
97
  const body = null;
@@ -124,7 +137,7 @@ async function $do(
124
137
  timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
125
138
  }, options);
126
139
  if (!requestRes.ok) {
127
- return [requestRes, { status: "invalid" }];
140
+ return [haltIterator(requestRes), { status: "invalid" }];
128
141
  }
129
142
  const req = requestRes.value;
130
143
 
@@ -135,12 +148,16 @@ async function $do(
135
148
  retryCodes: context.retryCodes,
136
149
  });
137
150
  if (!doResult.ok) {
138
- return [doResult, { status: "request-error", request: req }];
151
+ return [haltIterator(doResult), { status: "request-error", request: req }];
139
152
  }
140
153
  const response = doResult.value;
141
154
 
142
- const [result] = await M.match<
143
- operations.ListOrSearchSupportArticlesListOrSearchArticlesOk,
155
+ const responseFields = {
156
+ HttpMeta: { Response: response, Request: req },
157
+ };
158
+
159
+ const [result, raw] = await M.match<
160
+ operations.ListOrSearchSupportArticlesResponse,
144
161
  | APIError
145
162
  | SDKValidationError
146
163
  | UnexpectedClientError
@@ -149,17 +166,69 @@ async function $do(
149
166
  | RequestTimeoutError
150
167
  | ConnectionError
151
168
  >(
152
- M.json(
153
- 200,
154
- operations
155
- .ListOrSearchSupportArticlesListOrSearchArticlesOk$inboundSchema,
156
- ),
169
+ M.json(200, operations.ListOrSearchSupportArticlesResponse$inboundSchema, {
170
+ key: "Result",
171
+ }),
157
172
  M.fail("4XX"),
158
173
  M.fail("5XX"),
159
- )(response);
174
+ )(response, { extraFields: responseFields });
160
175
  if (!result.ok) {
161
- return [result, { status: "complete", request: req, response }];
176
+ return [haltIterator(result), {
177
+ status: "complete",
178
+ request: req,
179
+ response,
180
+ }];
162
181
  }
163
182
 
164
- return [result, { status: "complete", request: req, response }];
183
+ const nextFunc = (
184
+ responseData: unknown,
185
+ ): {
186
+ next: Paginator<
187
+ Result<
188
+ operations.ListOrSearchSupportArticlesResponse,
189
+ | APIError
190
+ | SDKValidationError
191
+ | UnexpectedClientError
192
+ | InvalidRequestError
193
+ | RequestAbortedError
194
+ | RequestTimeoutError
195
+ | ConnectionError
196
+ >
197
+ >;
198
+ "~next"?: { page: number };
199
+ } => {
200
+ const page = request?.page ?? 1;
201
+ const nextPage = page + 1;
202
+
203
+ if (!responseData) {
204
+ return { next: () => null };
205
+ }
206
+ const results = dlv(responseData, "items");
207
+ if (!Array.isArray(results) || !results.length) {
208
+ return { next: () => null };
209
+ }
210
+ const limit = request?.itemsPerPage ?? 0;
211
+ if (results.length < limit) {
212
+ return { next: () => null };
213
+ }
214
+
215
+ const nextVal = () =>
216
+ supportArticlesListOrSearchSupportArticles(
217
+ client,
218
+ {
219
+ ...request,
220
+ page: nextPage,
221
+ },
222
+ options,
223
+ );
224
+
225
+ return { next: nextVal, "~next": { page: nextPage } };
226
+ };
227
+
228
+ const page = { ...result, ...nextFunc(raw) };
229
+ return [{ ...page, ...createPageIterator(page, (v) => !v.ok) }, {
230
+ status: "complete",
231
+ request: req,
232
+ response,
233
+ }];
165
234
  }
@@ -0,0 +1,171 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ */
4
+
5
+ import { GreenSecurityCore } from "../core.js";
6
+ import { encodeSimple } from "../lib/encodings.js";
7
+ import * as M from "../lib/matchers.js";
8
+ import { compactMap } from "../lib/primitives.js";
9
+ import { safeParse } from "../lib/schemas.js";
10
+ import { RequestOptions } from "../lib/sdks.js";
11
+ import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js";
12
+ import { pathToFunc } from "../lib/url.js";
13
+ import { APIError } from "../models/errors/apierror.js";
14
+ import {
15
+ ConnectionError,
16
+ InvalidRequestError,
17
+ RequestAbortedError,
18
+ RequestTimeoutError,
19
+ UnexpectedClientError,
20
+ } from "../models/errors/httpclienterrors.js";
21
+ import * as errors from "../models/errors/index.js";
22
+ import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
23
+ import * as operations from "../models/operations/index.js";
24
+ import { APICall, APIPromise } from "../types/async.js";
25
+ import { Result } from "../types/fp.js";
26
+
27
+ /**
28
+ * Expedite time remaining
29
+ *
30
+ * @remarks
31
+ * For vendors who have a paid 24-hour expedite credentials invoice, get the remaining time (in seconds) for which submitted credentials will be expedited.
32
+ */
33
+ export function vendorsExpediteTimeRemaining(
34
+ client: GreenSecurityCore,
35
+ request: operations.ExpediteTimeRemainingRequest,
36
+ options?: RequestOptions,
37
+ ): APIPromise<
38
+ Result<
39
+ operations.ExpediteTimeRemainingResponseBody,
40
+ | errors.ApiErrorResponse
41
+ | APIError
42
+ | SDKValidationError
43
+ | UnexpectedClientError
44
+ | InvalidRequestError
45
+ | RequestAbortedError
46
+ | RequestTimeoutError
47
+ | ConnectionError
48
+ >
49
+ > {
50
+ return new APIPromise($do(
51
+ client,
52
+ request,
53
+ options,
54
+ ));
55
+ }
56
+
57
+ async function $do(
58
+ client: GreenSecurityCore,
59
+ request: operations.ExpediteTimeRemainingRequest,
60
+ options?: RequestOptions,
61
+ ): Promise<
62
+ [
63
+ Result<
64
+ operations.ExpediteTimeRemainingResponseBody,
65
+ | errors.ApiErrorResponse
66
+ | APIError
67
+ | SDKValidationError
68
+ | UnexpectedClientError
69
+ | InvalidRequestError
70
+ | RequestAbortedError
71
+ | RequestTimeoutError
72
+ | ConnectionError
73
+ >,
74
+ APICall,
75
+ ]
76
+ > {
77
+ const parsed = safeParse(
78
+ request,
79
+ (value) =>
80
+ operations.ExpediteTimeRemainingRequest$outboundSchema.parse(value),
81
+ "Input validation failed",
82
+ );
83
+ if (!parsed.ok) {
84
+ return [parsed, { status: "invalid" }];
85
+ }
86
+ const payload = parsed.value;
87
+ const body = null;
88
+
89
+ const pathParams = {
90
+ vendor_id_or_me: encodeSimple("vendor_id_or_me", payload.vendor_id_or_me, {
91
+ explode: false,
92
+ charEncoding: "percent",
93
+ }),
94
+ };
95
+
96
+ const path = pathToFunc("/vendors/{vendor_id_or_me}/expedite-time-remaining")(
97
+ pathParams,
98
+ );
99
+
100
+ const headers = new Headers(compactMap({
101
+ Accept: "application/json",
102
+ }));
103
+
104
+ const securityInput = await extractSecurity(client._options.security);
105
+ const requestSecurity = resolveGlobalSecurity(securityInput);
106
+
107
+ const context = {
108
+ baseURL: options?.serverURL ?? client._baseURL ?? "",
109
+ operationID: "expediteTimeRemaining",
110
+ oAuth2Scopes: [],
111
+
112
+ resolvedSecurity: requestSecurity,
113
+
114
+ securitySource: client._options.security,
115
+ retryConfig: options?.retries
116
+ || client._options.retryConfig
117
+ || { strategy: "none" },
118
+ retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"],
119
+ };
120
+
121
+ const requestRes = client._createRequest(context, {
122
+ security: requestSecurity,
123
+ method: "GET",
124
+ baseURL: options?.serverURL,
125
+ path: path,
126
+ headers: headers,
127
+ body: body,
128
+ timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
129
+ }, options);
130
+ if (!requestRes.ok) {
131
+ return [requestRes, { status: "invalid" }];
132
+ }
133
+ const req = requestRes.value;
134
+
135
+ const doResult = await client._do(req, {
136
+ context,
137
+ errorCodes: ["400", "401", "4XX", "5XX"],
138
+ retryConfig: context.retryConfig,
139
+ retryCodes: context.retryCodes,
140
+ });
141
+ if (!doResult.ok) {
142
+ return [doResult, { status: "request-error", request: req }];
143
+ }
144
+ const response = doResult.value;
145
+
146
+ const responseFields = {
147
+ HttpMeta: { Response: response, Request: req },
148
+ };
149
+
150
+ const [result] = await M.match<
151
+ operations.ExpediteTimeRemainingResponseBody,
152
+ | errors.ApiErrorResponse
153
+ | APIError
154
+ | SDKValidationError
155
+ | UnexpectedClientError
156
+ | InvalidRequestError
157
+ | RequestAbortedError
158
+ | RequestTimeoutError
159
+ | ConnectionError
160
+ >(
161
+ M.json(200, operations.ExpediteTimeRemainingResponseBody$inboundSchema),
162
+ M.jsonErr([400, 401], errors.ApiErrorResponse$inboundSchema),
163
+ M.fail("4XX"),
164
+ M.fail("5XX"),
165
+ )(response, { extraFields: responseFields });
166
+ if (!result.ok) {
167
+ return [result, { status: "complete", request: req, response }];
168
+ }
169
+
170
+ return [result, { status: "complete", request: req, response }];
171
+ }
@@ -0,0 +1,255 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ */
4
+
5
+ import { GreenSecurityCore } from "../core.js";
6
+ import { dlv } from "../lib/dlv.js";
7
+ import { encodeFormQuery, encodeSimple, queryJoin } from "../lib/encodings.js";
8
+ import * as M from "../lib/matchers.js";
9
+ import { compactMap } from "../lib/primitives.js";
10
+ import { safeParse } from "../lib/schemas.js";
11
+ import { RequestOptions } from "../lib/sdks.js";
12
+ import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js";
13
+ import { pathToFunc } from "../lib/url.js";
14
+ import { APIError } from "../models/errors/apierror.js";
15
+ import {
16
+ ConnectionError,
17
+ InvalidRequestError,
18
+ RequestAbortedError,
19
+ RequestTimeoutError,
20
+ UnexpectedClientError,
21
+ } from "../models/errors/httpclienterrors.js";
22
+ import * as errors from "../models/errors/index.js";
23
+ import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
24
+ import * as operations from "../models/operations/index.js";
25
+ import { APICall, APIPromise } from "../types/async.js";
26
+ import { Result } from "../types/fp.js";
27
+ import {
28
+ createPageIterator,
29
+ haltIterator,
30
+ PageIterator,
31
+ Paginator,
32
+ } from "../types/operations.js";
33
+
34
+ /**
35
+ * List vendor invoices
36
+ *
37
+ * @remarks
38
+ * List invoices for Vendors
39
+ *
40
+ * Available `expand` scopes are:
41
+ *
42
+ * invoice.line_items
43
+ */
44
+ export function vendorsListVendorInvoices(
45
+ client: GreenSecurityCore,
46
+ request: operations.ListVendorInvoicesRequest,
47
+ options?: RequestOptions,
48
+ ): APIPromise<
49
+ PageIterator<
50
+ Result<
51
+ operations.ListVendorInvoicesResponse,
52
+ | errors.ApiErrorResponse
53
+ | APIError
54
+ | SDKValidationError
55
+ | UnexpectedClientError
56
+ | InvalidRequestError
57
+ | RequestAbortedError
58
+ | RequestTimeoutError
59
+ | ConnectionError
60
+ >,
61
+ { page: number }
62
+ >
63
+ > {
64
+ return new APIPromise($do(
65
+ client,
66
+ request,
67
+ options,
68
+ ));
69
+ }
70
+
71
+ async function $do(
72
+ client: GreenSecurityCore,
73
+ request: operations.ListVendorInvoicesRequest,
74
+ options?: RequestOptions,
75
+ ): Promise<
76
+ [
77
+ PageIterator<
78
+ Result<
79
+ operations.ListVendorInvoicesResponse,
80
+ | errors.ApiErrorResponse
81
+ | APIError
82
+ | SDKValidationError
83
+ | UnexpectedClientError
84
+ | InvalidRequestError
85
+ | RequestAbortedError
86
+ | RequestTimeoutError
87
+ | ConnectionError
88
+ >,
89
+ { page: number }
90
+ >,
91
+ APICall,
92
+ ]
93
+ > {
94
+ const parsed = safeParse(
95
+ request,
96
+ (value) => operations.ListVendorInvoicesRequest$outboundSchema.parse(value),
97
+ "Input validation failed",
98
+ );
99
+ if (!parsed.ok) {
100
+ return [haltIterator(parsed), { status: "invalid" }];
101
+ }
102
+ const payload = parsed.value;
103
+ const body = null;
104
+
105
+ const pathParams = {
106
+ vendor_id_or_me: encodeSimple("vendor_id_or_me", payload.vendor_id_or_me, {
107
+ explode: false,
108
+ charEncoding: "percent",
109
+ }),
110
+ };
111
+
112
+ const path = pathToFunc("/vendors/{vendor_id_or_me}/invoices")(pathParams);
113
+
114
+ const query = queryJoin(
115
+ encodeFormQuery({
116
+ "expand": payload.expand,
117
+ }, { explode: false }),
118
+ encodeFormQuery({
119
+ "desc": payload.desc,
120
+ "items_per_page": payload.items_per_page,
121
+ "page": payload.page,
122
+ "sort": payload.sort,
123
+ }),
124
+ );
125
+
126
+ const headers = new Headers(compactMap({
127
+ Accept: "application/json",
128
+ }));
129
+
130
+ const securityInput = await extractSecurity(client._options.security);
131
+ const requestSecurity = resolveGlobalSecurity(securityInput);
132
+
133
+ const context = {
134
+ baseURL: options?.serverURL ?? client._baseURL ?? "",
135
+ operationID: "listVendorInvoices",
136
+ oAuth2Scopes: [],
137
+
138
+ resolvedSecurity: requestSecurity,
139
+
140
+ securitySource: client._options.security,
141
+ retryConfig: options?.retries
142
+ || client._options.retryConfig
143
+ || { strategy: "none" },
144
+ retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"],
145
+ };
146
+
147
+ const requestRes = client._createRequest(context, {
148
+ security: requestSecurity,
149
+ method: "GET",
150
+ baseURL: options?.serverURL,
151
+ path: path,
152
+ headers: headers,
153
+ query: query,
154
+ body: body,
155
+ timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
156
+ }, options);
157
+ if (!requestRes.ok) {
158
+ return [haltIterator(requestRes), { status: "invalid" }];
159
+ }
160
+ const req = requestRes.value;
161
+
162
+ const doResult = await client._do(req, {
163
+ context,
164
+ errorCodes: ["400", "401", "4XX", "5XX"],
165
+ retryConfig: context.retryConfig,
166
+ retryCodes: context.retryCodes,
167
+ });
168
+ if (!doResult.ok) {
169
+ return [haltIterator(doResult), { status: "request-error", request: req }];
170
+ }
171
+ const response = doResult.value;
172
+
173
+ const responseFields = {
174
+ HttpMeta: { Response: response, Request: req },
175
+ };
176
+
177
+ const [result, raw] = await M.match<
178
+ operations.ListVendorInvoicesResponse,
179
+ | errors.ApiErrorResponse
180
+ | APIError
181
+ | SDKValidationError
182
+ | UnexpectedClientError
183
+ | InvalidRequestError
184
+ | RequestAbortedError
185
+ | RequestTimeoutError
186
+ | ConnectionError
187
+ >(
188
+ M.json(200, operations.ListVendorInvoicesResponse$inboundSchema, {
189
+ key: "Result",
190
+ }),
191
+ M.jsonErr([400, 401], errors.ApiErrorResponse$inboundSchema),
192
+ M.fail("4XX"),
193
+ M.fail("5XX"),
194
+ )(response, { extraFields: responseFields });
195
+ if (!result.ok) {
196
+ return [haltIterator(result), {
197
+ status: "complete",
198
+ request: req,
199
+ response,
200
+ }];
201
+ }
202
+
203
+ const nextFunc = (
204
+ responseData: unknown,
205
+ ): {
206
+ next: Paginator<
207
+ Result<
208
+ operations.ListVendorInvoicesResponse,
209
+ | errors.ApiErrorResponse
210
+ | APIError
211
+ | SDKValidationError
212
+ | UnexpectedClientError
213
+ | InvalidRequestError
214
+ | RequestAbortedError
215
+ | RequestTimeoutError
216
+ | ConnectionError
217
+ >
218
+ >;
219
+ "~next"?: { page: number };
220
+ } => {
221
+ const page = request?.page ?? 1;
222
+ const nextPage = page + 1;
223
+
224
+ if (!responseData) {
225
+ return { next: () => null };
226
+ }
227
+ const results = dlv(responseData, "items");
228
+ if (!Array.isArray(results) || !results.length) {
229
+ return { next: () => null };
230
+ }
231
+ const limit = request?.itemsPerPage ?? 0;
232
+ if (results.length < limit) {
233
+ return { next: () => null };
234
+ }
235
+
236
+ const nextVal = () =>
237
+ vendorsListVendorInvoices(
238
+ client,
239
+ {
240
+ ...request,
241
+ page: nextPage,
242
+ },
243
+ options,
244
+ );
245
+
246
+ return { next: nextVal, "~next": { page: nextPage } };
247
+ };
248
+
249
+ const page = { ...result, ...nextFunc(raw) };
250
+ return [{ ...page, ...createPageIterator(page, (v) => !v.ok) }, {
251
+ status: "complete",
252
+ request: req,
253
+ response,
254
+ }];
255
+ }