diff --git a/build.log b/build.log new file mode 100644 index 0000000..d6e3149 --- /dev/null +++ b/build.log @@ -0,0 +1,105 @@ + +> @ominity/api-typescript@0.0.3 build +> tshy + +src/funcs/admins/adminsGet.ts(125,9): error TS2322: Type 'string | undefined' is not assignable to type 'string'. + Type 'undefined' is not assignable to type 'string'. +writing tsconfig files... +using existing tsconfig.json +building D:\Freelance\Tim - Money - Slave\ominity-api-typescript +tshy config { + sourceDialects: [ '@ominity/api-typescript/source' ], + exports: { + '.': './src/index.ts', + './package.json': './package.json', + './types': './src/types/index.ts', + './models/errors': './src/models/errors/index.ts', + './models': './src/models/index.ts', + './models/operations': './src/models/operations/index.ts', + './*.js': './src/*.ts', + './*': './src/*.ts' + } +} +exports { + '.': { + import: { + '@ominity/api-typescript/source': './src/index.ts', + types: './dist/esm/index.d.ts', + default: './dist/esm/index.js' + }, + require: { + types: './dist/commonjs/index.d.ts', + default: './dist/commonjs/index.js' + } + }, + './package.json': './package.json', + './types': { + import: { + '@ominity/api-typescript/source': './src/types/index.ts', + types: './dist/esm/types/index.d.ts', + default: './dist/esm/types/index.js' + }, + require: { + types: './dist/commonjs/types/index.d.ts', + default: './dist/commonjs/types/index.js' + } + }, + './models/errors': { + import: { + '@ominity/api-typescript/source': './src/models/errors/index.ts', + types: './dist/esm/models/errors/index.d.ts', + default: './dist/esm/models/errors/index.js' + }, + require: { + types: './dist/commonjs/models/errors/index.d.ts', + default: './dist/commonjs/models/errors/index.js' + } + }, + './models': { + import: { + '@ominity/api-typescript/source': './src/models/index.ts', + types: './dist/esm/models/index.d.ts', + default: './dist/esm/models/index.js' + }, + require: { + types: './dist/commonjs/models/index.d.ts', + default: './dist/commonjs/models/index.js' + } + }, + './models/operations': { + import: { + '@ominity/api-typescript/source': './src/models/operations/index.ts', + types: './dist/esm/models/operations/index.d.ts', + default: './dist/esm/models/operations/index.js' + }, + require: { + types: './dist/commonjs/models/operations/index.d.ts', + default: './dist/commonjs/models/operations/index.js' + } + }, + './*.js': { + import: { + '@ominity/api-typescript/source': './src/*.ts', + types: './dist/esm/*.d.ts', + default: './dist/esm/*.js' + }, + require: { + types: './dist/commonjs/*.d.ts', + default: './dist/commonjs/*.js' + } + }, + './*': { + import: { + '@ominity/api-typescript/source': './src/*.ts', + types: './dist/esm/*.d.ts', + default: './dist/esm/*.js' + }, + require: { + types: './dist/commonjs/*.d.ts', + default: './dist/commonjs/*.js' + } + } +} +set dialect { where: 'src', mode: 'esm' } +building esm +build failed diff --git a/build_log.txt b/build_log.txt new file mode 100644 index 0000000..d6646e7 Binary files /dev/null and b/build_log.txt differ diff --git a/build_log_2.txt b/build_log_2.txt new file mode 100644 index 0000000..b39658e Binary files /dev/null and b/build_log_2.txt differ diff --git a/build_log_3.txt b/build_log_3.txt new file mode 100644 index 0000000..e37d3ed Binary files /dev/null and b/build_log_3.txt differ diff --git a/src/funcs/admins/adminsGet.ts b/src/funcs/admins/adminsGet.ts new file mode 100644 index 0000000..0e82810 --- /dev/null +++ b/src/funcs/admins/adminsGet.ts @@ -0,0 +1,179 @@ +/* + * Get admin. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { + encodeSimple, +} from "../../lib/encodings.js"; +import * as M from "../../lib/matchers.js"; +import { safeParse } from "../../lib/schemas.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import * as errors from "../../models/errors/index.js"; +import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import * as operations from "../../models/operations/index.js"; +import { GetAdminResponse$inboundSchema } from "../../models/operations/admins.js"; +import { APICall, APIPromise } from "../../types/async.js"; +import { OK, Result } from "../../types/fp.js"; + +export function adminsGet( + client: ClientSDK, + request: operations.GetAdminRequest, + options?: RequestOptions, +): APIPromise< + Result< + operations.GetAdminResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + > +> { + return new APIPromise($do( + client, + request, + options, + )); +} + +async function $do( + client: ClientSDK, + request: operations.GetAdminRequest, + options?: RequestOptions, +): Promise< + [ + Result< + operations.GetAdminResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >, + APICall, + ] +> { + const parsed = safeParse( + request, + (value) => + operations.GetAdminRequest$outboundSchema.parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return [parsed, { status: "invalid" }]; + } + const payload = parsed.value; + const body = null; + + const path = encodeSimple( + "/admins/{id}", + { "id": payload.id }, + { explode: false, charEncoding: "percent" }, + ) || ""; + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + options: client._options, + baseURL: options?.serverURL ?? client._baseURL ?? "", + operationID: "admins.get", + oAuth2Scopes: null, + resolvedSecurity: requestSecurity, + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { + strategy: "backoff", + backoff: { + initialInterval: 500, + maxInterval: 5000, + exponent: 2, + maxElapsedTime: 7500, + }, + retryConnectionErrors: true, + } + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["5xx"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "GET", + baseURL: options?.serverURL, + path, + headers, + body, + userAgent: client._options.userAgent, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return [requestRes, { status: "invalid" }]; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "4XX", "5XX"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return [doResult, { status: "request-error", request: req }]; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.GetAdminResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >( + M.json(200, GetAdminResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.fail("5XX"), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return [result, { status: "complete", request: req, response }]; + } + + return [ + OK(result.value), + { status: "complete", request: req, response }, + ]; +} diff --git a/src/funcs/admins/adminsList.ts b/src/funcs/admins/adminsList.ts new file mode 100644 index 0000000..6cf502e --- /dev/null +++ b/src/funcs/admins/adminsList.ts @@ -0,0 +1,185 @@ +/* + * List admins. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { + encodeFormQuery, + queryJoin, +} from "../../lib/encodings.js"; +import * as M from "../../lib/matchers.js"; +import { safeParse } from "../../lib/schemas.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import * as errors from "../../models/errors/index.js"; +import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import * as operations from "../../models/operations/index.js"; +import { ListAdminsResponse$inboundSchema } from "../../models/operations/admins.js"; +import { applyPaginationParams } from "../../models/pagination.js"; +import { APICall, APIPromise } from "../../types/async.js"; +import { OK, Result } from "../../types/fp.js"; + +export function adminsList( + client: ClientSDK, + request?: operations.ListAdminsRequest | undefined, + options?: RequestOptions, +): APIPromise< + Result< + operations.ListAdminsResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + > +> { + return new APIPromise($do( + client, + request, + options, + )); +} + +async function $do( + client: ClientSDK, + request?: operations.ListAdminsRequest | undefined, + options?: RequestOptions, +): Promise< + [ + Result< + operations.ListAdminsResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >, + APICall, + ] +> { + const parsed = safeParse( + request, + (value) => + operations.ListAdminsRequest$outboundSchema.optional().parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return [parsed, { status: "invalid" }]; + } + const payload = parsed.value; + const body = null; + + const path = "/admins"; + + const baseQuery = encodeFormQuery({ + page: payload?.page, + limit: payload?.limit, + }); + + const query = queryJoin(baseQuery); + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + options: client._options, + baseURL: options?.serverURL ?? client._baseURL ?? "", + operationID: "admins.list", + oAuth2Scopes: null, + resolvedSecurity: requestSecurity, + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { + strategy: "backoff", + backoff: { + initialInterval: 500, + maxInterval: 5000, + exponent: 2, + maxElapsedTime: 7500, + }, + retryConnectionErrors: true, + } + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["5xx"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "GET", + baseURL: options?.serverURL, + path, + headers, + query, + body, + userAgent: client._options.userAgent, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return [requestRes, { status: "invalid" }]; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "4XX", "5XX"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return [doResult, { status: "request-error", request: req }]; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.ListAdminsResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >( + M.json(200, ListAdminsResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.fail("5XX"), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return [result, { status: "complete", request: req, response }]; + } + + return [ + OK(applyPaginationParams(result.value, payload)), + { status: "complete", request: req, response }, + ]; +} diff --git a/src/funcs/admins/index.ts b/src/funcs/admins/index.ts new file mode 100644 index 0000000..8ecf4f5 --- /dev/null +++ b/src/funcs/admins/index.ts @@ -0,0 +1,6 @@ +/* + * Admins functions. + */ + +export * from "./adminsGet.js"; +export * from "./adminsList.js"; diff --git a/src/funcs/cms/componentsGet.ts b/src/funcs/cms/componentsGet.ts new file mode 100644 index 0000000..9a5f974 --- /dev/null +++ b/src/funcs/cms/componentsGet.ts @@ -0,0 +1,162 @@ +/* + * Get CMS component. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { encodeFormQuery } from "../../lib/encodings.js"; + +import * as M from "../../lib/matchers.js"; +import { safeParse } from "../../lib/schemas.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import * as errors from "../../models/errors/index.js"; +import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import * as operations from "../../models/operations/index.js"; +import { APICall, APIPromise } from "../../types/async.js"; +import { OK, Result } from "../../types/fp.js"; + +export function componentsGet( + client: ClientSDK, + request: operations.GetComponentRequest, + options?: RequestOptions, +): APIPromise< + Result< + operations.GetComponentResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + > +> { + return new APIPromise($do( + client, + request, + options, + )); +} + +async function $do( + client: ClientSDK, + request: operations.GetComponentRequest, + options?: RequestOptions, +): Promise< + [ + Result< + operations.GetComponentResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >, + APICall, + ] +> { + const parsed = safeParse( + request, + (value) => operations.GetComponentRequest$outboundSchema.parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return [parsed, { status: "invalid" }]; + } + const payload = parsed.value; + const body = null; + + const safeId = encodeURIComponent(String(payload.id)); + const path = `/cms/components/${safeId}`; + + const query = encodeFormQuery({ + include: payload.include, + }); + + const headers = new Headers(); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + options: client._options, + baseURL: options?.serverURL ?? client._baseURL ?? "", + operationID: "cms.components.get", + oAuth2Scopes: null, + resolvedSecurity: requestSecurity, + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "5XX"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "GET", + baseURL: options?.serverURL, + path, + headers, + query, + body, + userAgent: client._options.userAgent, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return [requestRes, { status: "invalid" }]; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["4XX", "5XX"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return [doResult, { status: "request-error", request: req }]; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.GetComponentResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >( + M.json(200, operations.GetComponentResponse$inboundSchema, { ctype: "application/hal+json" }), + M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.fail("4XX"), + M.fail("5XX"), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return [result, { status: "complete", request: req, response }]; + } + + return [OK(result.value), { status: "complete", request: req, response }]; +} diff --git a/src/funcs/cms/componentsList.ts b/src/funcs/cms/componentsList.ts new file mode 100644 index 0000000..b8ed3c2 --- /dev/null +++ b/src/funcs/cms/componentsList.ts @@ -0,0 +1,167 @@ +/* + * List CMS components. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { encodeFormQuery } from "../../lib/encodings.js"; + +import * as M from "../../lib/matchers.js"; +import { safeParse } from "../../lib/schemas.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import * as errors from "../../models/errors/index.js"; +import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import * as operations from "../../models/operations/index.js"; +import { APICall, APIPromise } from "../../types/async.js"; +import { OK, Result } from "../../types/fp.js"; + +export function componentsList( + client: ClientSDK, + request?: operations.ListComponentsRequest | undefined, + options?: RequestOptions, +): APIPromise< + Result< + operations.ListComponentsResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + > +> { + return new APIPromise($do( + client, + request, + options, + )); +} + +async function $do( + client: ClientSDK, + request?: operations.ListComponentsRequest | undefined, + options?: RequestOptions, +): Promise< + [ + Result< + operations.ListComponentsResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >, + APICall, + ] +> { + const parsed = safeParse( + request, + (value) => operations.ListComponentsRequest$outboundSchema.optional().parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return [parsed, { status: "invalid" }]; + } + const payload = parsed.value; + const body = null; + + const path = "/cms/components"; + + const query = encodeFormQuery({ + "filter[id]": payload?.filterId, + "filter[slug]": payload?.filterSlug, + "filter[name]": payload?.filterName, + include: payload?.include, + sort: payload?.sort, + page: payload?.page, + limit: payload?.limit, + }); + + const headers = new Headers(); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + options: client._options, + baseURL: options?.serverURL ?? client._baseURL ?? "", + operationID: "cms.components.list", + oAuth2Scopes: null, + resolvedSecurity: requestSecurity, + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "5XX"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "GET", + baseURL: options?.serverURL, + path, + headers, + query, + body, + userAgent: client._options.userAgent, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return [requestRes, { status: "invalid" }]; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["4XX", "5XX"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return [doResult, { status: "request-error", request: req }]; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.ListComponentsResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >( + M.json(200, operations.ListComponentsResponse$inboundSchema, { ctype: "application/hal+json" }), + M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.fail("4XX"), + M.fail("5XX"), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return [result, { status: "complete", request: req, response }]; + } + + return [OK(result.value), { status: "complete", request: req, response }]; +} diff --git a/src/funcs/cms/index.ts b/src/funcs/cms/index.ts new file mode 100644 index 0000000..30bf21d --- /dev/null +++ b/src/funcs/cms/index.ts @@ -0,0 +1,9 @@ +export * from "./componentsList.js"; +export * from "./componentsGet.js"; +export * from "./layoutsList.js"; +export * from "./layoutsGet.js"; +export * from "./pagesList.js"; +export * from "./pagesGet.js"; +export * from "./pagesComponentsList.js"; +export * from "./menusList.js"; +export * from "./menusGet.js"; diff --git a/src/funcs/cms/layoutsGet.ts b/src/funcs/cms/layoutsGet.ts new file mode 100644 index 0000000..5a2e6bb --- /dev/null +++ b/src/funcs/cms/layoutsGet.ts @@ -0,0 +1,160 @@ +/* + * Get CMS layout. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { encodeFormQuery } from "../../lib/encodings.js"; + +import * as M from "../../lib/matchers.js"; +import { safeParse } from "../../lib/schemas.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import * as errors from "../../models/errors/index.js"; +import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import * as operations from "../../models/operations/index.js"; +import { APICall, APIPromise } from "../../types/async.js"; +import { OK, Result } from "../../types/fp.js"; + +export function layoutsGet( + client: ClientSDK, + request: operations.GetLayoutRequest, + options?: RequestOptions, +): APIPromise< + Result< + operations.GetLayoutResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + > +> { + return new APIPromise($do( + client, + request, + options, + )); +} + +async function $do( + client: ClientSDK, + request: operations.GetLayoutRequest, + options?: RequestOptions, +): Promise< + [ + Result< + operations.GetLayoutResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >, + APICall, + ] +> { + const parsed = safeParse( + request, + (value) => operations.GetLayoutRequest$outboundSchema.parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return [parsed, { status: "invalid" }]; + } + const payload = parsed.value; + const body = null; + + const safeId = encodeURIComponent(String(payload.id)); + const path = `/cms/layouts/${safeId}`; + + const query = encodeFormQuery({}); // No query params for layout get in current spec + + const headers = new Headers(); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + options: client._options, + baseURL: options?.serverURL ?? client._baseURL ?? "", + operationID: "cms.layouts.get", + oAuth2Scopes: null, + resolvedSecurity: requestSecurity, + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "5XX"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "GET", + baseURL: options?.serverURL, + path, + headers, + query, + body, + userAgent: client._options.userAgent, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return [requestRes, { status: "invalid" }]; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["4XX", "5XX"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return [doResult, { status: "request-error", request: req }]; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.GetLayoutResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >( + M.json(200, operations.GetLayoutResponse$inboundSchema, { ctype: "application/hal+json" }), + M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.fail("4XX"), + M.fail("5XX"), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return [result, { status: "complete", request: req, response }]; + } + + return [OK(result.value), { status: "complete", request: req, response }]; +} diff --git a/src/funcs/cms/layoutsList.ts b/src/funcs/cms/layoutsList.ts new file mode 100644 index 0000000..e43871e --- /dev/null +++ b/src/funcs/cms/layoutsList.ts @@ -0,0 +1,162 @@ +/* + * List CMS layouts. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { encodeFormQuery } from "../../lib/encodings.js"; + +import * as M from "../../lib/matchers.js"; +import { safeParse } from "../../lib/schemas.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import * as errors from "../../models/errors/index.js"; +import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import * as operations from "../../models/operations/index.js"; +import { APICall, APIPromise } from "../../types/async.js"; +import { OK, Result } from "../../types/fp.js"; + +export function layoutsList( + client: ClientSDK, + request?: operations.ListLayoutsRequest | undefined, + options?: RequestOptions, +): APIPromise< + Result< + operations.ListLayoutsResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + > +> { + return new APIPromise($do( + client, + request, + options, + )); +} + +async function $do( + client: ClientSDK, + request?: operations.ListLayoutsRequest | undefined, + options?: RequestOptions, +): Promise< + [ + Result< + operations.ListLayoutsResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >, + APICall, + ] +> { + const parsed = safeParse( + request, + (value) => operations.ListLayoutsRequest$outboundSchema.optional().parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return [parsed, { status: "invalid" }]; + } + const payload = parsed.value; + const body = null; + + const path = "/cms/layouts"; + + const query = encodeFormQuery({ + page: payload?.page, + limit: payload?.limit, + }); + + const headers = new Headers(); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + options: client._options, + baseURL: options?.serverURL ?? client._baseURL ?? "", + operationID: "cms.layouts.list", + oAuth2Scopes: null, + resolvedSecurity: requestSecurity, + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "5XX"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "GET", + baseURL: options?.serverURL, + path, + headers, + query, + body, + userAgent: client._options.userAgent, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return [requestRes, { status: "invalid" }]; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["4XX", "5XX"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return [doResult, { status: "request-error", request: req }]; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.ListLayoutsResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >( + M.json(200, operations.ListLayoutsResponse$inboundSchema, { ctype: "application/hal+json" }), + M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.fail("4XX"), + M.fail("5XX"), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return [result, { status: "complete", request: req, response }]; + } + + return [OK(result.value), { status: "complete", request: req, response }]; +} diff --git a/src/funcs/cms/menusGet.ts b/src/funcs/cms/menusGet.ts new file mode 100644 index 0000000..4cc8d35 --- /dev/null +++ b/src/funcs/cms/menusGet.ts @@ -0,0 +1,160 @@ +/* + * Get CMS menu. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { encodeFormQuery } from "../../lib/encodings.js"; + +import * as M from "../../lib/matchers.js"; +import { safeParse } from "../../lib/schemas.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import * as errors from "../../models/errors/index.js"; +import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import * as operations from "../../models/operations/index.js"; +import { APICall, APIPromise } from "../../types/async.js"; +import { OK, Result } from "../../types/fp.js"; + +export function menusGet( + client: ClientSDK, + request: operations.GetMenuRequest, + options?: RequestOptions, +): APIPromise< + Result< + operations.GetMenuResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + > +> { + return new APIPromise($do( + client, + request, + options, + )); +} + +async function $do( + client: ClientSDK, + request: operations.GetMenuRequest, + options?: RequestOptions, +): Promise< + [ + Result< + operations.GetMenuResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >, + APICall, + ] +> { + const parsed = safeParse( + request, + (value) => operations.GetMenuRequest$outboundSchema.parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return [parsed, { status: "invalid" }]; + } + const payload = parsed.value; + const body = null; + + const safeId = encodeURIComponent(String(payload.id)); + const path = `/cms/menus/${safeId}`; + + const query = encodeFormQuery({}); + + const headers = new Headers(); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + options: client._options, + baseURL: options?.serverURL ?? client._baseURL ?? "", + operationID: "cms.menus.get", + oAuth2Scopes: null, + resolvedSecurity: requestSecurity, + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "5XX"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "GET", + baseURL: options?.serverURL, + path, + headers, + query, + body, + userAgent: client._options.userAgent, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return [requestRes, { status: "invalid" }]; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["4XX", "5XX"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return [doResult, { status: "request-error", request: req }]; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.GetMenuResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >( + M.json(200, operations.GetMenuResponse$inboundSchema, { ctype: "application/hal+json" }), + M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.fail("4XX"), + M.fail("5XX"), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return [result, { status: "complete", request: req, response }]; + } + + return [OK(result.value), { status: "complete", request: req, response }]; +} diff --git a/src/funcs/cms/menusList.ts b/src/funcs/cms/menusList.ts new file mode 100644 index 0000000..5495ccf --- /dev/null +++ b/src/funcs/cms/menusList.ts @@ -0,0 +1,162 @@ +/* + * List CMS menus. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { encodeFormQuery } from "../../lib/encodings.js"; + +import * as M from "../../lib/matchers.js"; +import { safeParse } from "../../lib/schemas.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import * as errors from "../../models/errors/index.js"; +import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import * as operations from "../../models/operations/index.js"; +import { APICall, APIPromise } from "../../types/async.js"; +import { OK, Result } from "../../types/fp.js"; + +export function menusList( + client: ClientSDK, + request?: operations.ListMenusRequest | undefined, + options?: RequestOptions, +): APIPromise< + Result< + operations.ListMenusResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + > +> { + return new APIPromise($do( + client, + request, + options, + )); +} + +async function $do( + client: ClientSDK, + request?: operations.ListMenusRequest | undefined, + options?: RequestOptions, +): Promise< + [ + Result< + operations.ListMenusResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >, + APICall, + ] +> { + const parsed = safeParse( + request, + (value) => operations.ListMenusRequest$outboundSchema.optional().parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return [parsed, { status: "invalid" }]; + } + const payload = parsed.value; + const body = null; + + const path = "/cms/menus"; + + const query = encodeFormQuery({ + page: payload?.page, + limit: payload?.limit, + }); + + const headers = new Headers(); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + options: client._options, + baseURL: options?.serverURL ?? client._baseURL ?? "", + operationID: "cms.menus.list", + oAuth2Scopes: null, + resolvedSecurity: requestSecurity, + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "5XX"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "GET", + baseURL: options?.serverURL, + path, + headers, + query, + body, + userAgent: client._options.userAgent, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return [requestRes, { status: "invalid" }]; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["4XX", "5XX"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return [doResult, { status: "request-error", request: req }]; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.ListMenusResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >( + M.json(200, operations.ListMenusResponse$inboundSchema, { ctype: "application/hal+json" }), + M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.fail("4XX"), + M.fail("5XX"), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return [result, { status: "complete", request: req, response }]; + } + + return [OK(result.value), { status: "complete", request: req, response }]; +} diff --git a/src/funcs/cms/pagesComponentsList.ts b/src/funcs/cms/pagesComponentsList.ts new file mode 100644 index 0000000..6009525 --- /dev/null +++ b/src/funcs/cms/pagesComponentsList.ts @@ -0,0 +1,163 @@ +/* + * List CMS page components. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { encodeFormQuery } from "../../lib/encodings.js"; + +import * as M from "../../lib/matchers.js"; +import { safeParse } from "../../lib/schemas.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import * as errors from "../../models/errors/index.js"; +import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import * as operations from "../../models/operations/index.js"; +import { APICall, APIPromise } from "../../types/async.js"; +import { OK, Result } from "../../types/fp.js"; + +export function pagesComponentsList( + client: ClientSDK, + request: operations.ListPageComponentsRequest, + options?: RequestOptions, +): APIPromise< + Result< + operations.ListPageComponentsResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + > +> { + return new APIPromise($do( + client, + request, + options, + )); +} + +async function $do( + client: ClientSDK, + request: operations.ListPageComponentsRequest, + options?: RequestOptions, +): Promise< + [ + Result< + operations.ListPageComponentsResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >, + APICall, + ] +> { + const parsed = safeParse( + request, + (value) => operations.ListPageComponentsRequest$outboundSchema.parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return [parsed, { status: "invalid" }]; + } + const payload = parsed.value; + const body = null; + + const safeId = encodeURIComponent(String(payload.id)); + const path = `/cms/pages/${safeId}/components`; + + const query = encodeFormQuery({ + page: payload.page, + limit: payload.limit, + }); + + const headers = new Headers(); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + options: client._options, + baseURL: options?.serverURL ?? client._baseURL ?? "", + operationID: "cms.pages.components.list", + oAuth2Scopes: null, + resolvedSecurity: requestSecurity, + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "5XX"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "GET", + baseURL: options?.serverURL, + path, + headers, + query, + body, + userAgent: client._options.userAgent, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return [requestRes, { status: "invalid" }]; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["4XX", "5XX"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return [doResult, { status: "request-error", request: req }]; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.ListPageComponentsResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >( + M.json(200, operations.ListPageComponentsResponse$inboundSchema, { ctype: "application/hal+json" }), + M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.fail("4XX"), + M.fail("5XX"), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return [result, { status: "complete", request: req, response }]; + } + + return [OK(result.value), { status: "complete", request: req, response }]; +} diff --git a/src/funcs/cms/pagesGet.ts b/src/funcs/cms/pagesGet.ts new file mode 100644 index 0000000..ea9c572 --- /dev/null +++ b/src/funcs/cms/pagesGet.ts @@ -0,0 +1,162 @@ +/* + * Get CMS page. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { encodeFormQuery } from "../../lib/encodings.js"; + +import * as M from "../../lib/matchers.js"; +import { safeParse } from "../../lib/schemas.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import * as errors from "../../models/errors/index.js"; +import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import * as operations from "../../models/operations/index.js"; +import { APICall, APIPromise } from "../../types/async.js"; +import { OK, Result } from "../../types/fp.js"; + +export function pagesGet( + client: ClientSDK, + request: operations.GetPageRequest, + options?: RequestOptions, +): APIPromise< + Result< + operations.GetPageResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + > +> { + return new APIPromise($do( + client, + request, + options, + )); +} + +async function $do( + client: ClientSDK, + request: operations.GetPageRequest, + options?: RequestOptions, +): Promise< + [ + Result< + operations.GetPageResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >, + APICall, + ] +> { + const parsed = safeParse( + request, + (value) => operations.GetPageRequest$outboundSchema.parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return [parsed, { status: "invalid" }]; + } + const payload = parsed.value; + const body = null; + + const safeId = encodeURIComponent(String(payload.id)); + const path = `/cms/pages/${safeId}`; + + const query = encodeFormQuery({ + include: payload.include, + }); + + const headers = new Headers(); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + options: client._options, + baseURL: options?.serverURL ?? client._baseURL ?? "", + operationID: "cms.pages.get", + oAuth2Scopes: null, + resolvedSecurity: requestSecurity, + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "5XX"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "GET", + baseURL: options?.serverURL, + path, + headers, + query, + body, + userAgent: client._options.userAgent, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return [requestRes, { status: "invalid" }]; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["4XX", "5XX"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return [doResult, { status: "request-error", request: req }]; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.GetPageResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >( + M.json(200, operations.GetPageResponse$inboundSchema, { ctype: "application/hal+json" }), + M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.fail("4XX"), + M.fail("5XX"), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return [result, { status: "complete", request: req, response }]; + } + + return [OK(result.value), { status: "complete", request: req, response }]; +} diff --git a/src/funcs/cms/pagesList.ts b/src/funcs/cms/pagesList.ts new file mode 100644 index 0000000..b5f0d1e --- /dev/null +++ b/src/funcs/cms/pagesList.ts @@ -0,0 +1,165 @@ +/* + * List CMS pages. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { encodeFormQuery } from "../../lib/encodings.js"; + +import * as M from "../../lib/matchers.js"; +import { safeParse } from "../../lib/schemas.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import * as errors from "../../models/errors/index.js"; +import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import * as operations from "../../models/operations/index.js"; +import { APICall, APIPromise } from "../../types/async.js"; +import { OK, Result } from "../../types/fp.js"; + +export function pagesList( + client: ClientSDK, + request?: operations.ListPagesRequest | undefined, + options?: RequestOptions, +): APIPromise< + Result< + operations.ListPagesResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + > +> { + return new APIPromise($do( + client, + request, + options, + )); +} + +async function $do( + client: ClientSDK, + request?: operations.ListPagesRequest | undefined, + options?: RequestOptions, +): Promise< + [ + Result< + operations.ListPagesResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >, + APICall, + ] +> { + const parsed = safeParse( + request, + (value) => operations.ListPagesRequest$outboundSchema.optional().parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return [parsed, { status: "invalid" }]; + } + const payload = parsed.value; + const body = null; + + const path = "/cms/pages"; + + const query = encodeFormQuery({ + "filter[slug]": payload?.filterSlug, + "filter[published]": payload?.filterPublished, + include: payload?.include, + page: payload?.page, + limit: payload?.limit, + }); + + const headers = new Headers(); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + options: client._options, + baseURL: options?.serverURL ?? client._baseURL ?? "", + operationID: "cms.pages.list", + oAuth2Scopes: null, + resolvedSecurity: requestSecurity, + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "5XX"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "GET", + baseURL: options?.serverURL, + path, + headers, + query, + body, + userAgent: client._options.userAgent, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return [requestRes, { status: "invalid" }]; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["4XX", "5XX"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return [doResult, { status: "request-error", request: req }]; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.ListPagesResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >( + M.json(200, operations.ListPagesResponse$inboundSchema, { ctype: "application/hal+json" }), + M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.fail("4XX"), + M.fail("5XX"), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return [result, { status: "complete", request: req, response }]; + } + + return [OK(result.value), { status: "complete", request: req, response }]; +} diff --git a/src/funcs/commerce/cartItemsCreate.ts b/src/funcs/commerce/cartItemsCreate.ts index 00a42ec..53849e3 100644 --- a/src/funcs/commerce/cartItemsCreate.ts +++ b/src/funcs/commerce/cartItemsCreate.ts @@ -1,49 +1,35 @@ /* - * Create cart item. + * Create cart item function. */ import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; import * as M from "../../lib/matchers.js"; -import { safeParse } from "../../lib/schemas.js"; -import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; -import * as errors from "../../models/errors/index.js"; -import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; -import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; import { - ConnectionError, - InvalidRequestError, - RequestAbortedError, - RequestTimeoutError, - UnexpectedClientError, -} from "../../models/errors/http-client-errors.js"; -import * as operations from "../../models/operations/index.js"; -import { CartItem$inboundSchema } from "../../models/commerce/cart-item.js"; -import { APICall, APIPromise } from "../../types/async.js"; -import { OK, Result } from "../../types/fp.js"; + encodeJSON, +} from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; export function cartItemsCreate( client: ClientSDK, request: operations.CreateCartItemRequest, options?: RequestOptions, -): APIPromise< +): Promise< Result< operations.CreateCartItemResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError > > { - return new APIPromise($do( - client, - request, - options, - )); + return $do(client, request, options); } async function $do( @@ -51,112 +37,91 @@ async function $do( request: operations.CreateCartItemRequest, options?: RequestOptions, ): Promise< - [ - Result< - operations.CreateCartItemResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError - | ConnectionError - | RequestAbortedError - | RequestTimeoutError - | InvalidRequestError - | UnexpectedClientError - | SDKValidationError - >, - APICall, - ] + Result< + operations.CreateCartItemResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > > { - const parsed = safeParse( - request, - (value) => operations.CreateCartItemRequest$outboundSchema.parse(value), - "Input validation failed", - ); - if (!parsed.ok) { - return [parsed, { status: "invalid" }]; - } - const payload = parsed.value; - - const safeCartId = encodeURIComponent(String(payload.cartId)); - const path = `/commerce/carts/${safeCartId}/items`; + const path = pathToFunc("/commerce/carts/{cartId}/items")({ + cartId: request.cartId, + }); const headers = new Headers({ "Content-Type": "application/json", + Accept: "application/hal+json", }); const securityInput = await extractSecurity(client._options.security); - const requestSecurity = resolveGlobalSecurity(securityInput); + const security = resolveGlobalSecurity(securityInput); const context = { - options: client._options, - baseURL: options?.serverURL ?? client._baseURL ?? "", - operationID: "commerce.cart-items.create", - oAuth2Scopes: null, - resolvedSecurity: requestSecurity, + operationID: "createCartItem", + oAuth2Scopes: [], securitySource: client._options.security, - retryConfig: options?.retries - || client._options.retryConfig - || { strategy: "none" }, - retryCodes: options?.retryCodes || ["429", "5XX"], + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, }; - const requestRes = client._createRequest(context, { - security: requestSecurity, - method: "POST", - baseURL: options?.serverURL, - path, - headers, - body: JSON.stringify(payload.body ?? {}), - userAgent: client._options.userAgent, - timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, - }, options); + const body = encodeJSON("body", request, { explode: true }); + + const requestRes = client._createRequest( + context, + { + security: security, + method: "POST", + path: path, + headers: headers, + body: body, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); if (!requestRes.ok) { - return [requestRes, { status: "invalid" }]; + return requestRes; } const req = requestRes.value; const doResult = await client._do(req, { context, - errorCodes: ["4XX", "5XX"], - retryConfig: context.retryConfig, - retryCodes: context.retryCodes, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }); if (!doResult.ok) { - return [doResult, { status: "request-error", request: req }]; + return doResult; } const response = doResult.value; const responseFields = { - HttpMeta: { Response: response, Request: req }, + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, }; const [result] = await M.match< operations.CreateCartItemResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError >( - M.json(200, CartItem$inboundSchema, { - ctype: "application/hal+json", - }), - M.json(201, CartItem$inboundSchema, { - ctype: "application/hal+json", - }), - M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { - ctype: "application/hal+json", - }), - M.fail("4XX"), - M.fail("5XX"), + M.json(201, operations.CreateCartItemResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) )(response, req, { extraFields: responseFields }); if (!result.ok) { - return [result, { status: "complete", request: req, response }]; + return result; } - return [OK(result.value), { status: "complete", request: req, response }]; + return result; } + diff --git a/src/funcs/commerce/cartItemsDelete.ts b/src/funcs/commerce/cartItemsDelete.ts index 28ddaf1..7ae6e1b 100644 --- a/src/funcs/commerce/cartItemsDelete.ts +++ b/src/funcs/commerce/cartItemsDelete.ts @@ -1,49 +1,32 @@ /* - * Delete cart item. + * Delete cart item function. */ import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; -import * as z from "zod/v4"; +import * as operations from "../../models/operations/index.js"; import * as M from "../../lib/matchers.js"; -import { safeParse } from "../../lib/schemas.js"; +import { pathToFunc } from "../../lib/url.js"; import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; -import * as errors from "../../models/errors/index.js"; -import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; -import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; -import { - ConnectionError, - InvalidRequestError, - RequestAbortedError, - RequestTimeoutError, - UnexpectedClientError, -} from "../../models/errors/http-client-errors.js"; -import * as operations from "../../models/operations/index.js"; -import { APICall, APIPromise } from "../../types/async.js"; -import { OK, Result } from "../../types/fp.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; export function cartItemsDelete( client: ClientSDK, request: operations.DeleteCartItemRequest, options?: RequestOptions, -): APIPromise< +): Promise< Result< operations.DeleteCartItemResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError > > { - return new APIPromise($do( - client, - request, - options, - )); + return $do(client, request, options); } async function $do( @@ -51,106 +34,88 @@ async function $do( request: operations.DeleteCartItemRequest, options?: RequestOptions, ): Promise< - [ - Result< - operations.DeleteCartItemResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError - | ConnectionError - | RequestAbortedError - | RequestTimeoutError - | InvalidRequestError - | UnexpectedClientError - | SDKValidationError - >, - APICall, - ] + Result< + operations.DeleteCartItemResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > > { - const parsed = safeParse( - request, - (value) => operations.DeleteCartItemRequest$outboundSchema.parse(value), - "Input validation failed", - ); - if (!parsed.ok) { - return [parsed, { status: "invalid" }]; - } - const payload = parsed.value; - - const safeCartId = encodeURIComponent(String(payload.cartId)); - const safeItemId = encodeURIComponent(String(payload.itemId)); - const path = `/commerce/carts/${safeCartId}/items/${safeItemId}`; + const path = pathToFunc("/commerce/cart-items/{id}")({ + id: request.itemId, + }); - const headers = new Headers(); + const headers = new Headers({ + Accept: "application/hal+json", + }); const securityInput = await extractSecurity(client._options.security); - const requestSecurity = resolveGlobalSecurity(securityInput); + const security = resolveGlobalSecurity(securityInput); const context = { - options: client._options, - baseURL: options?.serverURL ?? client._baseURL ?? "", - operationID: "commerce.cart-items.delete", - oAuth2Scopes: null, - resolvedSecurity: requestSecurity, + operationID: "deleteCartItem", + oAuth2Scopes: [], securitySource: client._options.security, - retryConfig: options?.retries - || client._options.retryConfig - || { strategy: "none" }, - retryCodes: options?.retryCodes || ["429", "5XX"], + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, }; - const requestRes = client._createRequest(context, { - security: requestSecurity, - method: "DELETE", - baseURL: options?.serverURL, - path, - headers, - userAgent: client._options.userAgent, - timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, - }, options); + const requestRes = client._createRequest( + context, + { + security: security, + method: "DELETE", + path: path, + headers: headers, + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); if (!requestRes.ok) { - return [requestRes, { status: "invalid" }]; + return requestRes; } const req = requestRes.value; const doResult = await client._do(req, { context, - errorCodes: ["4XX", "5XX"], - retryConfig: context.retryConfig, - retryCodes: context.retryCodes, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }); if (!doResult.ok) { - return [doResult, { status: "request-error", request: req }]; + return doResult; } const response = doResult.value; const responseFields = { - HttpMeta: { Response: response, Request: req }, + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, }; const [result] = await M.match< operations.DeleteCartItemResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError >( - M.nil(200, z.null()), - M.nil(204, z.null()), - M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { - ctype: "application/hal+json", - }), - M.fail("4XX"), - M.fail("5XX"), + M.nil(204, operations.DeleteCartItemResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) )(response, req, { extraFields: responseFields }); if (!result.ok) { - return [result, { status: "complete", request: req, response }]; + return result; } - return [OK(undefined), { status: "complete", request: req, response }]; + return result; } + diff --git a/src/funcs/commerce/cartItemsGet.ts b/src/funcs/commerce/cartItemsGet.ts index b32b403..8e7a6fe 100644 --- a/src/funcs/commerce/cartItemsGet.ts +++ b/src/funcs/commerce/cartItemsGet.ts @@ -1,50 +1,34 @@ /* - * Get cart item. + * Get cart item function. */ import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; -import { encodeFormQuery } from "../../lib/encodings.js"; +import * as operations from "../../models/operations/index.js"; import * as M from "../../lib/matchers.js"; -import { safeParse } from "../../lib/schemas.js"; -import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; -import * as errors from "../../models/errors/index.js"; -import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; -import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; import { - ConnectionError, - InvalidRequestError, - RequestAbortedError, - RequestTimeoutError, - UnexpectedClientError, -} from "../../models/errors/http-client-errors.js"; -import * as operations from "../../models/operations/index.js"; -import { CartItem$inboundSchema } from "../../models/commerce/cart-item.js"; -import { APICall, APIPromise } from "../../types/async.js"; -import { OK, Result } from "../../types/fp.js"; + encodeSimpleQuery, } from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; export function cartItemsGet( client: ClientSDK, request: operations.GetCartItemRequest, options?: RequestOptions, -): APIPromise< +): Promise< Result< operations.GetCartItemResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError > > { - return new APIPromise($do( - client, - request, - options, - )); + return $do(client, request, options); } async function $do( @@ -52,114 +36,95 @@ async function $do( request: operations.GetCartItemRequest, options?: RequestOptions, ): Promise< - [ - Result< - operations.GetCartItemResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError - | ConnectionError - | RequestAbortedError - | RequestTimeoutError - | InvalidRequestError - | UnexpectedClientError - | SDKValidationError - >, - APICall, - ] + Result< + operations.GetCartItemResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > > { - const parsed = safeParse( - request, - (value) => operations.GetCartItemRequest$outboundSchema.parse(value), - "Input validation failed", - ); - if (!parsed.ok) { - return [parsed, { status: "invalid" }]; - } - const payload = parsed.value; - const body = null; - - const safeCartId = encodeURIComponent(String(payload.cartId)); - const safeItemId = encodeURIComponent(String(payload.itemId)); - const path = `/commerce/carts/${safeCartId}/items/${safeItemId}`; - - const query = encodeFormQuery({ - include: payload.include, + const path = pathToFunc("/commerce/cart-items/{id}")({ + id: request.itemId, }); - const headers = new Headers(); + const headers = new Headers({ + Accept: "application/hal+json", + }); const securityInput = await extractSecurity(client._options.security); - const requestSecurity = resolveGlobalSecurity(securityInput); + const security = resolveGlobalSecurity(securityInput); + + const simpleQuery = encodeSimpleQuery({ + "include": request.include, + }); + + const finalQuery = new URLSearchParams(simpleQuery || ""); const context = { - options: client._options, - baseURL: options?.serverURL ?? client._baseURL ?? "", - operationID: "commerce.cart-items.get", - oAuth2Scopes: null, - resolvedSecurity: requestSecurity, + operationID: "getCartItem", + oAuth2Scopes: [], securitySource: client._options.security, - retryConfig: options?.retries - || client._options.retryConfig - || { strategy: "none" }, - retryCodes: options?.retryCodes || ["429", "5XX"], + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, }; - const requestRes = client._createRequest(context, { - security: requestSecurity, - method: "GET", - baseURL: options?.serverURL, - path, - headers, - query, - body, - userAgent: client._options.userAgent, - timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, - }, options); + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); if (!requestRes.ok) { - return [requestRes, { status: "invalid" }]; + return requestRes; } const req = requestRes.value; const doResult = await client._do(req, { context, - errorCodes: ["4XX", "5XX"], - retryConfig: context.retryConfig, - retryCodes: context.retryCodes, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }); if (!doResult.ok) { - return [doResult, { status: "request-error", request: req }]; + return doResult; } const response = doResult.value; const responseFields = { - HttpMeta: { Response: response, Request: req }, + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, }; const [result] = await M.match< operations.GetCartItemResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError >( - M.json(200, CartItem$inboundSchema, { - ctype: "application/hal+json", - }), - M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { - ctype: "application/hal+json", - }), - M.fail("4XX"), - M.fail("5XX"), + M.json(200, operations.GetCartItemResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) )(response, req, { extraFields: responseFields }); if (!result.ok) { - return [result, { status: "complete", request: req, response }]; + return result; } - return [OK(result.value), { status: "complete", request: req, response }]; + return result; } + diff --git a/src/funcs/commerce/cartItemsList.ts b/src/funcs/commerce/cartItemsList.ts index 64615d5..1e17e9a 100644 --- a/src/funcs/commerce/cartItemsList.ts +++ b/src/funcs/commerce/cartItemsList.ts @@ -1,55 +1,35 @@ /* - * List cart items. + * List cart items function. */ import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; import { - encodeDeepObjectQuery, - encodeFormQuery, - queryJoin, + encodeSimpleQuery, encodeDeepObjectQuery, } from "../../lib/encodings.js"; -import * as M from "../../lib/matchers.js"; -import { safeParse } from "../../lib/schemas.js"; +import { pathToFunc } from "../../lib/url.js"; import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; -import * as errors from "../../models/errors/index.js"; -import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; -import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; -import { - ConnectionError, - InvalidRequestError, - RequestAbortedError, - RequestTimeoutError, - UnexpectedClientError, -} from "../../models/errors/http-client-errors.js"; -import * as operations from "../../models/operations/index.js"; -import { CartItemsListResponse$inboundSchema } from "../../models/commerce/cart-item.js"; -import { applyPaginationParams } from "../../models/pagination.js"; -import { APICall, APIPromise } from "../../types/async.js"; -import { OK, Result } from "../../types/fp.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; export function cartItemsList( client: ClientSDK, request: operations.ListCartItemsRequest, options?: RequestOptions, -): APIPromise< +): Promise< Result< operations.ListCartItemsResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError > > { - return new APIPromise($do( - client, - request, - options, - )); + return $do(client, request, options); } async function $do( @@ -57,131 +37,104 @@ async function $do( request: operations.ListCartItemsRequest, options?: RequestOptions, ): Promise< - [ - Result< - operations.ListCartItemsResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError - | ConnectionError - | RequestAbortedError - | RequestTimeoutError - | InvalidRequestError - | UnexpectedClientError - | SDKValidationError - >, - APICall, - ] + Result< + operations.ListCartItemsResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > > { - const parsed = safeParse( - request, - (value) => operations.ListCartItemsRequest$outboundSchema.parse(value), - "Input validation failed", - ); - if (!parsed.ok) { - return [parsed, { status: "invalid" }]; - } - const payload = parsed.value; - const body = null; - - const safeCartId = encodeURIComponent(String(payload.cartId)); - const path = `/commerce/carts/${safeCartId}/items`; - - const baseQuery = encodeFormQuery({ - page: payload.page, - limit: payload.limit, - include: payload.include, - sort: payload.sort, + const path = pathToFunc("/commerce/carts/{cartId}/items")({ + cartId: request.cartId, }); - let filterQuery: string | undefined; - if (typeof payload.filter === "string") { - filterQuery = encodeFormQuery({ filter: payload.filter }); - } else if ( - payload.filter != null - && typeof payload.filter === "object" - && !Array.isArray(payload.filter) - ) { - filterQuery = encodeDeepObjectQuery({ filter: payload.filter }); - } + const headers = new Headers({ + Accept: "application/hal+json", + }); - const query = queryJoin(baseQuery, filterQuery); + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); - const headers = new Headers(); + const query = encodeDeepObjectQuery({ + "filter": request?.filter, + }); + const simpleQuery = encodeSimpleQuery({ + "include": request?.include, + "sort": request?.sort, + "page": request?.page, + "limit": request?.limit, + }); - const securityInput = await extractSecurity(client._options.security); - const requestSecurity = resolveGlobalSecurity(securityInput); + const finalQuery = new URLSearchParams(query); + new URLSearchParams(simpleQuery || "").forEach((value, key) => { + finalQuery.append(key, value); + }); const context = { - options: client._options, - baseURL: options?.serverURL ?? client._baseURL ?? "", - operationID: "commerce.cart-items.list", - oAuth2Scopes: null, - resolvedSecurity: requestSecurity, + operationID: "listCartItems", + oAuth2Scopes: [], securitySource: client._options.security, - retryConfig: options?.retries - || client._options.retryConfig - || { strategy: "none" }, - retryCodes: options?.retryCodes || ["429", "5XX"], + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, }; - const requestRes = client._createRequest(context, { - security: requestSecurity, - method: "GET", - baseURL: options?.serverURL, - path, - headers, - query, - body, - userAgent: client._options.userAgent, - timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, - }, options); + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); if (!requestRes.ok) { - return [requestRes, { status: "invalid" }]; + return requestRes; } const req = requestRes.value; const doResult = await client._do(req, { context, - errorCodes: ["4XX", "5XX"], - retryConfig: context.retryConfig, - retryCodes: context.retryCodes, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }); if (!doResult.ok) { - return [doResult, { status: "request-error", request: req }]; + return doResult; } const response = doResult.value; const responseFields = { - HttpMeta: { Response: response, Request: req }, + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, }; const [result] = await M.match< operations.ListCartItemsResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError >( - M.json(200, CartItemsListResponse$inboundSchema, { - ctype: "application/hal+json", - }), - M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { - ctype: "application/hal+json", - }), - M.fail("4XX"), - M.fail("5XX"), + M.json(200, operations.ListCartItemsResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) )(response, req, { extraFields: responseFields }); if (!result.ok) { - return [result, { status: "complete", request: req, response }]; + return result; } - const finalValue = applyPaginationParams(result.value, payload); - - return [OK(finalValue), { status: "complete", request: req, response }]; + return result; } + diff --git a/src/funcs/commerce/cartItemsUpdate.ts b/src/funcs/commerce/cartItemsUpdate.ts index df27511..dc9d99b 100644 --- a/src/funcs/commerce/cartItemsUpdate.ts +++ b/src/funcs/commerce/cartItemsUpdate.ts @@ -1,49 +1,35 @@ /* - * Update cart item. + * Update cart item function. */ import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; import * as M from "../../lib/matchers.js"; -import { safeParse } from "../../lib/schemas.js"; -import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; -import * as errors from "../../models/errors/index.js"; -import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; -import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; import { - ConnectionError, - InvalidRequestError, - RequestAbortedError, - RequestTimeoutError, - UnexpectedClientError, -} from "../../models/errors/http-client-errors.js"; -import * as operations from "../../models/operations/index.js"; -import { CartItem$inboundSchema } from "../../models/commerce/cart-item.js"; -import { APICall, APIPromise } from "../../types/async.js"; -import { OK, Result } from "../../types/fp.js"; + encodeJSON, +} from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; export function cartItemsUpdate( client: ClientSDK, request: operations.UpdateCartItemRequest, options?: RequestOptions, -): APIPromise< +): Promise< Result< operations.UpdateCartItemResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError > > { - return new APIPromise($do( - client, - request, - options, - )); + return $do(client, request, options); } async function $do( @@ -51,110 +37,91 @@ async function $do( request: operations.UpdateCartItemRequest, options?: RequestOptions, ): Promise< - [ - Result< - operations.UpdateCartItemResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError - | ConnectionError - | RequestAbortedError - | RequestTimeoutError - | InvalidRequestError - | UnexpectedClientError - | SDKValidationError - >, - APICall, - ] + Result< + operations.UpdateCartItemResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > > { - const parsed = safeParse( - request, - (value) => operations.UpdateCartItemRequest$outboundSchema.parse(value), - "Input validation failed", - ); - if (!parsed.ok) { - return [parsed, { status: "invalid" }]; - } - const payload = parsed.value; - - const safeCartId = encodeURIComponent(String(payload.cartId)); - const safeItemId = encodeURIComponent(String(payload.itemId)); - const path = `/commerce/carts/${safeCartId}/items/${safeItemId}`; + const path = pathToFunc("/commerce/cart-items/{id}")({ + id: request.itemId, + }); const headers = new Headers({ "Content-Type": "application/json", + Accept: "application/hal+json", }); const securityInput = await extractSecurity(client._options.security); - const requestSecurity = resolveGlobalSecurity(securityInput); + const security = resolveGlobalSecurity(securityInput); const context = { - options: client._options, - baseURL: options?.serverURL ?? client._baseURL ?? "", - operationID: "commerce.cart-items.update", - oAuth2Scopes: null, - resolvedSecurity: requestSecurity, + operationID: "updateCartItem", + oAuth2Scopes: [], securitySource: client._options.security, - retryConfig: options?.retries - || client._options.retryConfig - || { strategy: "none" }, - retryCodes: options?.retryCodes || ["429", "5XX"], + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, }; - const requestRes = client._createRequest(context, { - security: requestSecurity, - method: "PATCH", - baseURL: options?.serverURL, - path, - headers, - body: JSON.stringify(payload.body ?? {}), - userAgent: client._options.userAgent, - timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, - }, options); + const body = encodeJSON("body", request.data, { explode: true }); + + const requestRes = client._createRequest( + context, + { + security: security, + method: "PATCH", + path: path, + headers: headers, + body: body, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); if (!requestRes.ok) { - return [requestRes, { status: "invalid" }]; + return requestRes; } const req = requestRes.value; const doResult = await client._do(req, { context, - errorCodes: ["4XX", "5XX"], - retryConfig: context.retryConfig, - retryCodes: context.retryCodes, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }); if (!doResult.ok) { - return [doResult, { status: "request-error", request: req }]; + return doResult; } const response = doResult.value; const responseFields = { - HttpMeta: { Response: response, Request: req }, + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, }; const [result] = await M.match< operations.UpdateCartItemResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError >( - M.json(200, CartItem$inboundSchema, { - ctype: "application/hal+json", - }), - M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { - ctype: "application/hal+json", - }), - M.fail("4XX"), - M.fail("5XX"), + M.json(200, operations.UpdateCartItemResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) )(response, req, { extraFields: responseFields }); if (!result.ok) { - return [result, { status: "complete", request: req, response }]; + return result; } - return [OK(result.value), { status: "complete", request: req, response }]; + return result; } + diff --git a/src/funcs/commerce/cartsCreate.ts b/src/funcs/commerce/cartsCreate.ts index a89e489..a6ab215 100644 --- a/src/funcs/commerce/cartsCreate.ts +++ b/src/funcs/commerce/cartsCreate.ts @@ -1,49 +1,35 @@ /* - * Create cart. + * Create cart function. */ import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; import * as M from "../../lib/matchers.js"; -import { safeParse } from "../../lib/schemas.js"; -import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; -import * as errors from "../../models/errors/index.js"; -import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; -import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; import { - ConnectionError, - InvalidRequestError, - RequestAbortedError, - RequestTimeoutError, - UnexpectedClientError, -} from "../../models/errors/http-client-errors.js"; -import * as operations from "../../models/operations/index.js"; -import { Cart$inboundSchema } from "../../models/commerce/cart.js"; -import { APICall, APIPromise } from "../../types/async.js"; -import { OK, Result } from "../../types/fp.js"; + encodeJSON, +} from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; export function cartsCreate( client: ClientSDK, request: operations.CreateCartRequest, options?: RequestOptions, -): APIPromise< +): Promise< Result< operations.CreateCartResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError > > { - return new APIPromise($do( - client, - request, - options, - )); + return $do(client, request, options); } async function $do( @@ -51,111 +37,89 @@ async function $do( request: operations.CreateCartRequest, options?: RequestOptions, ): Promise< - [ - Result< - operations.CreateCartResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError - | ConnectionError - | RequestAbortedError - | RequestTimeoutError - | InvalidRequestError - | UnexpectedClientError - | SDKValidationError - >, - APICall, - ] + Result< + operations.CreateCartResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > > { - const parsed = safeParse( - request, - (value) => operations.CreateCartRequest$outboundSchema.parse(value), - "Input validation failed", - ); - if (!parsed.ok) { - return [parsed, { status: "invalid" }]; - } - const payload = parsed.value; - - const path = "/commerce/carts"; + const path = pathToFunc("/commerce/carts")(); const headers = new Headers({ "Content-Type": "application/json", + Accept: "application/hal+json", }); const securityInput = await extractSecurity(client._options.security); - const requestSecurity = resolveGlobalSecurity(securityInput); + const security = resolveGlobalSecurity(securityInput); const context = { - options: client._options, - baseURL: options?.serverURL ?? client._baseURL ?? "", - operationID: "commerce.carts.create", - oAuth2Scopes: null, - resolvedSecurity: requestSecurity, + operationID: "createCart", + oAuth2Scopes: [], securitySource: client._options.security, - retryConfig: options?.retries - || client._options.retryConfig - || { strategy: "none" }, - retryCodes: options?.retryCodes || ["429", "5XX"], + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, }; - const requestRes = client._createRequest(context, { - security: requestSecurity, - method: "POST", - baseURL: options?.serverURL, - path, - headers, - body: JSON.stringify(payload), - userAgent: client._options.userAgent, - timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, - }, options); + const body = encodeJSON("body", request, { explode: true }); + + const requestRes = client._createRequest( + context, + { + security: security, + method: "POST", + path: path, + headers: headers, + body: body, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); if (!requestRes.ok) { - return [requestRes, { status: "invalid" }]; + return requestRes; } const req = requestRes.value; const doResult = await client._do(req, { context, - errorCodes: ["4XX", "5XX"], - retryConfig: context.retryConfig, - retryCodes: context.retryCodes, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }); if (!doResult.ok) { - return [doResult, { status: "request-error", request: req }]; + return doResult; } const response = doResult.value; const responseFields = { - HttpMeta: { Response: response, Request: req }, + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, }; const [result] = await M.match< operations.CreateCartResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError >( - M.json(200, Cart$inboundSchema, { - ctype: "application/hal+json", - }), - M.json(201, Cart$inboundSchema, { - ctype: "application/hal+json", - }), - M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { - ctype: "application/hal+json", - }), - M.fail("4XX"), - M.fail("5XX"), + M.json(201, operations.CreateCartResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) )(response, req, { extraFields: responseFields }); if (!result.ok) { - return [result, { status: "complete", request: req, response }]; + return result; } - return [OK(result.value), { status: "complete", request: req, response }]; + return result; } + diff --git a/src/funcs/commerce/cartsGet.ts b/src/funcs/commerce/cartsGet.ts index f99eb4d..e16db2a 100644 --- a/src/funcs/commerce/cartsGet.ts +++ b/src/funcs/commerce/cartsGet.ts @@ -1,50 +1,34 @@ /* - * Get cart. + * Get cart function. */ import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; -import { encodeFormQuery } from "../../lib/encodings.js"; +import * as operations from "../../models/operations/index.js"; import * as M from "../../lib/matchers.js"; -import { safeParse } from "../../lib/schemas.js"; -import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; -import * as errors from "../../models/errors/index.js"; -import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; -import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; import { - ConnectionError, - InvalidRequestError, - RequestAbortedError, - RequestTimeoutError, - UnexpectedClientError, -} from "../../models/errors/http-client-errors.js"; -import * as operations from "../../models/operations/index.js"; -import { Cart$inboundSchema } from "../../models/commerce/cart.js"; -import { APICall, APIPromise } from "../../types/async.js"; -import { OK, Result } from "../../types/fp.js"; + encodeSimpleQuery, } from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; export function cartsGet( client: ClientSDK, request: operations.GetCartRequest, options?: RequestOptions, -): APIPromise< +): Promise< Result< operations.GetCartResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError > > { - return new APIPromise($do( - client, - request, - options, - )); + return $do(client, request, options); } async function $do( @@ -52,113 +36,95 @@ async function $do( request: operations.GetCartRequest, options?: RequestOptions, ): Promise< - [ - Result< - operations.GetCartResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError - | ConnectionError - | RequestAbortedError - | RequestTimeoutError - | InvalidRequestError - | UnexpectedClientError - | SDKValidationError - >, - APICall, - ] + Result< + operations.GetCartResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > > { - const parsed = safeParse( - request, - (value) => operations.GetCartRequest$outboundSchema.parse(value), - "Input validation failed", - ); - if (!parsed.ok) { - return [parsed, { status: "invalid" }]; - } - const payload = parsed.value; - const body = null; - - const safeId = encodeURIComponent(String(payload.id)); - const path = `/commerce/carts/${safeId}`; - - const query = encodeFormQuery({ - include: payload.include, + const path = pathToFunc("/commerce/carts/{id}")({ + id: request.id, }); - const headers = new Headers(); + const headers = new Headers({ + Accept: "application/hal+json", + }); const securityInput = await extractSecurity(client._options.security); - const requestSecurity = resolveGlobalSecurity(securityInput); + const security = resolveGlobalSecurity(securityInput); + + const simpleQuery = encodeSimpleQuery({ + "include": request.include, + }); + + const finalQuery = new URLSearchParams(simpleQuery || ""); const context = { - options: client._options, - baseURL: options?.serverURL ?? client._baseURL ?? "", - operationID: "commerce.carts.get", - oAuth2Scopes: null, - resolvedSecurity: requestSecurity, + operationID: "getCart", + oAuth2Scopes: [], securitySource: client._options.security, - retryConfig: options?.retries - || client._options.retryConfig - || { strategy: "none" }, - retryCodes: options?.retryCodes || ["429", "5XX"], + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, }; - const requestRes = client._createRequest(context, { - security: requestSecurity, - method: "GET", - baseURL: options?.serverURL, - path, - headers, - query, - body, - userAgent: client._options.userAgent, - timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, - }, options); + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); if (!requestRes.ok) { - return [requestRes, { status: "invalid" }]; + return requestRes; } const req = requestRes.value; const doResult = await client._do(req, { context, - errorCodes: ["4XX", "5XX"], - retryConfig: context.retryConfig, - retryCodes: context.retryCodes, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }); if (!doResult.ok) { - return [doResult, { status: "request-error", request: req }]; + return doResult; } const response = doResult.value; const responseFields = { - HttpMeta: { Response: response, Request: req }, + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, }; const [result] = await M.match< operations.GetCartResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError >( - M.json(200, Cart$inboundSchema, { - ctype: "application/hal+json", - }), - M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { - ctype: "application/hal+json", - }), - M.fail("4XX"), - M.fail("5XX"), + M.json(200, operations.GetCartResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) )(response, req, { extraFields: responseFields }); if (!result.ok) { - return [result, { status: "complete", request: req, response }]; + return result; } - return [OK(result.value), { status: "complete", request: req, response }]; + return result; } + diff --git a/src/funcs/commerce/cartsList.ts b/src/funcs/commerce/cartsList.ts index e99cdc1..4041d03 100644 --- a/src/funcs/commerce/cartsList.ts +++ b/src/funcs/commerce/cartsList.ts @@ -1,187 +1,138 @@ /* - * List carts. + * List carts function. */ import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; import { - encodeDeepObjectQuery, - encodeFormQuery, - queryJoin, + encodeSimpleQuery, encodeDeepObjectQuery, } from "../../lib/encodings.js"; -import * as M from "../../lib/matchers.js"; -import { safeParse } from "../../lib/schemas.js"; +import { pathToFunc } from "../../lib/url.js"; import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; -import * as errors from "../../models/errors/index.js"; -import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; -import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; -import { - ConnectionError, - InvalidRequestError, - RequestAbortedError, - RequestTimeoutError, - UnexpectedClientError, -} from "../../models/errors/http-client-errors.js"; -import * as operations from "../../models/operations/index.js"; -import { CartsListResponse$inboundSchema } from "../../models/commerce/cart.js"; -import { applyPaginationParams } from "../../models/pagination.js"; -import { APICall, APIPromise } from "../../types/async.js"; -import { OK, Result } from "../../types/fp.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; export function cartsList( client: ClientSDK, - request?: operations.CartsListParams | undefined, + request?: operations.ListCartsRequest | undefined, options?: RequestOptions, -): APIPromise< +): Promise< Result< operations.ListCartsResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError > > { - return new APIPromise($do( - client, - request, - options, - )); + return $do(client, request, options); } async function $do( client: ClientSDK, - request?: operations.CartsListParams | undefined, + request?: operations.ListCartsRequest | undefined, options?: RequestOptions, ): Promise< - [ - Result< - operations.ListCartsResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError - | ConnectionError - | RequestAbortedError - | RequestTimeoutError - | InvalidRequestError - | UnexpectedClientError - | SDKValidationError - >, - APICall, - ] + Result< + operations.ListCartsResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > > { - const parsed = safeParse( - request, - (value) => - operations.CartsListParams$outboundSchema.optional().parse(value), - "Input validation failed", - ); - if (!parsed.ok) { - return [parsed, { status: "invalid" }]; - } - const payload = parsed.value; - const body = null; - - const path = "/commerce/carts"; + const path = pathToFunc("/commerce/carts")(); - const baseQuery = encodeFormQuery({ - page: payload?.page, - limit: payload?.limit, - include: payload?.include, - sort: payload?.sort, + const headers = new Headers({ + Accept: "application/hal+json", }); - let filterQuery: string | undefined; - if (typeof payload?.filter === "string") { - filterQuery = encodeFormQuery({ filter: payload.filter }); - } else if ( - payload?.filter != null - && typeof payload.filter === "object" - && !Array.isArray(payload.filter) - ) { - filterQuery = encodeDeepObjectQuery({ filter: payload.filter }); - } - - const query = queryJoin(baseQuery, filterQuery); + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); - const headers = new Headers(); + const query = encodeDeepObjectQuery({ + "filter": request?.filter, + }); + const simpleQuery = encodeSimpleQuery({ + "include": request?.include, + "sort": request?.sort, + "page": request?.page, + "limit": request?.limit, + }); - const securityInput = await extractSecurity(client._options.security); - const requestSecurity = resolveGlobalSecurity(securityInput); + const finalQuery = new URLSearchParams(query); + new URLSearchParams(simpleQuery || "").forEach((value, key) => { + finalQuery.append(key, value); + }); const context = { - options: client._options, - baseURL: options?.serverURL ?? client._baseURL ?? "", - operationID: "commerce.carts.list", - oAuth2Scopes: null, - resolvedSecurity: requestSecurity, + operationID: "listCarts", + oAuth2Scopes: [], securitySource: client._options.security, - retryConfig: options?.retries - || client._options.retryConfig - || { strategy: "none" }, - retryCodes: options?.retryCodes || ["429", "5XX"], + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, }; - const requestRes = client._createRequest(context, { - security: requestSecurity, - method: "GET", - baseURL: options?.serverURL, - path, - headers, - query, - body, - userAgent: client._options.userAgent, - timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, - }, options); + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); if (!requestRes.ok) { - return [requestRes, { status: "invalid" }]; + return requestRes; } const req = requestRes.value; const doResult = await client._do(req, { context, - errorCodes: ["4XX", "5XX"], - retryConfig: context.retryConfig, - retryCodes: context.retryCodes, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }); if (!doResult.ok) { - return [doResult, { status: "request-error", request: req }]; + return doResult; } const response = doResult.value; const responseFields = { - HttpMeta: { Response: response, Request: req }, + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, }; const [result] = await M.match< operations.ListCartsResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError >( - M.json(200, CartsListResponse$inboundSchema, { - ctype: "application/hal+json", - }), - M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { - ctype: "application/hal+json", - }), - M.fail("4XX"), - M.fail("5XX"), + M.json(200, operations.ListCartsResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) )(response, req, { extraFields: responseFields }); if (!result.ok) { - return [result, { status: "complete", request: req, response }]; + return result; } - const finalValue = applyPaginationParams(result.value, payload); - - return [OK(finalValue), { status: "complete", request: req, response }]; + return result; } + diff --git a/src/funcs/commerce/cartsUpdate.ts b/src/funcs/commerce/cartsUpdate.ts index fd20047..926cf0a 100644 --- a/src/funcs/commerce/cartsUpdate.ts +++ b/src/funcs/commerce/cartsUpdate.ts @@ -1,49 +1,35 @@ /* - * Update cart. + * Update cart function. */ import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; import * as M from "../../lib/matchers.js"; -import { safeParse } from "../../lib/schemas.js"; -import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; -import * as errors from "../../models/errors/index.js"; -import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; -import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; import { - ConnectionError, - InvalidRequestError, - RequestAbortedError, - RequestTimeoutError, - UnexpectedClientError, -} from "../../models/errors/http-client-errors.js"; -import * as operations from "../../models/operations/index.js"; -import { Cart$inboundSchema } from "../../models/commerce/cart.js"; -import { APICall, APIPromise } from "../../types/async.js"; -import { OK, Result } from "../../types/fp.js"; + encodeJSON, +} from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; export function cartsUpdate( client: ClientSDK, request: operations.UpdateCartRequest, options?: RequestOptions, -): APIPromise< +): Promise< Result< operations.UpdateCartResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError > > { - return new APIPromise($do( - client, - request, - options, - )); + return $do(client, request, options); } async function $do( @@ -51,109 +37,91 @@ async function $do( request: operations.UpdateCartRequest, options?: RequestOptions, ): Promise< - [ - Result< - operations.UpdateCartResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError - | ConnectionError - | RequestAbortedError - | RequestTimeoutError - | InvalidRequestError - | UnexpectedClientError - | SDKValidationError - >, - APICall, - ] + Result< + operations.UpdateCartResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > > { - const parsed = safeParse( - request, - (value) => operations.UpdateCartRequest$outboundSchema.parse(value), - "Input validation failed", - ); - if (!parsed.ok) { - return [parsed, { status: "invalid" }]; - } - const payload = parsed.value; - - const safeId = encodeURIComponent(String(payload.id)); - const path = `/commerce/carts/${safeId}`; + const path = pathToFunc("/commerce/carts/{id}")({ + id: request.id, + }); const headers = new Headers({ "Content-Type": "application/json", + Accept: "application/hal+json", }); const securityInput = await extractSecurity(client._options.security); - const requestSecurity = resolveGlobalSecurity(securityInput); + const security = resolveGlobalSecurity(securityInput); const context = { - options: client._options, - baseURL: options?.serverURL ?? client._baseURL ?? "", - operationID: "commerce.carts.update", - oAuth2Scopes: null, - resolvedSecurity: requestSecurity, + operationID: "updateCart", + oAuth2Scopes: [], securitySource: client._options.security, - retryConfig: options?.retries - || client._options.retryConfig - || { strategy: "none" }, - retryCodes: options?.retryCodes || ["429", "5XX"], + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, }; - const requestRes = client._createRequest(context, { - security: requestSecurity, - method: "PATCH", - baseURL: options?.serverURL, - path, - headers, - body: JSON.stringify(payload.body ?? {}), - userAgent: client._options.userAgent, - timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, - }, options); + const body = encodeJSON("body", request.data, { explode: true }); + + const requestRes = client._createRequest( + context, + { + security: security, + method: "PATCH", + path: path, + headers: headers, + body: body, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); if (!requestRes.ok) { - return [requestRes, { status: "invalid" }]; + return requestRes; } const req = requestRes.value; const doResult = await client._do(req, { context, - errorCodes: ["4XX", "5XX"], - retryConfig: context.retryConfig, - retryCodes: context.retryCodes, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }); if (!doResult.ok) { - return [doResult, { status: "request-error", request: req }]; + return doResult; } const response = doResult.value; const responseFields = { - HttpMeta: { Response: response, Request: req }, + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, }; const [result] = await M.match< operations.UpdateCartResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError >( - M.json(200, Cart$inboundSchema, { - ctype: "application/hal+json", - }), - M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { - ctype: "application/hal+json", - }), - M.fail("4XX"), - M.fail("5XX"), + M.json(200, operations.UpdateCartResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) )(response, req, { extraFields: responseFields }); if (!result.ok) { - return [result, { status: "complete", request: req, response }]; + return result; } - return [OK(result.value), { status: "complete", request: req, response }]; + return result; } + diff --git a/src/funcs/commerce/categoriesGet.ts b/src/funcs/commerce/categoriesGet.ts index 2874c15..54f8910 100644 --- a/src/funcs/commerce/categoriesGet.ts +++ b/src/funcs/commerce/categoriesGet.ts @@ -1,50 +1,34 @@ /* - * Get category. + * Get category function. */ import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; -import { encodeFormQuery } from "../../lib/encodings.js"; +import * as operations from "../../models/operations/index.js"; import * as M from "../../lib/matchers.js"; -import { safeParse } from "../../lib/schemas.js"; -import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; -import * as errors from "../../models/errors/index.js"; -import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; -import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; import { - ConnectionError, - InvalidRequestError, - RequestAbortedError, - RequestTimeoutError, - UnexpectedClientError, -} from "../../models/errors/http-client-errors.js"; -import * as operations from "../../models/operations/index.js"; -import { Category$inboundSchema } from "../../models/commerce/category.js"; -import { APICall, APIPromise } from "../../types/async.js"; -import { OK, Result } from "../../types/fp.js"; + encodeSimpleQuery, } from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; export function categoriesGet( client: ClientSDK, request: operations.GetCategoryRequest, options?: RequestOptions, -): APIPromise< +): Promise< Result< operations.GetCategoryResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError > > { - return new APIPromise($do( - client, - request, - options, - )); + return $do(client, request, options); } async function $do( @@ -52,113 +36,95 @@ async function $do( request: operations.GetCategoryRequest, options?: RequestOptions, ): Promise< - [ - Result< - operations.GetCategoryResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError - | ConnectionError - | RequestAbortedError - | RequestTimeoutError - | InvalidRequestError - | UnexpectedClientError - | SDKValidationError - >, - APICall, - ] + Result< + operations.GetCategoryResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > > { - const parsed = safeParse( - request, - (value) => operations.GetCategoryRequest$outboundSchema.parse(value), - "Input validation failed", - ); - if (!parsed.ok) { - return [parsed, { status: "invalid" }]; - } - const payload = parsed.value; - const body = null; - - const safeId = encodeURIComponent(String(payload.id)); - const path = `/commerce/categories/${safeId}`; - - const query = encodeFormQuery({ - include: payload.include, + const path = pathToFunc("/commerce/categories/{id}")({ + id: request.id, }); - const headers = new Headers(); + const headers = new Headers({ + Accept: "application/hal+json", + }); const securityInput = await extractSecurity(client._options.security); - const requestSecurity = resolveGlobalSecurity(securityInput); + const security = resolveGlobalSecurity(securityInput); + + const simpleQuery = encodeSimpleQuery({ + "include": request.include, + }); + + const finalQuery = new URLSearchParams(simpleQuery || ""); const context = { - options: client._options, - baseURL: options?.serverURL ?? client._baseURL ?? "", - operationID: "commerce.categories.get", - oAuth2Scopes: null, - resolvedSecurity: requestSecurity, + operationID: "getCategory", + oAuth2Scopes: [], securitySource: client._options.security, - retryConfig: options?.retries - || client._options.retryConfig - || { strategy: "none" }, - retryCodes: options?.retryCodes || ["429", "5XX"], + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, }; - const requestRes = client._createRequest(context, { - security: requestSecurity, - method: "GET", - baseURL: options?.serverURL, - path, - headers, - query, - body, - userAgent: client._options.userAgent, - timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, - }, options); + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); if (!requestRes.ok) { - return [requestRes, { status: "invalid" }]; + return requestRes; } const req = requestRes.value; const doResult = await client._do(req, { context, - errorCodes: ["4XX", "5XX"], - retryConfig: context.retryConfig, - retryCodes: context.retryCodes, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }); if (!doResult.ok) { - return [doResult, { status: "request-error", request: req }]; + return doResult; } const response = doResult.value; const responseFields = { - HttpMeta: { Response: response, Request: req }, + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, }; const [result] = await M.match< operations.GetCategoryResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError >( - M.json(200, Category$inboundSchema, { - ctype: "application/hal+json", - }), - M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { - ctype: "application/hal+json", - }), - M.fail("4XX"), - M.fail("5XX"), + M.json(200, operations.GetCategoryResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) )(response, req, { extraFields: responseFields }); if (!result.ok) { - return [result, { status: "complete", request: req, response }]; + return result; } - return [OK(result.value), { status: "complete", request: req, response }]; + return result; } + diff --git a/src/funcs/commerce/categoriesList.ts b/src/funcs/commerce/categoriesList.ts index 36e41ab..e5fa549 100644 --- a/src/funcs/commerce/categoriesList.ts +++ b/src/funcs/commerce/categoriesList.ts @@ -1,187 +1,138 @@ /* - * List categories. + * List categories function. */ import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; import { - encodeDeepObjectQuery, - encodeFormQuery, - queryJoin, + encodeSimpleQuery, encodeDeepObjectQuery, } from "../../lib/encodings.js"; -import * as M from "../../lib/matchers.js"; -import { safeParse } from "../../lib/schemas.js"; +import { pathToFunc } from "../../lib/url.js"; import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; -import * as errors from "../../models/errors/index.js"; -import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; -import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; -import { - ConnectionError, - InvalidRequestError, - RequestAbortedError, - RequestTimeoutError, - UnexpectedClientError, -} from "../../models/errors/http-client-errors.js"; -import * as operations from "../../models/operations/index.js"; -import { CategoriesListResponse$inboundSchema } from "../../models/commerce/category.js"; -import { applyPaginationParams } from "../../models/pagination.js"; -import { APICall, APIPromise } from "../../types/async.js"; -import { OK, Result } from "../../types/fp.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; export function categoriesList( client: ClientSDK, - request?: operations.CategoriesListParams | undefined, + request?: operations.ListCategoriesRequest | undefined, options?: RequestOptions, -): APIPromise< +): Promise< Result< operations.ListCategoriesResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError > > { - return new APIPromise($do( - client, - request, - options, - )); + return $do(client, request, options); } async function $do( client: ClientSDK, - request?: operations.CategoriesListParams | undefined, + request?: operations.ListCategoriesRequest | undefined, options?: RequestOptions, ): Promise< - [ - Result< - operations.ListCategoriesResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError - | ConnectionError - | RequestAbortedError - | RequestTimeoutError - | InvalidRequestError - | UnexpectedClientError - | SDKValidationError - >, - APICall, - ] + Result< + operations.ListCategoriesResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > > { - const parsed = safeParse( - request, - (value) => - operations.CategoriesListParams$outboundSchema.optional().parse(value), - "Input validation failed", - ); - if (!parsed.ok) { - return [parsed, { status: "invalid" }]; - } - const payload = parsed.value; - const body = null; - - const path = "/commerce/categories"; + const path = pathToFunc("/commerce/categories")(); - const baseQuery = encodeFormQuery({ - page: payload?.page, - limit: payload?.limit, - include: payload?.include, - sort: payload?.sort, + const headers = new Headers({ + Accept: "application/hal+json", }); - let filterQuery: string | undefined; - if (typeof payload?.filter === "string") { - filterQuery = encodeFormQuery({ filter: payload.filter }); - } else if ( - payload?.filter != null - && typeof payload.filter === "object" - && !Array.isArray(payload.filter) - ) { - filterQuery = encodeDeepObjectQuery({ filter: payload.filter }); - } - - const query = queryJoin(baseQuery, filterQuery); + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); - const headers = new Headers(); + const query = encodeDeepObjectQuery({ + "filter": request?.filter, + }); + const simpleQuery = encodeSimpleQuery({ + "include": request?.include, + "sort": request?.sort, + "page": request?.page, + "limit": request?.limit, + }); - const securityInput = await extractSecurity(client._options.security); - const requestSecurity = resolveGlobalSecurity(securityInput); + const finalQuery = new URLSearchParams(query); + new URLSearchParams(simpleQuery || "").forEach((value, key) => { + finalQuery.append(key, value); + }); const context = { - options: client._options, - baseURL: options?.serverURL ?? client._baseURL ?? "", - operationID: "commerce.categories.list", - oAuth2Scopes: null, - resolvedSecurity: requestSecurity, + operationID: "listCategories", + oAuth2Scopes: [], securitySource: client._options.security, - retryConfig: options?.retries - || client._options.retryConfig - || { strategy: "none" }, - retryCodes: options?.retryCodes || ["429", "5XX"], + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, }; - const requestRes = client._createRequest(context, { - security: requestSecurity, - method: "GET", - baseURL: options?.serverURL, - path, - headers, - query, - body, - userAgent: client._options.userAgent, - timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, - }, options); + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); if (!requestRes.ok) { - return [requestRes, { status: "invalid" }]; + return requestRes; } const req = requestRes.value; const doResult = await client._do(req, { context, - errorCodes: ["4XX", "5XX"], - retryConfig: context.retryConfig, - retryCodes: context.retryCodes, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }); if (!doResult.ok) { - return [doResult, { status: "request-error", request: req }]; + return doResult; } const response = doResult.value; const responseFields = { - HttpMeta: { Response: response, Request: req }, + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, }; const [result] = await M.match< operations.ListCategoriesResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError >( - M.json(200, CategoriesListResponse$inboundSchema, { - ctype: "application/hal+json", - }), - M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { - ctype: "application/hal+json", - }), - M.fail("4XX"), - M.fail("5XX"), + M.json(200, operations.ListCategoriesResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) )(response, req, { extraFields: responseFields }); if (!result.ok) { - return [result, { status: "complete", request: req, response }]; + return result; } - const finalValue = applyPaginationParams(result.value, payload); - - return [OK(finalValue), { status: "complete", request: req, response }]; + return result; } + diff --git a/src/funcs/commerce/currenciesGet.ts b/src/funcs/commerce/currenciesGet.ts new file mode 100644 index 0000000..abe4b3a --- /dev/null +++ b/src/funcs/commerce/currenciesGet.ts @@ -0,0 +1,130 @@ +/* + * Get currency function. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; +import { + encodeSimpleQuery, } from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; + +export function currenciesGet( + client: ClientSDK, + request: operations.GetCurrencyRequest, + options?: RequestOptions, +): Promise< + Result< + operations.GetCurrencyResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + return $do(client, request, options); +} + +async function $do( + client: ClientSDK, + request: operations.GetCurrencyRequest, + options?: RequestOptions, +): Promise< + Result< + operations.GetCurrencyResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + const path = pathToFunc("/commerce/currencies/{code}")({ + code: request.code, + }); + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); + + const simpleQuery = encodeSimpleQuery({ + "include": request.include, + }); + + const finalQuery = new URLSearchParams(simpleQuery || ""); + + const context = { + operationID: "getCurrency", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, + }; + + const [result] = await M.match< + operations.GetCurrencyResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + >( + M.json(200, operations.GetCurrencyResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} + diff --git a/src/funcs/commerce/currenciesList.ts b/src/funcs/commerce/currenciesList.ts new file mode 100644 index 0000000..8db500e --- /dev/null +++ b/src/funcs/commerce/currenciesList.ts @@ -0,0 +1,138 @@ +/* + * List currencies function. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; +import { + encodeSimpleQuery, encodeDeepObjectQuery, +} from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; + +export function currenciesList( + client: ClientSDK, + request?: operations.ListCurrenciesRequest | undefined, + options?: RequestOptions, +): Promise< + Result< + operations.ListCurrenciesResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + return $do(client, request, options); +} + +async function $do( + client: ClientSDK, + request?: operations.ListCurrenciesRequest | undefined, + options?: RequestOptions, +): Promise< + Result< + operations.ListCurrenciesResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + const path = pathToFunc("/commerce/currencies")(); + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); + + const query = encodeDeepObjectQuery({ + "filter": request?.filter, + }); + const simpleQuery = encodeSimpleQuery({ + "include": request?.include, + "sort": request?.sort, + "page": request?.page, + "limit": request?.limit, + }); + + const finalQuery = new URLSearchParams(query); + new URLSearchParams(simpleQuery || "").forEach((value, key) => { + finalQuery.append(key, value); + }); + + const context = { + operationID: "listCurrencies", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, + }; + + const [result] = await M.match< + operations.ListCurrenciesResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + >( + M.json(200, operations.ListCurrenciesResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} + diff --git a/src/funcs/commerce/index.ts b/src/funcs/commerce/index.ts new file mode 100644 index 0000000..73eb5e4 --- /dev/null +++ b/src/funcs/commerce/index.ts @@ -0,0 +1,38 @@ +export * from "./invoicesList.js"; +export * from "./invoicesGet.js"; +export * from "./productsList.js"; +export * from "./productsGet.js"; +export * from "./productsOffersList.js"; +export * from "./productGroupsList.js"; +export * from "./productGroupsGet.js"; +export * from "./subscriptionIntervalsList.js"; +export * from "./subscriptionIntervalsGet.js"; +export * from "./categoriesList.js"; +export * from "./categoriesGet.js"; +export * from "./cartItemsCreate.js"; +export * from "./cartItemsDelete.js"; +export * from "./cartItemsGet.js"; +export * from "./cartItemsList.js"; +export * from "./cartItemsUpdate.js"; +export * from "./cartsCreate.js"; +export * from "./cartsGet.js"; +export * from "./cartsList.js"; +export * from "./cartsUpdate.js"; +export * from "./ordersList.js"; +export * from "./ordersGet.js"; +export * from "./ordersCreate.js"; +export * from "./ordersUpdate.js"; +export * from "./ordersPaymentsList.js"; +export * from "./paymentsGet.js"; +export * from "./vatValidationsGet.js"; +export * from "./shippingMethodsList.js"; +export * from "./shippingMethodsGet.js"; +export * from "./shippingZonesList.js"; +export * from "./shippingZonesGet.js"; +export * from "./reviewsList.js"; +export * from "./reviewsGet.js"; +export * from "./reviewsCreate.js"; +export * from "./reviewsUpdate.js"; +export * from "./currenciesList.js"; +export * from "./currenciesGet.js"; + diff --git a/src/funcs/commerce/invoicesGet.ts b/src/funcs/commerce/invoicesGet.ts new file mode 100644 index 0000000..5e2b835 --- /dev/null +++ b/src/funcs/commerce/invoicesGet.ts @@ -0,0 +1,130 @@ +/* + * Get invoice function. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; +import { + encodeSimpleQuery, } from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; + +export function invoicesGet( + client: ClientSDK, + request: operations.GetInvoiceRequest, + options?: RequestOptions, +): Promise< + Result< + operations.GetInvoiceResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + return $do(client, request, options); +} + +async function $do( + client: ClientSDK, + request: operations.GetInvoiceRequest, + options?: RequestOptions, +): Promise< + Result< + operations.GetInvoiceResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + const path = pathToFunc("/commerce/invoices/{id}")({ + id: request.id, + }); + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); + + const simpleQuery = encodeSimpleQuery({ + "include": request.include, + }); + + const finalQuery = new URLSearchParams(simpleQuery || ""); + + const context = { + operationID: "getInvoice", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, + }; + + const [result] = await M.match< + operations.GetInvoiceResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + >( + M.json(200, operations.GetInvoiceResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} + diff --git a/src/funcs/commerce/invoicesList.ts b/src/funcs/commerce/invoicesList.ts new file mode 100644 index 0000000..4b610af --- /dev/null +++ b/src/funcs/commerce/invoicesList.ts @@ -0,0 +1,138 @@ +/* + * List invoices function. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; +import { + encodeSimpleQuery, encodeDeepObjectQuery, +} from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; + +export function invoicesList( + client: ClientSDK, + request?: operations.ListInvoicesRequest | undefined, + options?: RequestOptions, +): Promise< + Result< + operations.ListInvoicesResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + return $do(client, request, options); +} + +async function $do( + client: ClientSDK, + request?: operations.ListInvoicesRequest | undefined, + options?: RequestOptions, +): Promise< + Result< + operations.ListInvoicesResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + const path = pathToFunc("/commerce/invoices")(); + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); + + const query = encodeDeepObjectQuery({ + "filter": request?.filter, + }); + const simpleQuery = encodeSimpleQuery({ + "include": request?.include, + "sort": request?.sort, + "page": request?.page, + "limit": request?.limit, + }); + + const finalQuery = new URLSearchParams(query); + new URLSearchParams(simpleQuery || "").forEach((value, key) => { + finalQuery.append(key, value); + }); + + const context = { + operationID: "listInvoices", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, + }; + + const [result] = await M.match< + operations.ListInvoicesResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + >( + M.json(200, operations.ListInvoicesResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} + diff --git a/src/funcs/commerce/ordersCreate.ts b/src/funcs/commerce/ordersCreate.ts new file mode 100644 index 0000000..9215769 --- /dev/null +++ b/src/funcs/commerce/ordersCreate.ts @@ -0,0 +1,125 @@ +/* + * Create order function. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; +import { + encodeJSON, +} from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; + +export function ordersCreate( + client: ClientSDK, + request: operations.CreateOrderRequest, + options?: RequestOptions, +): Promise< + Result< + operations.CreateOrderResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + return $do(client, request, options); +} + +async function $do( + client: ClientSDK, + request: operations.CreateOrderRequest, + options?: RequestOptions, +): Promise< + Result< + operations.CreateOrderResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + const path = pathToFunc("/commerce/orders")(); + + const headers = new Headers({ + "Content-Type": "application/json", + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); + + const context = { + operationID: "createOrder", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const body = encodeJSON("body", request, { explode: true }); + + const requestRes = client._createRequest( + context, + { + security: security, + method: "POST", + path: path, + headers: headers, + body: body, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, + }; + + const [result] = await M.match< + operations.CreateOrderResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + >( + M.json(201, operations.CreateOrderResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} + diff --git a/src/funcs/commerce/ordersGet.ts b/src/funcs/commerce/ordersGet.ts new file mode 100644 index 0000000..8720d6a --- /dev/null +++ b/src/funcs/commerce/ordersGet.ts @@ -0,0 +1,130 @@ +/* + * Get order function. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; +import { + encodeSimpleQuery, } from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; + +export function ordersGet( + client: ClientSDK, + request: operations.GetOrderRequest, + options?: RequestOptions, +): Promise< + Result< + operations.GetOrderResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + return $do(client, request, options); +} + +async function $do( + client: ClientSDK, + request: operations.GetOrderRequest, + options?: RequestOptions, +): Promise< + Result< + operations.GetOrderResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + const path = pathToFunc("/commerce/orders/{id}")({ + id: request.id, + }); + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); + + const simpleQuery = encodeSimpleQuery({ + "include": request.include, + }); + + const finalQuery = new URLSearchParams(simpleQuery || ""); + + const context = { + operationID: "getOrder", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, + }; + + const [result] = await M.match< + operations.GetOrderResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + >( + M.json(200, operations.GetOrderResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} + diff --git a/src/funcs/commerce/ordersList.ts b/src/funcs/commerce/ordersList.ts new file mode 100644 index 0000000..6c85b5b --- /dev/null +++ b/src/funcs/commerce/ordersList.ts @@ -0,0 +1,138 @@ +/* + * List orders function. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; +import { + encodeSimpleQuery, encodeDeepObjectQuery, +} from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; + +export function ordersList( + client: ClientSDK, + request?: operations.ListOrdersRequest | undefined, + options?: RequestOptions, +): Promise< + Result< + operations.ListOrdersResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + return $do(client, request, options); +} + +async function $do( + client: ClientSDK, + request?: operations.ListOrdersRequest | undefined, + options?: RequestOptions, +): Promise< + Result< + operations.ListOrdersResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + const path = pathToFunc("/commerce/orders")(); + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); + + const query = encodeDeepObjectQuery({ + "filter": request?.filter, + }); + const simpleQuery = encodeSimpleQuery({ + "include": request?.include, + "sort": request?.sort, + "page": request?.page, + "limit": request?.limit, + }); + + const finalQuery = new URLSearchParams(query); + new URLSearchParams(simpleQuery || "").forEach((value, key) => { + finalQuery.append(key, value); + }); + + const context = { + operationID: "listOrders", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, + }; + + const [result] = await M.match< + operations.ListOrdersResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + >( + M.json(200, operations.ListOrdersResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} + diff --git a/src/funcs/commerce/ordersPaymentsList.ts b/src/funcs/commerce/ordersPaymentsList.ts new file mode 100644 index 0000000..9e4f37e --- /dev/null +++ b/src/funcs/commerce/ordersPaymentsList.ts @@ -0,0 +1,132 @@ +/* + * List order payments function. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; +import { + encodeSimpleQuery, } from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; + +export function ordersPaymentsList( + client: ClientSDK, + request: operations.ListOrderPaymentsRequest, + options?: RequestOptions, +): Promise< + Result< + operations.ListOrderPaymentsResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + return $do(client, request, options); +} + +async function $do( + client: ClientSDK, + request: operations.ListOrderPaymentsRequest, + options?: RequestOptions, +): Promise< + Result< + operations.ListOrderPaymentsResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + const path = pathToFunc("/commerce/orders/{orderId}/payments")({ + orderId: request.orderId, + }); + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); + + const simpleQuery = encodeSimpleQuery({ + "sort": request.sort, + "page": request.page, + "limit": request.limit, + }); + + const finalQuery = new URLSearchParams(simpleQuery || ""); + + const context = { + operationID: "listOrderPayments", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, + }; + + const [result] = await M.match< + operations.ListOrderPaymentsResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + >( + M.json(200, operations.ListOrderPaymentsResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} + diff --git a/src/funcs/commerce/ordersUpdate.ts b/src/funcs/commerce/ordersUpdate.ts new file mode 100644 index 0000000..2b5ef61 --- /dev/null +++ b/src/funcs/commerce/ordersUpdate.ts @@ -0,0 +1,127 @@ +/* + * Update order function. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; +import { + encodeJSON, +} from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; + +export function ordersUpdate( + client: ClientSDK, + request: operations.UpdateOrderRequest, + options?: RequestOptions, +): Promise< + Result< + operations.UpdateOrderResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + return $do(client, request, options); +} + +async function $do( + client: ClientSDK, + request: operations.UpdateOrderRequest, + options?: RequestOptions, +): Promise< + Result< + operations.UpdateOrderResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + const path = pathToFunc("/commerce/orders/{id}")({ + id: request.id, + }); + + const headers = new Headers({ + "Content-Type": "application/json", + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); + + const context = { + operationID: "updateOrder", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const body = encodeJSON("body", request.data, { explode: true }); + + const requestRes = client._createRequest( + context, + { + security: security, + method: "PATCH", + path: path, + headers: headers, + body: body, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, + }; + + const [result] = await M.match< + operations.UpdateOrderResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + >( + M.json(200, operations.UpdateOrderResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} + diff --git a/src/funcs/commerce/paymentsGet.ts b/src/funcs/commerce/paymentsGet.ts new file mode 100644 index 0000000..a007c37 --- /dev/null +++ b/src/funcs/commerce/paymentsGet.ts @@ -0,0 +1,130 @@ +/* + * Get payment function. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; +import { + encodeSimpleQuery, } from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; + +export function paymentsGet( + client: ClientSDK, + request: operations.GetPaymentRequest, + options?: RequestOptions, +): Promise< + Result< + operations.GetPaymentResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + return $do(client, request, options); +} + +async function $do( + client: ClientSDK, + request: operations.GetPaymentRequest, + options?: RequestOptions, +): Promise< + Result< + operations.GetPaymentResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + const path = pathToFunc("/commerce/payments/{id}")({ + id: request.id, + }); + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); + + const simpleQuery = encodeSimpleQuery({ + "include": request.include, + }); + + const finalQuery = new URLSearchParams(simpleQuery || ""); + + const context = { + operationID: "getPayment", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, + }; + + const [result] = await M.match< + operations.GetPaymentResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + >( + M.json(200, operations.GetPaymentResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} + diff --git a/src/funcs/commerce/productGroupsGet.ts b/src/funcs/commerce/productGroupsGet.ts new file mode 100644 index 0000000..ee1b228 --- /dev/null +++ b/src/funcs/commerce/productGroupsGet.ts @@ -0,0 +1,130 @@ +/* + * Get product group function. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; +import { + encodeSimpleQuery, } from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; + +export function productGroupsGet( + client: ClientSDK, + request: operations.GetProductGroupRequest, + options?: RequestOptions, +): Promise< + Result< + operations.GetProductGroupResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + return $do(client, request, options); +} + +async function $do( + client: ClientSDK, + request: operations.GetProductGroupRequest, + options?: RequestOptions, +): Promise< + Result< + operations.GetProductGroupResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + const path = pathToFunc("/commerce/product-groups/{id}")({ + id: request.id, + }); + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); + + const simpleQuery = encodeSimpleQuery({ + "include": request.include, + }); + + const finalQuery = new URLSearchParams(simpleQuery || ""); + + const context = { + operationID: "getProductGroup", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, + }; + + const [result] = await M.match< + operations.GetProductGroupResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + >( + M.json(200, operations.GetProductGroupResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} + diff --git a/src/funcs/commerce/productGroupsList.ts b/src/funcs/commerce/productGroupsList.ts new file mode 100644 index 0000000..e200cef --- /dev/null +++ b/src/funcs/commerce/productGroupsList.ts @@ -0,0 +1,138 @@ +/* + * List product groups function. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; +import { + encodeSimpleQuery, encodeDeepObjectQuery, +} from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; + +export function productGroupsList( + client: ClientSDK, + request?: operations.ListProductGroupsRequest | undefined, + options?: RequestOptions, +): Promise< + Result< + operations.ListProductGroupsResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + return $do(client, request, options); +} + +async function $do( + client: ClientSDK, + request?: operations.ListProductGroupsRequest | undefined, + options?: RequestOptions, +): Promise< + Result< + operations.ListProductGroupsResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + const path = pathToFunc("/commerce/product-groups")(); + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); + + const query = encodeDeepObjectQuery({ + "filter": request?.filter, + }); + const simpleQuery = encodeSimpleQuery({ + "include": request?.include, + "sort": request?.sort, + "page": request?.page, + "limit": request?.limit, + }); + + const finalQuery = new URLSearchParams(query); + new URLSearchParams(simpleQuery || "").forEach((value, key) => { + finalQuery.append(key, value); + }); + + const context = { + operationID: "listProductGroups", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, + }; + + const [result] = await M.match< + operations.ListProductGroupsResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + >( + M.json(200, operations.ListProductGroupsResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} + diff --git a/src/funcs/commerce/productsGet.ts b/src/funcs/commerce/productsGet.ts index 9023641..cf1f384 100644 --- a/src/funcs/commerce/productsGet.ts +++ b/src/funcs/commerce/productsGet.ts @@ -1,50 +1,34 @@ /* - * Get product. + * Get product function. */ import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; -import { encodeFormQuery } from "../../lib/encodings.js"; +import * as operations from "../../models/operations/index.js"; import * as M from "../../lib/matchers.js"; -import { safeParse } from "../../lib/schemas.js"; -import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; -import * as errors from "../../models/errors/index.js"; -import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; -import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; import { - ConnectionError, - InvalidRequestError, - RequestAbortedError, - RequestTimeoutError, - UnexpectedClientError, -} from "../../models/errors/http-client-errors.js"; -import * as operations from "../../models/operations/index.js"; -import { Product$inboundSchema } from "../../models/commerce/product.js"; -import { APICall, APIPromise } from "../../types/async.js"; -import { OK, Result } from "../../types/fp.js"; + encodeSimpleQuery, } from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; export function productsGet( client: ClientSDK, request: operations.GetProductRequest, options?: RequestOptions, -): APIPromise< +): Promise< Result< operations.GetProductResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError > > { - return new APIPromise($do( - client, - request, - options, - )); + return $do(client, request, options); } async function $do( @@ -52,113 +36,95 @@ async function $do( request: operations.GetProductRequest, options?: RequestOptions, ): Promise< - [ - Result< - operations.GetProductResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError - | ConnectionError - | RequestAbortedError - | RequestTimeoutError - | InvalidRequestError - | UnexpectedClientError - | SDKValidationError - >, - APICall, - ] + Result< + operations.GetProductResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > > { - const parsed = safeParse( - request, - (value) => operations.GetProductRequest$outboundSchema.parse(value), - "Input validation failed", - ); - if (!parsed.ok) { - return [parsed, { status: "invalid" }]; - } - const payload = parsed.value; - const body = null; - - const safeId = encodeURIComponent(String(payload.id)); - const path = `/commerce/products/${safeId}`; - - const query = encodeFormQuery({ - include: payload.include, + const path = pathToFunc("/commerce/products/{id}")({ + id: request.id, }); - const headers = new Headers(); + const headers = new Headers({ + Accept: "application/hal+json", + }); const securityInput = await extractSecurity(client._options.security); - const requestSecurity = resolveGlobalSecurity(securityInput); + const security = resolveGlobalSecurity(securityInput); + + const simpleQuery = encodeSimpleQuery({ + "include": request.include, + }); + + const finalQuery = new URLSearchParams(simpleQuery || ""); const context = { - options: client._options, - baseURL: options?.serverURL ?? client._baseURL ?? "", - operationID: "commerce.products.get", - oAuth2Scopes: null, - resolvedSecurity: requestSecurity, + operationID: "getProduct", + oAuth2Scopes: [], securitySource: client._options.security, - retryConfig: options?.retries - || client._options.retryConfig - || { strategy: "none" }, - retryCodes: options?.retryCodes || ["429", "5XX"], + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, }; - const requestRes = client._createRequest(context, { - security: requestSecurity, - method: "GET", - baseURL: options?.serverURL, - path, - headers, - query, - body, - userAgent: client._options.userAgent, - timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, - }, options); + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); if (!requestRes.ok) { - return [requestRes, { status: "invalid" }]; + return requestRes; } const req = requestRes.value; const doResult = await client._do(req, { context, - errorCodes: ["4XX", "5XX"], - retryConfig: context.retryConfig, - retryCodes: context.retryCodes, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }); if (!doResult.ok) { - return [doResult, { status: "request-error", request: req }]; + return doResult; } const response = doResult.value; const responseFields = { - HttpMeta: { Response: response, Request: req }, + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, }; const [result] = await M.match< operations.GetProductResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError >( - M.json(200, Product$inboundSchema, { - ctype: "application/hal+json", - }), - M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { - ctype: "application/hal+json", - }), - M.fail("4XX"), - M.fail("5XX"), + M.json(200, operations.GetProductResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) )(response, req, { extraFields: responseFields }); if (!result.ok) { - return [result, { status: "complete", request: req, response }]; + return result; } - return [OK(result.value), { status: "complete", request: req, response }]; + return result; } + diff --git a/src/funcs/commerce/productsList.ts b/src/funcs/commerce/productsList.ts index a67cd0c..ca83553 100644 --- a/src/funcs/commerce/productsList.ts +++ b/src/funcs/commerce/productsList.ts @@ -1,187 +1,138 @@ /* - * List products. + * List products function. */ import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; import { - encodeDeepObjectQuery, - encodeFormQuery, - queryJoin, + encodeSimpleQuery, encodeDeepObjectQuery, } from "../../lib/encodings.js"; -import * as M from "../../lib/matchers.js"; -import { safeParse } from "../../lib/schemas.js"; +import { pathToFunc } from "../../lib/url.js"; import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; -import * as errors from "../../models/errors/index.js"; -import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; -import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; -import { - ConnectionError, - InvalidRequestError, - RequestAbortedError, - RequestTimeoutError, - UnexpectedClientError, -} from "../../models/errors/http-client-errors.js"; -import * as operations from "../../models/operations/index.js"; -import { ProductsListResponse$inboundSchema } from "../../models/commerce/product.js"; -import { applyPaginationParams } from "../../models/pagination.js"; -import { APICall, APIPromise } from "../../types/async.js"; -import { OK, Result } from "../../types/fp.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; export function productsList( client: ClientSDK, - request?: operations.ProductsListParams | undefined, + request?: operations.ListProductsRequest | undefined, options?: RequestOptions, -): APIPromise< +): Promise< Result< operations.ListProductsResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError > > { - return new APIPromise($do( - client, - request, - options, - )); + return $do(client, request, options); } async function $do( client: ClientSDK, - request?: operations.ProductsListParams | undefined, + request?: operations.ListProductsRequest | undefined, options?: RequestOptions, ): Promise< - [ - Result< - operations.ListProductsResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError - | ConnectionError - | RequestAbortedError - | RequestTimeoutError - | InvalidRequestError - | UnexpectedClientError - | SDKValidationError - >, - APICall, - ] + Result< + operations.ListProductsResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > > { - const parsed = safeParse( - request, - (value) => - operations.ProductsListParams$outboundSchema.optional().parse(value), - "Input validation failed", - ); - if (!parsed.ok) { - return [parsed, { status: "invalid" }]; - } - const payload = parsed.value; - const body = null; - - const path = "/commerce/products"; + const path = pathToFunc("/commerce/products")(); - const baseQuery = encodeFormQuery({ - page: payload?.page, - limit: payload?.limit, - include: payload?.include, - sort: payload?.sort, + const headers = new Headers({ + Accept: "application/hal+json", }); - let filterQuery: string | undefined; - if (typeof payload?.filter === "string") { - filterQuery = encodeFormQuery({ filter: payload.filter }); - } else if ( - payload?.filter != null - && typeof payload.filter === "object" - && !Array.isArray(payload.filter) - ) { - filterQuery = encodeDeepObjectQuery({ filter: payload.filter }); - } - - const query = queryJoin(baseQuery, filterQuery); + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); - const headers = new Headers(); + const query = encodeDeepObjectQuery({ + "filter": request?.filter, + }); + const simpleQuery = encodeSimpleQuery({ + "include": request?.include, + "sort": request?.sort, + "page": request?.page, + "limit": request?.limit, + }); - const securityInput = await extractSecurity(client._options.security); - const requestSecurity = resolveGlobalSecurity(securityInput); + const finalQuery = new URLSearchParams(query); + new URLSearchParams(simpleQuery || "").forEach((value, key) => { + finalQuery.append(key, value); + }); const context = { - options: client._options, - baseURL: options?.serverURL ?? client._baseURL ?? "", - operationID: "commerce.products.list", - oAuth2Scopes: null, - resolvedSecurity: requestSecurity, + operationID: "listProducts", + oAuth2Scopes: [], securitySource: client._options.security, - retryConfig: options?.retries - || client._options.retryConfig - || { strategy: "none" }, - retryCodes: options?.retryCodes || ["429", "5XX"], + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, }; - const requestRes = client._createRequest(context, { - security: requestSecurity, - method: "GET", - baseURL: options?.serverURL, - path, - headers, - query, - body, - userAgent: client._options.userAgent, - timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, - }, options); + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); if (!requestRes.ok) { - return [requestRes, { status: "invalid" }]; + return requestRes; } const req = requestRes.value; const doResult = await client._do(req, { context, - errorCodes: ["4XX", "5XX"], - retryConfig: context.retryConfig, - retryCodes: context.retryCodes, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }); if (!doResult.ok) { - return [doResult, { status: "request-error", request: req }]; + return doResult; } const response = doResult.value; const responseFields = { - HttpMeta: { Response: response, Request: req }, + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, }; const [result] = await M.match< operations.ListProductsResponse, - | errors.ErrorResponse - | errors.OminityDefaultError - | ResponseValidationError + | OminityError | ConnectionError - | RequestAbortedError - | RequestTimeoutError | InvalidRequestError | UnexpectedClientError - | SDKValidationError + | RequestAbortedError + | RequestTimeoutError >( - M.json(200, ProductsListResponse$inboundSchema, { - ctype: "application/hal+json", - }), - M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { - ctype: "application/hal+json", - }), - M.fail("4XX"), - M.fail("5XX"), + M.json(200, operations.ListProductsResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) )(response, req, { extraFields: responseFields }); if (!result.ok) { - return [result, { status: "complete", request: req, response }]; + return result; } - const finalValue = applyPaginationParams(result.value, payload); - - return [OK(finalValue), { status: "complete", request: req, response }]; + return result; } + diff --git a/src/funcs/commerce/productsOffersList.ts b/src/funcs/commerce/productsOffersList.ts new file mode 100644 index 0000000..59eb7e1 --- /dev/null +++ b/src/funcs/commerce/productsOffersList.ts @@ -0,0 +1,140 @@ +/* + * List product offers function. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; +import { + encodeSimpleQuery, encodeDeepObjectQuery, +} from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; + +export function productsOffersList( + client: ClientSDK, + request: operations.ListProductOffersRequest, + options?: RequestOptions, +): Promise< + Result< + operations.ListProductOffersResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + return $do(client, request, options); +} + +async function $do( + client: ClientSDK, + request: operations.ListProductOffersRequest, + options?: RequestOptions, +): Promise< + Result< + operations.ListProductOffersResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + const path = pathToFunc("/commerce/products/{id}/offers")({ + id: request.id, + }); + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); + + const query = encodeDeepObjectQuery({ + "filter": request?.filter, + }); + const simpleQuery = encodeSimpleQuery({ + "include": request?.include, + "sort": request?.sort, + "page": request?.page, + "limit": request?.limit, + }); + + const finalQuery = new URLSearchParams(query); + new URLSearchParams(simpleQuery || "").forEach((value, key) => { + finalQuery.append(key, value); + }); + + const context = { + operationID: "listProductOffers", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, + }; + + const [result] = await M.match< + operations.ListProductOffersResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + >( + M.json(200, operations.ListProductOffersResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} + diff --git a/src/funcs/commerce/reviewsCreate.ts b/src/funcs/commerce/reviewsCreate.ts new file mode 100644 index 0000000..eb985c1 --- /dev/null +++ b/src/funcs/commerce/reviewsCreate.ts @@ -0,0 +1,125 @@ +/* + * Create review function. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; +import { + encodeJSON, +} from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; + +export function reviewsCreate( + client: ClientSDK, + request: operations.CreateReviewRequest, + options?: RequestOptions, +): Promise< + Result< + operations.CreateReviewResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + return $do(client, request, options); +} + +async function $do( + client: ClientSDK, + request: operations.CreateReviewRequest, + options?: RequestOptions, +): Promise< + Result< + operations.CreateReviewResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + const path = pathToFunc("/commerce/reviews")(); + + const headers = new Headers({ + "Content-Type": "application/json", + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); + + const context = { + operationID: "createReview", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const body = encodeJSON("body", request, { explode: true }); + + const requestRes = client._createRequest( + context, + { + security: security, + method: "POST", + path: path, + headers: headers, + body: body, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, + }; + + const [result] = await M.match< + operations.CreateReviewResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + >( + M.json(201, operations.CreateReviewResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} + diff --git a/src/funcs/commerce/reviewsGet.ts b/src/funcs/commerce/reviewsGet.ts new file mode 100644 index 0000000..133149a --- /dev/null +++ b/src/funcs/commerce/reviewsGet.ts @@ -0,0 +1,130 @@ +/* + * Get review function. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; +import { + encodeSimpleQuery, } from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; + +export function reviewsGet( + client: ClientSDK, + request: operations.GetReviewRequest, + options?: RequestOptions, +): Promise< + Result< + operations.GetReviewResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + return $do(client, request, options); +} + +async function $do( + client: ClientSDK, + request: operations.GetReviewRequest, + options?: RequestOptions, +): Promise< + Result< + operations.GetReviewResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + const path = pathToFunc("/commerce/reviews/{id}")({ + id: request.id, + }); + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); + + const simpleQuery = encodeSimpleQuery({ + "include": request.include, + }); + + const finalQuery = new URLSearchParams(simpleQuery || ""); + + const context = { + operationID: "getReview", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, + }; + + const [result] = await M.match< + operations.GetReviewResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + >( + M.json(200, operations.GetReviewResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} + diff --git a/src/funcs/commerce/reviewsList.ts b/src/funcs/commerce/reviewsList.ts new file mode 100644 index 0000000..16e54e1 --- /dev/null +++ b/src/funcs/commerce/reviewsList.ts @@ -0,0 +1,138 @@ +/* + * List reviews function. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; +import { + encodeSimpleQuery, encodeDeepObjectQuery, +} from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; + +export function reviewsList( + client: ClientSDK, + request?: operations.ListReviewsRequest | undefined, + options?: RequestOptions, +): Promise< + Result< + operations.ListReviewsResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + return $do(client, request, options); +} + +async function $do( + client: ClientSDK, + request?: operations.ListReviewsRequest | undefined, + options?: RequestOptions, +): Promise< + Result< + operations.ListReviewsResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + const path = pathToFunc("/commerce/reviews")(); + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); + + const query = encodeDeepObjectQuery({ + "filter": request?.filter, + }); + const simpleQuery = encodeSimpleQuery({ + "include": request?.include, + "sort": request?.sort, + "page": request?.page, + "limit": request?.limit, + }); + + const finalQuery = new URLSearchParams(query); + new URLSearchParams(simpleQuery || "").forEach((value, key) => { + finalQuery.append(key, value); + }); + + const context = { + operationID: "listReviews", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, + }; + + const [result] = await M.match< + operations.ListReviewsResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + >( + M.json(200, operations.ListReviewsResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} + diff --git a/src/funcs/commerce/reviewsUpdate.ts b/src/funcs/commerce/reviewsUpdate.ts new file mode 100644 index 0000000..86f4870 --- /dev/null +++ b/src/funcs/commerce/reviewsUpdate.ts @@ -0,0 +1,127 @@ +/* + * Update review function. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; +import { + encodeJSON, +} from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; + +export function reviewsUpdate( + client: ClientSDK, + request: operations.UpdateReviewRequest, + options?: RequestOptions, +): Promise< + Result< + operations.UpdateReviewResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + return $do(client, request, options); +} + +async function $do( + client: ClientSDK, + request: operations.UpdateReviewRequest, + options?: RequestOptions, +): Promise< + Result< + operations.UpdateReviewResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + const path = pathToFunc("/commerce/reviews/{id}")({ + id: request.id, + }); + + const headers = new Headers({ + "Content-Type": "application/json", + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); + + const context = { + operationID: "updateReview", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const body = encodeJSON("body", request.data, { explode: true }); + + const requestRes = client._createRequest( + context, + { + security: security, + method: "PATCH", + path: path, + headers: headers, + body: body, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, + }; + + const [result] = await M.match< + operations.UpdateReviewResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + >( + M.json(200, operations.UpdateReviewResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} + diff --git a/src/funcs/commerce/shippingMethodsGet.ts b/src/funcs/commerce/shippingMethodsGet.ts new file mode 100644 index 0000000..8e3274d --- /dev/null +++ b/src/funcs/commerce/shippingMethodsGet.ts @@ -0,0 +1,130 @@ +/* + * Get shipping method function. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; +import { + encodeSimpleQuery, } from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; + +export function shippingMethodsGet( + client: ClientSDK, + request: operations.GetShippingMethodRequest, + options?: RequestOptions, +): Promise< + Result< + operations.GetShippingMethodResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + return $do(client, request, options); +} + +async function $do( + client: ClientSDK, + request: operations.GetShippingMethodRequest, + options?: RequestOptions, +): Promise< + Result< + operations.GetShippingMethodResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + const path = pathToFunc("/commerce/shipping-methods/{id}")({ + id: request.id, + }); + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); + + const simpleQuery = encodeSimpleQuery({ + "include": request.include, + }); + + const finalQuery = new URLSearchParams(simpleQuery || ""); + + const context = { + operationID: "getShippingMethod", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, + }; + + const [result] = await M.match< + operations.GetShippingMethodResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + >( + M.json(200, operations.GetShippingMethodResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} + diff --git a/src/funcs/commerce/shippingMethodsList.ts b/src/funcs/commerce/shippingMethodsList.ts new file mode 100644 index 0000000..a5708e1 --- /dev/null +++ b/src/funcs/commerce/shippingMethodsList.ts @@ -0,0 +1,138 @@ +/* + * List shipping methods function. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; +import { + encodeSimpleQuery, encodeDeepObjectQuery, +} from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; + +export function shippingMethodsList( + client: ClientSDK, + request?: operations.ListShippingMethodsRequest | undefined, + options?: RequestOptions, +): Promise< + Result< + operations.ListShippingMethodsResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + return $do(client, request, options); +} + +async function $do( + client: ClientSDK, + request?: operations.ListShippingMethodsRequest | undefined, + options?: RequestOptions, +): Promise< + Result< + operations.ListShippingMethodsResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + const path = pathToFunc("/commerce/shipping-methods")(); + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); + + const query = encodeDeepObjectQuery({ + "filter": request?.filter, + }); + const simpleQuery = encodeSimpleQuery({ + "include": request?.include, + "sort": request?.sort, + "page": request?.page, + "limit": request?.limit, + }); + + const finalQuery = new URLSearchParams(query); + new URLSearchParams(simpleQuery || "").forEach((value, key) => { + finalQuery.append(key, value); + }); + + const context = { + operationID: "listShippingMethods", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, + }; + + const [result] = await M.match< + operations.ListShippingMethodsResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + >( + M.json(200, operations.ListShippingMethodsResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} + diff --git a/src/funcs/commerce/shippingZonesGet.ts b/src/funcs/commerce/shippingZonesGet.ts new file mode 100644 index 0000000..7efd8a5 --- /dev/null +++ b/src/funcs/commerce/shippingZonesGet.ts @@ -0,0 +1,130 @@ +/* + * Get shipping zone function. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; +import { + encodeSimpleQuery, } from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; + +export function shippingZonesGet( + client: ClientSDK, + request: operations.GetShippingZoneRequest, + options?: RequestOptions, +): Promise< + Result< + operations.GetShippingZoneResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + return $do(client, request, options); +} + +async function $do( + client: ClientSDK, + request: operations.GetShippingZoneRequest, + options?: RequestOptions, +): Promise< + Result< + operations.GetShippingZoneResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + const path = pathToFunc("/commerce/shipping-zones/{id}")({ + id: request.id, + }); + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); + + const simpleQuery = encodeSimpleQuery({ + "include": request.include, + }); + + const finalQuery = new URLSearchParams(simpleQuery || ""); + + const context = { + operationID: "getShippingZone", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, + }; + + const [result] = await M.match< + operations.GetShippingZoneResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + >( + M.json(200, operations.GetShippingZoneResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} + diff --git a/src/funcs/commerce/shippingZonesList.ts b/src/funcs/commerce/shippingZonesList.ts new file mode 100644 index 0000000..e9f254f --- /dev/null +++ b/src/funcs/commerce/shippingZonesList.ts @@ -0,0 +1,138 @@ +/* + * List shipping zones function. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; +import { + encodeSimpleQuery, encodeDeepObjectQuery, +} from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; + +export function shippingZonesList( + client: ClientSDK, + request?: operations.ListShippingZonesRequest | undefined, + options?: RequestOptions, +): Promise< + Result< + operations.ListShippingZonesResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + return $do(client, request, options); +} + +async function $do( + client: ClientSDK, + request?: operations.ListShippingZonesRequest | undefined, + options?: RequestOptions, +): Promise< + Result< + operations.ListShippingZonesResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + const path = pathToFunc("/commerce/shipping-zones")(); + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); + + const query = encodeDeepObjectQuery({ + "filter": request?.filter, + }); + const simpleQuery = encodeSimpleQuery({ + "include": request?.include, + "sort": request?.sort, + "page": request?.page, + "limit": request?.limit, + }); + + const finalQuery = new URLSearchParams(query); + new URLSearchParams(simpleQuery || "").forEach((value, key) => { + finalQuery.append(key, value); + }); + + const context = { + operationID: "listShippingZones", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, + }; + + const [result] = await M.match< + operations.ListShippingZonesResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + >( + M.json(200, operations.ListShippingZonesResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} + diff --git a/src/funcs/commerce/subscriptionIntervalsGet.ts b/src/funcs/commerce/subscriptionIntervalsGet.ts new file mode 100644 index 0000000..2938fd2 --- /dev/null +++ b/src/funcs/commerce/subscriptionIntervalsGet.ts @@ -0,0 +1,130 @@ +/* + * Get subscription interval function. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; +import { + encodeSimpleQuery, } from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; + +export function subscriptionIntervalsGet( + client: ClientSDK, + request: operations.GetSubscriptionIntervalRequest, + options?: RequestOptions, +): Promise< + Result< + operations.GetSubscriptionIntervalResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + return $do(client, request, options); +} + +async function $do( + client: ClientSDK, + request: operations.GetSubscriptionIntervalRequest, + options?: RequestOptions, +): Promise< + Result< + operations.GetSubscriptionIntervalResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + const path = pathToFunc("/commerce/subscription-intervals/{id}")({ + id: request.id, + }); + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); + + const simpleQuery = encodeSimpleQuery({ + "include": request.include, + }); + + const finalQuery = new URLSearchParams(simpleQuery || ""); + + const context = { + operationID: "getSubscriptionInterval", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, + }; + + const [result] = await M.match< + operations.GetSubscriptionIntervalResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + >( + M.json(200, operations.GetSubscriptionIntervalResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} + diff --git a/src/funcs/commerce/subscriptionIntervalsList.ts b/src/funcs/commerce/subscriptionIntervalsList.ts new file mode 100644 index 0000000..e15c291 --- /dev/null +++ b/src/funcs/commerce/subscriptionIntervalsList.ts @@ -0,0 +1,138 @@ +/* + * List subscription intervals function. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; +import { + encodeSimpleQuery, encodeDeepObjectQuery, +} from "../../lib/encodings.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; + +export function subscriptionIntervalsList( + client: ClientSDK, + request?: operations.ListSubscriptionIntervalsRequest | undefined, + options?: RequestOptions, +): Promise< + Result< + operations.ListSubscriptionIntervalsResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + return $do(client, request, options); +} + +async function $do( + client: ClientSDK, + request?: operations.ListSubscriptionIntervalsRequest | undefined, + options?: RequestOptions, +): Promise< + Result< + operations.ListSubscriptionIntervalsResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + const path = pathToFunc("/commerce/subscription-intervals")(); + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); + + const query = encodeDeepObjectQuery({ + "filter": request?.filter, + }); + const simpleQuery = encodeSimpleQuery({ + "include": request?.include, + "sort": request?.sort, + "page": request?.page, + "limit": request?.limit, + }); + + const finalQuery = new URLSearchParams(query); + new URLSearchParams(simpleQuery || "").forEach((value, key) => { + finalQuery.append(key, value); + }); + + const context = { + operationID: "listSubscriptionIntervals", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, + }; + + const [result] = await M.match< + operations.ListSubscriptionIntervalsResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + >( + M.json(200, operations.ListSubscriptionIntervalsResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} + diff --git a/src/funcs/commerce/vatValidationsGet.ts b/src/funcs/commerce/vatValidationsGet.ts new file mode 100644 index 0000000..42070e5 --- /dev/null +++ b/src/funcs/commerce/vatValidationsGet.ts @@ -0,0 +1,121 @@ +/* + * Get VAT validation function. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import * as M from "../../lib/matchers.js"; +import { pathToFunc } from "../../lib/url.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { ConnectionError, InvalidRequestError, UnexpectedClientError, RequestAbortedError, RequestTimeoutError } from "../../models/errors/http-client-errors.js"; +import { Result } from "../../types/fp.js"; + +export function vatValidationsGet( + client: ClientSDK, + request: operations.GetVatValidationRequest, + options?: RequestOptions, +): Promise< + Result< + operations.GetVatValidationResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + return $do(client, request, options); +} + +async function $do( + client: ClientSDK, + request: operations.GetVatValidationRequest, + options?: RequestOptions, +): Promise< + Result< + operations.GetVatValidationResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + > +> { + const path = pathToFunc("/commerce/vat-validations/{number}")({ + number: request.vatNumber, + }); + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const security = resolveGlobalSecurity(securityInput); + + const context = { + operationID: "getVatValidation", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: path, + headers: headers, + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + ContentType: response.headers.get("content-type") ?? "application/octet-stream", + StatusCode: response.status, + RawResponse: response, + Headers: {}, + }; + + const [result] = await M.match< + operations.GetVatValidationResponse, + | OminityError + | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | RequestAbortedError + | RequestTimeoutError + >( + M.json(200, operations.GetVatValidationResponse$inboundSchema), + M.fail([400, 401, 403, 404, "4XX", 500, "5XX"]) + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} + diff --git a/src/funcs/index.ts b/src/funcs/index.ts index eed5b2d..715ced5 100644 --- a/src/funcs/index.ts +++ b/src/funcs/index.ts @@ -17,3 +17,4 @@ export * from "./commerce/cartItemsUpdate.js"; export * from "./commerce/cartItemsDelete.js"; export * from "./meGet.js"; export * from "./users/index.js"; +export * from "./admins/index.js"; diff --git a/src/funcs/settings/countriesGet.ts b/src/funcs/settings/countriesGet.ts new file mode 100644 index 0000000..aa8721d --- /dev/null +++ b/src/funcs/settings/countriesGet.ts @@ -0,0 +1,115 @@ +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { encodeSimpleQuery } from "../../lib/encodings.js"; +import * as M from "../../lib/matchers.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { pathToFunc } from "../../lib/url.js"; +import * as operations from "../../models/operations/index.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { Result } from "../../types/fp.js"; + +/** + * Get country. + */ +export async function countriesGet( + client: ClientSDK, + request: operations.GetCountryRequest, + options?: RequestOptions, +): Promise< + Result< + operations.GetCountryResponse, + | OminityError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + > +> { + const input: operations.GetCountryRequest = request; + + const securitySettings = client._options.security; + const securityInput = await extractSecurity(securitySettings); + const security = resolveGlobalSecurity(securityInput); + + const simpleQuery = encodeSimpleQuery({ + "include": input.include, + }); + + const finalQuery = new URLSearchParams(simpleQuery || ""); + + const context = { + operationID: "getCountry", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: pathToFunc("/countries/{code}")(input), + headers: new Headers(options?.headers), + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options, + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.GetCountryResponse, + | OminityError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + >( + M.json( + 200, + operations.GetCountryResponse$inboundSchema, + ), + M.fail( + ["400", "401", "403", "404", "4XX", "500", "5XX"], + ), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} diff --git a/src/funcs/settings/countriesList.ts b/src/funcs/settings/countriesList.ts new file mode 100644 index 0000000..c964e99 --- /dev/null +++ b/src/funcs/settings/countriesList.ts @@ -0,0 +1,125 @@ +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { encodeSimpleQuery, encodeDeepObjectQuery } from "../../lib/encodings.js"; +import * as M from "../../lib/matchers.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { pathToFunc } from "../../lib/url.js"; +import * as operations from "../../models/operations/index.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { Result } from "../../types/fp.js"; + +/** + * List countries. + */ +export async function countriesList( + client: ClientSDK, + request?: operations.ListCountriesRequest | undefined, + options?: RequestOptions, +): Promise< + Result< + operations.ListCountriesResponse, + | OminityError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + > +> { + const input: operations.ListCountriesRequest = + request ?? {}; + + const securitySettings = client._options.security; + const securityInput = await extractSecurity(securitySettings); + const security = resolveGlobalSecurity(securityInput); + + const query = encodeDeepObjectQuery({ + "filter": input.filter, + }); + const simpleQuery = encodeSimpleQuery({ + "include": input.include, + "sort": input.sort, + "page": input.page, + "limit": input.limit, + }); + + const finalQuery = new URLSearchParams(query); + new URLSearchParams(simpleQuery || "").forEach((value, key) => { + finalQuery.append(key, value); + }); + + const context = { + operationID: "listCountries", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: pathToFunc("/countries")(), + headers: new Headers(options?.headers), + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options, + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.ListCountriesResponse, + | OminityError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + >( + M.json( + 200, + operations.ListCountriesResponse$inboundSchema, + ), + M.fail( + ["400", "401", "403", "404", "4XX", "500", "5XX"], + ), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} diff --git a/src/funcs/settings/index.ts b/src/funcs/settings/index.ts new file mode 100644 index 0000000..0ba10b6 --- /dev/null +++ b/src/funcs/settings/index.ts @@ -0,0 +1,11 @@ +/* + * Standalone SDK functions. + */ + +export * from "./countriesGet.js"; +export * from "./countriesList.js"; +export * from "./languagesList.js"; +export * from "./paymentMethodsGet.js"; +export * from "./paymentMethodsList.js"; +export * from "./socialProvidersGet.js"; +export * from "./socialProvidersList.js"; diff --git a/src/funcs/settings/languagesList.ts b/src/funcs/settings/languagesList.ts new file mode 100644 index 0000000..6b45fb6 --- /dev/null +++ b/src/funcs/settings/languagesList.ts @@ -0,0 +1,124 @@ +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { encodeSimpleQuery, encodeDeepObjectQuery } from "../../lib/encodings.js"; +import * as M from "../../lib/matchers.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { pathToFunc } from "../../lib/url.js"; +import * as operations from "../../models/operations/index.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { Result } from "../../types/fp.js"; + +/** + * List languages. + */ +export async function languagesList( + client: ClientSDK, + request?: operations.ListLanguagesRequest | undefined, + options?: RequestOptions, +): Promise< + Result< + operations.ListLanguagesResponse, + | OminityError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + > +> { + const input: operations.ListLanguagesRequest = + request ?? {}; + + const securitySettings = client._options.security; + const securityInput = await extractSecurity(securitySettings); + const security = resolveGlobalSecurity(securityInput); + + const query = encodeDeepObjectQuery({ + "filter": input.filter, + }); + const simpleQuery = encodeSimpleQuery({ + "sort": input.sort, + "page": input.page, + "limit": input.limit, + }); + + const finalQuery = new URLSearchParams(query); + new URLSearchParams(simpleQuery || "").forEach((value, key) => { + finalQuery.append(key, value); + }); + + const context = { + operationID: "listLanguages", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: pathToFunc("/settings/languages")(), + headers: new Headers(options?.headers), + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options, + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.ListLanguagesResponse, + | OminityError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + >( + M.json( + 200, + operations.ListLanguagesResponse$inboundSchema, + ), + M.fail( + ["400", "401", "403", "404", "4XX", "500", "5XX"], + ), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} diff --git a/src/funcs/settings/paymentMethodsGet.ts b/src/funcs/settings/paymentMethodsGet.ts new file mode 100644 index 0000000..1cc9632 --- /dev/null +++ b/src/funcs/settings/paymentMethodsGet.ts @@ -0,0 +1,108 @@ +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as M from "../../lib/matchers.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { pathToFunc } from "../../lib/url.js"; +import * as operations from "../../models/operations/index.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { Result } from "../../types/fp.js"; + +/** + * Get payment method. + */ +export async function paymentMethodsGet( + client: ClientSDK, + request: operations.GetPaymentMethodRequest, + options?: RequestOptions, +): Promise< + Result< + operations.GetPaymentMethodResponse, + | OminityError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + > +> { + const input: operations.GetPaymentMethodRequest = request; + + const securitySettings = client._options.security; + const securityInput = await extractSecurity(securitySettings); + const security = resolveGlobalSecurity(securityInput); + + const context = { + operationID: "getPaymentMethod", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: pathToFunc("/settings/paymentmethods/{id}")(input), + headers: new Headers(options?.headers), + query: "", + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options, + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.GetPaymentMethodResponse, + | OminityError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + >( + M.json( + 200, + operations.GetPaymentMethodResponse$inboundSchema, + ), + M.fail( + ["400", "401", "403", "404", "4XX", "500", "5XX"], + ), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} diff --git a/src/funcs/settings/paymentMethodsList.ts b/src/funcs/settings/paymentMethodsList.ts new file mode 100644 index 0000000..d0aaca0 --- /dev/null +++ b/src/funcs/settings/paymentMethodsList.ts @@ -0,0 +1,117 @@ +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { encodeSimpleQuery } from "../../lib/encodings.js"; +import * as M from "../../lib/matchers.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { pathToFunc } from "../../lib/url.js"; +import * as operations from "../../models/operations/index.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { Result } from "../../types/fp.js"; + +/** + * List payment methods. + */ +export async function paymentMethodsList( + client: ClientSDK, + request?: operations.ListPaymentMethodsRequest | undefined, + options?: RequestOptions, +): Promise< + Result< + operations.ListPaymentMethodsResponse, + | OminityError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + > +> { + const input: operations.ListPaymentMethodsRequest = + request ?? {}; + + const securitySettings = client._options.security; + const securityInput = await extractSecurity(securitySettings); + const security = resolveGlobalSecurity(securityInput); + + const simpleQuery = encodeSimpleQuery({ + "page": input.page, + "limit": input.limit, + }); + + const finalQuery = new URLSearchParams(simpleQuery || ""); + + const context = { + operationID: "listPaymentMethods", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: pathToFunc("/settings/paymentmethods")(), + headers: new Headers(options?.headers), + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options, + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.ListPaymentMethodsResponse, + | OminityError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + >( + M.json( + 200, + operations.ListPaymentMethodsResponse$inboundSchema, + ), + M.fail( + ["400", "401", "403", "404", "4XX", "500", "5XX"], + ), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} diff --git a/src/funcs/settings/socialProvidersGet.ts b/src/funcs/settings/socialProvidersGet.ts new file mode 100644 index 0000000..b7eb970 --- /dev/null +++ b/src/funcs/settings/socialProvidersGet.ts @@ -0,0 +1,108 @@ +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as M from "../../lib/matchers.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { pathToFunc } from "../../lib/url.js"; +import * as operations from "../../models/operations/index.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { Result } from "../../types/fp.js"; + +/** + * Get social provider. + */ +export async function socialProvidersGet( + client: ClientSDK, + request: operations.GetSocialProviderRequest, + options?: RequestOptions, +): Promise< + Result< + operations.GetSocialProviderResponse, + | OminityError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + > +> { + const input: operations.GetSocialProviderRequest = request; + + const securitySettings = client._options.security; + const securityInput = await extractSecurity(securitySettings); + const security = resolveGlobalSecurity(securityInput); + + const context = { + operationID: "getSocialProvider", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: pathToFunc("/settings/socialproviders/{id}")(input), + headers: new Headers(options?.headers), + query: "", + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options, + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.GetSocialProviderResponse, + | OminityError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + >( + M.json( + 200, + operations.GetSocialProviderResponse$inboundSchema, + ), + M.fail( + ["400", "401", "403", "404", "4XX", "500", "5XX"], + ), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} diff --git a/src/funcs/settings/socialProvidersList.ts b/src/funcs/settings/socialProvidersList.ts new file mode 100644 index 0000000..ea5d8a6 --- /dev/null +++ b/src/funcs/settings/socialProvidersList.ts @@ -0,0 +1,117 @@ +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { encodeSimpleQuery } from "../../lib/encodings.js"; +import * as M from "../../lib/matchers.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import { pathToFunc } from "../../lib/url.js"; +import * as operations from "../../models/operations/index.js"; +import { OminityError } from "../../models/errors/ominity-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { Result } from "../../types/fp.js"; + +/** + * List social providers. + */ +export async function socialProvidersList( + client: ClientSDK, + request?: operations.ListSocialProvidersRequest | undefined, + options?: RequestOptions, +): Promise< + Result< + operations.ListSocialProvidersResponse, + | OminityError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + > +> { + const input: operations.ListSocialProvidersRequest = + request ?? {}; + + const securitySettings = client._options.security; + const securityInput = await extractSecurity(securitySettings); + const security = resolveGlobalSecurity(securityInput); + + const simpleQuery = encodeSimpleQuery({ + "page": input.page, + "limit": input.limit, + }); + + const finalQuery = new URLSearchParams(simpleQuery || ""); + + const context = { + operationID: "listSocialProviders", + oAuth2Scopes: [], + securitySource: client._options.security, + baseURL: client._baseURL, + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + resolvedSecurity: security, + options: options, + }; + + const requestRes = client._createRequest( + context, + { + security: security, + method: "GET", + path: pathToFunc("/settings/socialproviders")(), + headers: new Headers(options?.headers), + query: finalQuery.toString(), + body: null, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, + options, + ); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"], + retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.ListSocialProvidersResponse, + | OminityError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + >( + M.json( + 200, + operations.ListSocialProvidersResponse$inboundSchema, + ), + M.fail( + ["400", "401", "403", "404", "4XX", "500", "5XX"], + ), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} diff --git a/src/funcs/users/index.ts b/src/funcs/users/index.ts index e0f6816..a0dbab6 100644 --- a/src/funcs/users/index.ts +++ b/src/funcs/users/index.ts @@ -1,11 +1,18 @@ /* - * User-related SDK functions. + * Users functions. */ -export * from "./usersList.js"; -export * from "./usersGet.js"; export * from "./usersCreate.js"; +export * from "./usersGet.js"; +export * from "./usersList.js"; export * from "./usersUpdate.js"; -export * from "./loginsList.js"; -export * from "./loginsGet.js"; -export * from "./loginsCreate.js"; +export * from "./usersListCustomers.js"; +export * from "./usersListOAuthAccounts.js"; +export * from "./usersListMfaMethods.js"; +export * from "./usersEnableMfa.js"; +export * from "./usersDisableMfa.js"; +export * from "./usersValidateMfa.js"; +export * from "./usersSendMfa.js"; +export * from "./usersListRecoveryCodes.js"; +export * from "./usersRegenerateRecoveryCodes.js"; +export * from "./usersValidateRecoveryCode.js"; diff --git a/src/funcs/users/usersDisableMfa.ts b/src/funcs/users/usersDisableMfa.ts new file mode 100644 index 0000000..28e9867 --- /dev/null +++ b/src/funcs/users/usersDisableMfa.ts @@ -0,0 +1,177 @@ +/* + * Disable user MFA method. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { + encodeSimple, +} from "../../lib/encodings.js"; +import * as M from "../../lib/matchers.js"; +import { safeParse } from "../../lib/schemas.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import * as errors from "../../models/errors/index.js"; +import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import * as operations from "../../models/operations/index.js"; +import { DisableMfaResponse$inboundSchema } from "../../models/operations/users-mfa.js"; +import { APICall, APIPromise } from "../../types/async.js"; +import { OK, Result } from "../../types/fp.js"; + +export function usersDisableMfa( + client: ClientSDK, + request: operations.DisableMfaRequest, + options?: RequestOptions, +): APIPromise< + Result< + operations.DisableMfaResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + > +> { + return new APIPromise($do( + client, + request, + options, + )); +} + +async function $do( + client: ClientSDK, + request: operations.DisableMfaRequest, + options?: RequestOptions, +): Promise< + [ + Result< + operations.DisableMfaResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >, + APICall, + ] +> { + const parsed = safeParse( + request, + (value) => + operations.DisableMfaRequest$outboundSchema.parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return [parsed, { status: "invalid" }]; + } + const payload = parsed.value; + const body = null; + + const path = encodeSimple( + "/users/{id}/mfa-methods/{method}", + { "id": payload.id, "method": payload.method }, + { explode: false, charEncoding: "percent" }, + ) || ""; + + const headers = new Headers({ + Accept: "*/*", + }); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + options: client._options, + baseURL: options?.serverURL ?? client._baseURL ?? "", + operationID: "users.disableMfa", + oAuth2Scopes: null, + resolvedSecurity: requestSecurity, + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { + strategy: "backoff", + backoff: { + initialInterval: 500, + maxInterval: 5000, + exponent: 2, + maxElapsedTime: 7500, + }, + retryConnectionErrors: true, + } + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["5xx"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "DELETE", + baseURL: options?.serverURL, + path, + headers, + body, + userAgent: client._options.userAgent, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return [requestRes, { status: "invalid" }]; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "4XX", "5XX"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return [doResult, { status: "request-error", request: req }]; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.DisableMfaResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >( + M.nil("2XX", DisableMfaResponse$inboundSchema), + M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.fail("5XX"), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return [result, { status: "complete", request: req, response }]; + } + + return [ + OK(result.value), + { status: "complete", request: req, response }, + ]; +} diff --git a/src/funcs/users/usersEnableMfa.ts b/src/funcs/users/usersEnableMfa.ts new file mode 100644 index 0000000..936799e --- /dev/null +++ b/src/funcs/users/usersEnableMfa.ts @@ -0,0 +1,179 @@ +/* + * Enable user MFA method. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { + encodeSimple, +} from "../../lib/encodings.js"; +import * as M from "../../lib/matchers.js"; +import { safeParse } from "../../lib/schemas.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import * as errors from "../../models/errors/index.js"; +import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import * as operations from "../../models/operations/index.js"; +import { EnableMfaResponse$inboundSchema } from "../../models/operations/users-mfa.js"; +import { APICall, APIPromise } from "../../types/async.js"; +import { OK, Result } from "../../types/fp.js"; + +export function usersEnableMfa( + client: ClientSDK, + request: operations.EnableMfaRequest, + options?: RequestOptions, +): APIPromise< + Result< + operations.EnableMfaResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + > +> { + return new APIPromise($do( + client, + request, + options, + )); +} + +async function $do( + client: ClientSDK, + request: operations.EnableMfaRequest, + options?: RequestOptions, +): Promise< + [ + Result< + operations.EnableMfaResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >, + APICall, + ] +> { + const parsed = safeParse( + request, + (value) => + operations.EnableMfaRequest$outboundSchema.parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return [parsed, { status: "invalid" }]; + } + const payload = parsed.value; + const body = null; + + const path = encodeSimple( + "/users/{id}/mfa-methods/{method}/enable", + { "id": payload.id, "method": payload.method }, + { explode: false, charEncoding: "percent" }, + ) || ""; + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + options: client._options, + baseURL: options?.serverURL ?? client._baseURL ?? "", + operationID: "users.enableMfa", + oAuth2Scopes: null, + resolvedSecurity: requestSecurity, + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { + strategy: "backoff", + backoff: { + initialInterval: 500, + maxInterval: 5000, + exponent: 2, + maxElapsedTime: 7500, + }, + retryConnectionErrors: true, + } + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["5xx"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "POST", + baseURL: options?.serverURL, + path, + headers, + body, + userAgent: client._options.userAgent, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return [requestRes, { status: "invalid" }]; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "4XX", "5XX"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return [doResult, { status: "request-error", request: req }]; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.EnableMfaResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >( + M.json(200, EnableMfaResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.fail("5XX"), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return [result, { status: "complete", request: req, response }]; + } + + return [ + OK(result.value), + { status: "complete", request: req, response }, + ]; +} diff --git a/src/funcs/users/usersListCustomers.ts b/src/funcs/users/usersListCustomers.ts new file mode 100644 index 0000000..03cf04e --- /dev/null +++ b/src/funcs/users/usersListCustomers.ts @@ -0,0 +1,190 @@ +/* + * List user customers. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { + encodeSimple, + encodeFormQuery, + queryJoin, +} from "../../lib/encodings.js"; +import * as M from "../../lib/matchers.js"; +import { safeParse } from "../../lib/schemas.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import * as errors from "../../models/errors/index.js"; +import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import * as operations from "../../models/operations/index.js"; +import { ListUserCustomersResponse$inboundSchema } from "../../models/operations/users-customers.js"; +import { applyPaginationParams } from "../../models/pagination.js"; +import { APICall, APIPromise } from "../../types/async.js"; +import { OK, Result } from "../../types/fp.js"; + +export function usersListCustomers( + client: ClientSDK, + request: operations.ListUserCustomersRequest, + options?: RequestOptions, +): APIPromise< + Result< + operations.ListUserCustomersResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + > +> { + return new APIPromise($do( + client, + request, + options, + )); +} + +async function $do( + client: ClientSDK, + request: operations.ListUserCustomersRequest, + options?: RequestOptions, +): Promise< + [ + Result< + operations.ListUserCustomersResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >, + APICall, + ] +> { + const parsed = safeParse( + request, + (value) => + operations.ListUserCustomersRequest$outboundSchema.parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return [parsed, { status: "invalid" }]; + } + const payload = parsed.value; + const body = null; + + const path = encodeSimple( + "/users/{id}/customers", + { "id": payload.id }, + { explode: false, charEncoding: "percent" }, + ) || ""; + + const baseQuery = encodeFormQuery({ + page: payload.page, + limit: payload.limit, + }); + + const query = queryJoin(baseQuery); + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + options: client._options, + baseURL: options?.serverURL ?? client._baseURL ?? "", + operationID: "users.listCustomers", + oAuth2Scopes: null, + resolvedSecurity: requestSecurity, + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { + strategy: "backoff", + backoff: { + initialInterval: 500, + maxInterval: 5000, + exponent: 2, + maxElapsedTime: 7500, + }, + retryConnectionErrors: true, + } + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["5xx"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "GET", + baseURL: options?.serverURL, + path, + headers, + query, + body, + userAgent: client._options.userAgent, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return [requestRes, { status: "invalid" }]; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "4XX", "5XX"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return [doResult, { status: "request-error", request: req }]; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.ListUserCustomersResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >( + M.json(200, ListUserCustomersResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.fail("5XX"), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return [result, { status: "complete", request: req, response }]; + } + + return [ + OK(applyPaginationParams(result.value, payload)), + { status: "complete", request: req, response }, + ]; +} diff --git a/src/funcs/users/usersListMfaMethods.ts b/src/funcs/users/usersListMfaMethods.ts new file mode 100644 index 0000000..34f1d71 --- /dev/null +++ b/src/funcs/users/usersListMfaMethods.ts @@ -0,0 +1,190 @@ +/* + * List user MFA methods. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { + encodeSimple, + encodeFormQuery, + queryJoin, +} from "../../lib/encodings.js"; +import * as M from "../../lib/matchers.js"; +import { safeParse } from "../../lib/schemas.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import * as errors from "../../models/errors/index.js"; +import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import * as operations from "../../models/operations/index.js"; +import { ListUserMfaMethodsResponse$inboundSchema } from "../../models/operations/users-mfa.js"; +import { applyPaginationParams } from "../../models/pagination.js"; +import { APICall, APIPromise } from "../../types/async.js"; +import { OK, Result } from "../../types/fp.js"; + +export function usersListMfaMethods( + client: ClientSDK, + request: operations.ListUserMfaMethodsRequest, + options?: RequestOptions, +): APIPromise< + Result< + operations.ListUserMfaMethodsResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + > +> { + return new APIPromise($do( + client, + request, + options, + )); +} + +async function $do( + client: ClientSDK, + request: operations.ListUserMfaMethodsRequest, + options?: RequestOptions, +): Promise< + [ + Result< + operations.ListUserMfaMethodsResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >, + APICall, + ] +> { + const parsed = safeParse( + request, + (value) => + operations.ListUserMfaMethodsRequest$outboundSchema.parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return [parsed, { status: "invalid" }]; + } + const payload = parsed.value; + const body = null; + + const path = encodeSimple( + "/users/{id}/mfa-methods", + { "id": payload.id }, + { explode: false, charEncoding: "percent" }, + ) || ""; + + const baseQuery = encodeFormQuery({ + page: payload.page, + limit: payload.limit, + }); + + const query = queryJoin(baseQuery); + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + options: client._options, + baseURL: options?.serverURL ?? client._baseURL ?? "", + operationID: "users.listMfaMethods", + oAuth2Scopes: null, + resolvedSecurity: requestSecurity, + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { + strategy: "backoff", + backoff: { + initialInterval: 500, + maxInterval: 5000, + exponent: 2, + maxElapsedTime: 7500, + }, + retryConnectionErrors: true, + } + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["5xx"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "GET", + baseURL: options?.serverURL, + path, + headers, + query, + body, + userAgent: client._options.userAgent, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return [requestRes, { status: "invalid" }]; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "4XX", "5XX"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return [doResult, { status: "request-error", request: req }]; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.ListUserMfaMethodsResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >( + M.json(200, ListUserMfaMethodsResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.fail("5XX"), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return [result, { status: "complete", request: req, response }]; + } + + return [ + OK(applyPaginationParams(result.value, payload)), + { status: "complete", request: req, response }, + ]; +} diff --git a/src/funcs/users/usersListOAuthAccounts.ts b/src/funcs/users/usersListOAuthAccounts.ts new file mode 100644 index 0000000..9813a38 --- /dev/null +++ b/src/funcs/users/usersListOAuthAccounts.ts @@ -0,0 +1,190 @@ +/* + * List user OAuth accounts. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { + encodeSimple, + encodeFormQuery, + queryJoin, +} from "../../lib/encodings.js"; +import * as M from "../../lib/matchers.js"; +import { safeParse } from "../../lib/schemas.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import * as errors from "../../models/errors/index.js"; +import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import * as operations from "../../models/operations/index.js"; +import { ListUserOAuthAccountsResponse$inboundSchema } from "../../models/operations/users-oauth-accounts.js"; +import { applyPaginationParams } from "../../models/pagination.js"; +import { APICall, APIPromise } from "../../types/async.js"; +import { OK, Result } from "../../types/fp.js"; + +export function usersListOAuthAccounts( + client: ClientSDK, + request: operations.ListUserOAuthAccountsRequest, + options?: RequestOptions, +): APIPromise< + Result< + operations.ListUserOAuthAccountsResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + > +> { + return new APIPromise($do( + client, + request, + options, + )); +} + +async function $do( + client: ClientSDK, + request: operations.ListUserOAuthAccountsRequest, + options?: RequestOptions, +): Promise< + [ + Result< + operations.ListUserOAuthAccountsResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >, + APICall, + ] +> { + const parsed = safeParse( + request, + (value) => + operations.ListUserOAuthAccountsRequest$outboundSchema.parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return [parsed, { status: "invalid" }]; + } + const payload = parsed.value; + const body = null; + + const path = encodeSimple( + "/users/{id}/oauthaccounts", + { "id": payload.id }, + { explode: false, charEncoding: "percent" }, + ) || ""; + + const baseQuery = encodeFormQuery({ + page: payload.page, + limit: payload.limit, + }); + + const query = queryJoin(baseQuery); + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + options: client._options, + baseURL: options?.serverURL ?? client._baseURL ?? "", + operationID: "users.listOAuthAccounts", + oAuth2Scopes: null, + resolvedSecurity: requestSecurity, + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { + strategy: "backoff", + backoff: { + initialInterval: 500, + maxInterval: 5000, + exponent: 2, + maxElapsedTime: 7500, + }, + retryConnectionErrors: true, + } + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["5xx"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "GET", + baseURL: options?.serverURL, + path, + headers, + query, + body, + userAgent: client._options.userAgent, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return [requestRes, { status: "invalid" }]; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "4XX", "5XX"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return [doResult, { status: "request-error", request: req }]; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.ListUserOAuthAccountsResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >( + M.json(200, ListUserOAuthAccountsResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.fail("5XX"), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return [result, { status: "complete", request: req, response }]; + } + + return [ + OK(applyPaginationParams(result.value, payload)), + { status: "complete", request: req, response }, + ]; +} diff --git a/src/funcs/users/usersListRecoveryCodes.ts b/src/funcs/users/usersListRecoveryCodes.ts new file mode 100644 index 0000000..3e2d6f3 --- /dev/null +++ b/src/funcs/users/usersListRecoveryCodes.ts @@ -0,0 +1,190 @@ +/* + * List user recovery codes. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { + encodeSimple, + encodeFormQuery, + queryJoin, +} from "../../lib/encodings.js"; +import * as M from "../../lib/matchers.js"; +import { safeParse } from "../../lib/schemas.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import * as errors from "../../models/errors/index.js"; +import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import * as operations from "../../models/operations/index.js"; +import { ListUserRecoveryCodesResponse$inboundSchema } from "../../models/operations/users-recovery-codes.js"; +import { applyPaginationParams } from "../../models/pagination.js"; +import { APICall, APIPromise } from "../../types/async.js"; +import { OK, Result } from "../../types/fp.js"; + +export function usersListRecoveryCodes( + client: ClientSDK, + request: operations.ListUserRecoveryCodesRequest, + options?: RequestOptions, +): APIPromise< + Result< + operations.ListUserRecoveryCodesResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + > +> { + return new APIPromise($do( + client, + request, + options, + )); +} + +async function $do( + client: ClientSDK, + request: operations.ListUserRecoveryCodesRequest, + options?: RequestOptions, +): Promise< + [ + Result< + operations.ListUserRecoveryCodesResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >, + APICall, + ] +> { + const parsed = safeParse( + request, + (value) => + operations.ListUserRecoveryCodesRequest$outboundSchema.parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return [parsed, { status: "invalid" }]; + } + const payload = parsed.value; + const body = null; + + const path = encodeSimple( + "/users/{id}/recovery-codes", + { "id": payload.id }, + { explode: false, charEncoding: "percent" }, + ) || ""; + + const baseQuery = encodeFormQuery({ + page: payload.page, + limit: payload.limit, + }); + + const query = queryJoin(baseQuery); + + const headers = new Headers({ + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + options: client._options, + baseURL: options?.serverURL ?? client._baseURL ?? "", + operationID: "users.listRecoveryCodes", + oAuth2Scopes: null, + resolvedSecurity: requestSecurity, + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { + strategy: "backoff", + backoff: { + initialInterval: 500, + maxInterval: 5000, + exponent: 2, + maxElapsedTime: 7500, + }, + retryConnectionErrors: true, + } + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["5xx"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "GET", + baseURL: options?.serverURL, + path, + headers, + query, + body, + userAgent: client._options.userAgent, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return [requestRes, { status: "invalid" }]; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "4XX", "5XX"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return [doResult, { status: "request-error", request: req }]; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.ListUserRecoveryCodesResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >( + M.json(200, ListUserRecoveryCodesResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.fail("5XX"), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return [result, { status: "complete", request: req, response }]; + } + + return [ + OK(applyPaginationParams(result.value, payload)), + { status: "complete", request: req, response }, + ]; +} diff --git a/src/funcs/users/usersRegenerateRecoveryCodes.ts b/src/funcs/users/usersRegenerateRecoveryCodes.ts new file mode 100644 index 0000000..f9e54f0 --- /dev/null +++ b/src/funcs/users/usersRegenerateRecoveryCodes.ts @@ -0,0 +1,179 @@ +/* + * Regenerate user recovery codes. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { + encodeSimple, +} from "../../lib/encodings.js"; +import * as M from "../../lib/matchers.js"; +import { safeParse } from "../../lib/schemas.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import * as errors from "../../models/errors/index.js"; +import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import * as operations from "../../models/operations/index.js"; +import { RegenerateRecoveryCodesResponse$inboundSchema } from "../../models/operations/users-recovery-codes.js"; +import { APICall, APIPromise } from "../../types/async.js"; +import { OK, Result } from "../../types/fp.js"; + +export function usersRegenerateRecoveryCodes( + client: ClientSDK, + request: operations.RegenerateRecoveryCodesRequest, + options?: RequestOptions, +): APIPromise< + Result< + operations.RegenerateRecoveryCodesResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + > +> { + return new APIPromise($do( + client, + request, + options, + )); +} + +async function $do( + client: ClientSDK, + request: operations.RegenerateRecoveryCodesRequest, + options?: RequestOptions, +): Promise< + [ + Result< + operations.RegenerateRecoveryCodesResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >, + APICall, + ] +> { + const parsed = safeParse( + request, + (value) => + operations.RegenerateRecoveryCodesRequest$outboundSchema.parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return [parsed, { status: "invalid" }]; + } + const payload = parsed.value; + const body = null; + + const path = encodeSimple( + "/users/{id}/recovery-codes", + { "id": payload.id }, + { explode: false, charEncoding: "percent" }, + ) || ""; + + const headers = new Headers({ + Accept: "application/json", + }); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + options: client._options, + baseURL: options?.serverURL ?? client._baseURL ?? "", + operationID: "users.regenerateRecoveryCodes", + oAuth2Scopes: null, + resolvedSecurity: requestSecurity, + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { + strategy: "backoff", + backoff: { + initialInterval: 500, + maxInterval: 5000, + exponent: 2, + maxElapsedTime: 7500, + }, + retryConnectionErrors: true, + } + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["5xx"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "POST", + baseURL: options?.serverURL, + path, + headers, + body, + userAgent: client._options.userAgent, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return [requestRes, { status: "invalid" }]; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "4XX", "5XX"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return [doResult, { status: "request-error", request: req }]; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.RegenerateRecoveryCodesResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >( + M.json(200, RegenerateRecoveryCodesResponse$inboundSchema, { + ctype: "application/json", + }), + M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.fail("5XX"), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return [result, { status: "complete", request: req, response }]; + } + + return [ + OK(result.value), + { status: "complete", request: req, response }, + ]; +} diff --git a/src/funcs/users/usersSendMfa.ts b/src/funcs/users/usersSendMfa.ts new file mode 100644 index 0000000..9bfec4c --- /dev/null +++ b/src/funcs/users/usersSendMfa.ts @@ -0,0 +1,177 @@ +/* + * Send user MFA code. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { + encodeSimple, +} from "../../lib/encodings.js"; +import * as M from "../../lib/matchers.js"; +import { safeParse } from "../../lib/schemas.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import * as errors from "../../models/errors/index.js"; +import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import * as operations from "../../models/operations/index.js"; +import { SendMfaResponse$inboundSchema } from "../../models/operations/users-mfa.js"; +import { APICall, APIPromise } from "../../types/async.js"; +import { OK, Result } from "../../types/fp.js"; + +export function usersSendMfa( + client: ClientSDK, + request: operations.SendMfaRequest, + options?: RequestOptions, +): APIPromise< + Result< + operations.SendMfaResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + > +> { + return new APIPromise($do( + client, + request, + options, + )); +} + +async function $do( + client: ClientSDK, + request: operations.SendMfaRequest, + options?: RequestOptions, +): Promise< + [ + Result< + operations.SendMfaResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >, + APICall, + ] +> { + const parsed = safeParse( + request, + (value) => + operations.SendMfaRequest$outboundSchema.parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return [parsed, { status: "invalid" }]; + } + const payload = parsed.value; + const body = null; + + const path = encodeSimple( + "/users/{id}/mfa-methods/{method}/send", + { "id": payload.id, "method": payload.method }, + { explode: false, charEncoding: "percent" }, + ) || ""; + + const headers = new Headers({ + Accept: "*/*", + }); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + options: client._options, + baseURL: options?.serverURL ?? client._baseURL ?? "", + operationID: "users.sendMfa", + oAuth2Scopes: null, + resolvedSecurity: requestSecurity, + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { + strategy: "backoff", + backoff: { + initialInterval: 500, + maxInterval: 5000, + exponent: 2, + maxElapsedTime: 7500, + }, + retryConnectionErrors: true, + } + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["5xx"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "POST", + baseURL: options?.serverURL, + path, + headers, + body, + userAgent: client._options.userAgent, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return [requestRes, { status: "invalid" }]; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "4XX", "5XX"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return [doResult, { status: "request-error", request: req }]; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.SendMfaResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >( + M.nil("2XX", SendMfaResponse$inboundSchema), + M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.fail("5XX"), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return [result, { status: "complete", request: req, response }]; + } + + return [ + OK(result.value), + { status: "complete", request: req, response }, + ]; +} diff --git a/src/funcs/users/usersValidateMfa.ts b/src/funcs/users/usersValidateMfa.ts new file mode 100644 index 0000000..1fbc944 --- /dev/null +++ b/src/funcs/users/usersValidateMfa.ts @@ -0,0 +1,181 @@ +/* + * Validate user MFA method. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { + encodeSimple, + encodeJSON, +} from "../../lib/encodings.js"; +import * as M from "../../lib/matchers.js"; +import { safeParse } from "../../lib/schemas.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import * as errors from "../../models/errors/index.js"; +import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import * as operations from "../../models/operations/index.js"; +import { ValidateMfaResponse$inboundSchema } from "../../models/operations/users-mfa.js"; +import { APICall, APIPromise } from "../../types/async.js"; +import { OK, Result } from "../../types/fp.js"; + +export function usersValidateMfa( + client: ClientSDK, + request: operations.ValidateMfaRequest, + options?: RequestOptions, +): APIPromise< + Result< + operations.ValidateMfaResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + > +> { + return new APIPromise($do( + client, + request, + options, + )); +} + +async function $do( + client: ClientSDK, + request: operations.ValidateMfaRequest, + options?: RequestOptions, +): Promise< + [ + Result< + operations.ValidateMfaResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >, + APICall, + ] +> { + const parsed = safeParse( + request, + (value) => + operations.ValidateMfaRequest$outboundSchema.parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return [parsed, { status: "invalid" }]; + } + const payload = parsed.value; + const body = encodeJSON("body", { code: payload.code }, { explode: true }); + + const path = encodeSimple( + "/users/{id}/mfa-methods/{method}/validate", + { "id": payload.id, "method": payload.method }, + { explode: false, charEncoding: "percent" }, + ) || ""; + + const headers = new Headers({ + "Content-Type": "application/json", + Accept: "application/hal+json", + }); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + options: client._options, + baseURL: options?.serverURL ?? client._baseURL ?? "", + operationID: "users.validateMfa", + oAuth2Scopes: null, + resolvedSecurity: requestSecurity, + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { + strategy: "backoff", + backoff: { + initialInterval: 500, + maxInterval: 5000, + exponent: 2, + maxElapsedTime: 7500, + }, + retryConnectionErrors: true, + } + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["5xx"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "POST", + baseURL: options?.serverURL, + path, + headers, + body, + userAgent: client._options.userAgent, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return [requestRes, { status: "invalid" }]; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "4XX", "5XX"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return [doResult, { status: "request-error", request: req }]; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.ValidateMfaResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >( + M.json(200, ValidateMfaResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.fail("5XX"), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return [result, { status: "complete", request: req, response }]; + } + + return [ + OK(result.value), + { status: "complete", request: req, response }, + ]; +} diff --git a/src/funcs/users/usersValidateRecoveryCode.ts b/src/funcs/users/usersValidateRecoveryCode.ts new file mode 100644 index 0000000..fa5519a --- /dev/null +++ b/src/funcs/users/usersValidateRecoveryCode.ts @@ -0,0 +1,179 @@ +/* + * Validate user recovery code. + */ + +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import { + encodeSimple, + encodeJSON, +} from "../../lib/encodings.js"; +import * as M from "../../lib/matchers.js"; +import { safeParse } from "../../lib/schemas.js"; +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; +import * as errors from "../../models/errors/index.js"; +import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../../models/errors/http-client-errors.js"; +import * as operations from "../../models/operations/index.js"; +import { ValidateRecoveryCodeResponse$inboundSchema } from "../../models/operations/users-recovery-codes.js"; +import { APICall, APIPromise } from "../../types/async.js"; +import { OK, Result } from "../../types/fp.js"; + +export function usersValidateRecoveryCode( + client: ClientSDK, + request: operations.ValidateRecoveryCodeRequest, + options?: RequestOptions, +): APIPromise< + Result< + operations.ValidateRecoveryCodeResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + > +> { + return new APIPromise($do( + client, + request, + options, + )); +} + +async function $do( + client: ClientSDK, + request: operations.ValidateRecoveryCodeRequest, + options?: RequestOptions, +): Promise< + [ + Result< + operations.ValidateRecoveryCodeResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >, + APICall, + ] +> { + const parsed = safeParse( + request, + (value) => + operations.ValidateRecoveryCodeRequest$outboundSchema.parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return [parsed, { status: "invalid" }]; + } + const payload = parsed.value; + const body = encodeJSON("body", { code: payload.code }, { explode: true }); + + const path = encodeSimple( + "/users/{id}/recovery-codes/validate", + { "id": payload.id }, + { explode: false, charEncoding: "percent" }, + ) || ""; + + const headers = new Headers({ + "Content-Type": "application/json", + Accept: "*/*", + }); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + options: client._options, + baseURL: options?.serverURL ?? client._baseURL ?? "", + operationID: "users.validateRecoveryCode", + oAuth2Scopes: null, + resolvedSecurity: requestSecurity, + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { + strategy: "backoff", + backoff: { + initialInterval: 500, + maxInterval: 5000, + exponent: 2, + maxElapsedTime: 7500, + }, + retryConnectionErrors: true, + } + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["5xx"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "POST", + baseURL: options?.serverURL, + path, + headers, + body, + userAgent: client._options.userAgent, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return [requestRes, { status: "invalid" }]; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "4XX", "5XX"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return [doResult, { status: "request-error", request: req }]; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.ValidateRecoveryCodeResponse, + | errors.ErrorResponse + | errors.OminityDefaultError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >( + M.nil("2XX", ValidateRecoveryCodeResponse$inboundSchema), + M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { + ctype: "application/hal+json", + }), + M.fail("5XX"), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return [result, { status: "complete", request: req, response }]; + } + + return [ + OK(result.value), + { status: "complete", request: req, response }, + ]; +} diff --git a/src/hooks/types.ts b/src/hooks/types.ts index 2b74437..6ea7c6b 100644 --- a/src/hooks/types.ts +++ b/src/hooks/types.ts @@ -4,13 +4,13 @@ import { RetryConfig } from "../lib/retries.js"; import { SecurityState } from "../lib/security.js"; export type HookContext = { - baseURL: string | URL; + baseURL: string | URL | null; operationID: string; oAuth2Scopes: string[] | null; securitySource?: any | (() => Promise); - retryConfig: RetryConfig; + retryConfig: RetryConfig | undefined; resolvedSecurity: SecurityState | null; - options: SDKOptions; + options: SDKOptions | any; }; export type Awaitable = T | Promise; diff --git a/src/lib/encodings.ts b/src/lib/encodings.ts index 8e865f0..077025e 100644 --- a/src/lib/encodings.ts +++ b/src/lib/encodings.ts @@ -438,7 +438,7 @@ type BulkQueryEncoder = ( ) => string; export function queryEncoder(f: QueryEncoder): BulkQueryEncoder { - const bulkEncode = function( + const bulkEncode = function ( values: Record, options?: QueryEncoderOptions, ): string { @@ -474,6 +474,7 @@ export const encodeFormQuery = queryEncoder(encodeForm); export const encodeSpaceDelimitedQuery = queryEncoder(encodeSpaceDelimited); export const encodePipeDelimitedQuery = queryEncoder(encodePipeDelimited); export const encodeDeepObjectQuery = queryEncoder(encodeDeepObject); +export const encodeSimpleQuery = queryEncoder(encodeSimple); export function appendForm( fd: FormData, diff --git a/src/models/cms/component.ts b/src/models/cms/component.ts new file mode 100644 index 0000000..7fac09e --- /dev/null +++ b/src/models/cms/component.ts @@ -0,0 +1,36 @@ +/* + * CMS Component model. + */ + +import * as z from "zod/v4"; +import { remap as remap$ } from "../../lib/primitives.js"; +import { HalLinks, HalLinks$inboundSchema } from "../hal.js"; + +export type Component = { + id: number; + slug: string; + name: string; + description: string; + type: string; + createdAt: string; + updatedAt: string; + links?: HalLinks; +}; + +/** @internal */ +export const Component$inboundSchema: z.ZodType = z.object({ + id: z.number(), + slug: z.string(), + name: z.string(), + description: z.string(), + type: z.string(), + created_at: z.string(), + updated_at: z.string(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => { + return remap$(v, { + "created_at": "createdAt", + "updated_at": "updatedAt", + "_links": "links", + }) as Component; +}); diff --git a/src/models/cms/index.ts b/src/models/cms/index.ts new file mode 100644 index 0000000..62af4ad --- /dev/null +++ b/src/models/cms/index.ts @@ -0,0 +1,8 @@ +export * from "./component.js"; +export * from "./layout.js"; +export * from "./page.js"; +export * from "./menu.js"; +export * from "./page-component.js"; + + + diff --git a/src/models/cms/layout.ts b/src/models/cms/layout.ts new file mode 100644 index 0000000..d3edb72 --- /dev/null +++ b/src/models/cms/layout.ts @@ -0,0 +1,30 @@ +/* + * CMS Layout model. + */ + +import * as z from "zod/v4"; +import { remap as remap$ } from "../../lib/primitives.js"; +import { HalLinks, HalLinks$inboundSchema } from "../hal.js"; + +export type Layout = { + resource: string; + id: number; + name: string; + createdAt: string; + updatedAt: string; + links?: HalLinks; +}; + +/** @internal */ +export const Layout$inboundSchema: z.ZodType = z.object({ + resource: z.string(), + id: z.number(), + name: z.string(), + createdAt: z.string(), + updatedAt: z.string(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => { + return remap$(v, { + "_links": "links", + }) as Layout; +}); diff --git a/src/models/cms/menu.ts b/src/models/cms/menu.ts new file mode 100644 index 0000000..9532146 --- /dev/null +++ b/src/models/cms/menu.ts @@ -0,0 +1,32 @@ +/* + * CMS Menu model. + */ + +import * as z from "zod/v4"; +import { remap as remap$ } from "../../lib/primitives.js"; +import { HalLinks, HalLinks$inboundSchema } from "../hal.js"; + +export type Menu = { + resource: string; + id: number; + name: string; + slug: string; + createdAt: string; + updatedAt: string; + links?: HalLinks; +}; + +/** @internal */ +export const Menu$inboundSchema: z.ZodType = z.object({ + resource: z.string(), + id: z.number(), + name: z.string(), + slug: z.string(), + createdAt: z.string(), + updatedAt: z.string(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => { + return remap$(v, { + "_links": "links", + }) as Menu; +}); diff --git a/src/models/cms/page-component.ts b/src/models/cms/page-component.ts new file mode 100644 index 0000000..a64981a --- /dev/null +++ b/src/models/cms/page-component.ts @@ -0,0 +1,38 @@ +/* + * CMS Page Component model. + */ + +import * as z from "zod/v4"; +import { remap as remap$ } from "../../lib/primitives.js"; +import { HalLinks, HalLinks$inboundSchema } from "../hal.js"; + +export type PageComponent = { + resource: string; + id: number; + pageId: number; + componentId: number; + order: number; + parameters: Record; + createdAt: string; + updatedAt: string; + links?: HalLinks; +}; + +/** @internal */ +export const PageComponent$inboundSchema: z.ZodType = z.object({ + resource: z.string(), + id: z.number(), + pageId: z.number(), + componentId: z.number(), + order: z.number(), + parameters: z.record(z.string(), z.any()), + created_at: z.string(), + updated_at: z.string(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => { + return remap$(v, { + "created_at": "createdAt", + "updated_at": "updatedAt", + "_links": "links", + }) as PageComponent; +}); diff --git a/src/models/cms/page.ts b/src/models/cms/page.ts new file mode 100644 index 0000000..43e4c41 --- /dev/null +++ b/src/models/cms/page.ts @@ -0,0 +1,40 @@ +/* + * CMS Page model. + */ + +import * as z from "zod/v4"; +import { remap as remap$ } from "../../lib/primitives.js"; +import { HalLinks, HalLinks$inboundSchema } from "../hal.js"; + +export type Page = { + resource: string; + id: number; + slug: string; + title: string; + description: string; + type: string; + published: boolean; + createdAt: string; + updatedAt: string; + links?: HalLinks; +}; + +/** @internal */ +export const Page$inboundSchema: z.ZodType = z.object({ + resource: z.string(), + id: z.number(), + slug: z.string(), + title: z.string(), + description: z.string(), + type: z.string(), + published: z.boolean(), + created_at: z.string(), + updated_at: z.string(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => { + return remap$(v, { + "created_at": "createdAt", + "updated_at": "updatedAt", + "_links": "links", + }) as Page; +}); diff --git a/src/models/commerce/address.ts b/src/models/commerce/address.ts index 3d3288d..6f5b528 100644 --- a/src/models/commerce/address.ts +++ b/src/models/commerce/address.ts @@ -1,30 +1,43 @@ /* - * Address model. + * Commerce Address model. */ import * as z from "zod/v4"; export type Address = { - firstName?: string | null | undefined; - lastName?: string | null | undefined; - street?: string | null | undefined; - number?: string | null | undefined; - additional?: string | null | undefined; - postalCode?: string | null | undefined; - city?: string | null | undefined; - region?: string | null | undefined; - country?: string | null | undefined; + firstName: string; + lastName: string; + street: string; + number: string; + additional: string; + postalCode: string; + city: string; + region: string; + country: string; }; /** @internal */ export const Address$inboundSchema: z.ZodType
= z.object({ - firstName: z.string().nullable().optional(), - lastName: z.string().nullable().optional(), - street: z.string().nullable().optional(), - number: z.string().nullable().optional(), - additional: z.string().nullable().optional(), - postalCode: z.string().nullable().optional(), - city: z.string().nullable().optional(), - region: z.string().nullable().optional(), - country: z.string().nullable().optional(), + firstName: z.string(), + lastName: z.string(), + street: z.string(), + number: z.string(), + additional: z.string(), + postalCode: z.string(), + city: z.string(), + region: z.string(), + country: z.string(), +}); + +/** @internal */ +export const Address$outboundSchema: z.ZodType
= z.object({ + firstName: z.string(), + lastName: z.string(), + street: z.string(), + number: z.string(), + additional: z.string(), + postalCode: z.string(), + city: z.string(), + region: z.string(), + country: z.string(), }); diff --git a/src/models/commerce/cart-item.ts b/src/models/commerce/cart-item.ts index 17b8e93..e1f35ac 100644 --- a/src/models/commerce/cart-item.ts +++ b/src/models/commerce/cart-item.ts @@ -1,83 +1,33 @@ -/* - * Cart item model. - */ - import * as z from "zod/v4"; -import { remap as remap$ } from "../../lib/primitives.js"; -import { CurrencyAmount, CurrencyAmount$inboundSchema } from "../common/amount.js"; -import { HalLinks, HalLinks$inboundSchema } from "../hal.js"; -import { Product, Product$inboundSchema } from "./product.js"; -import { ProductOffer, ProductOffer$inboundSchema } from "./product-offer.js"; -import { buildPaginated, Paginated } from "../pagination.js"; + +// Placeholder - waiting for actual data structure from user export type CartItem = { - resource: string; - id: string; - cartId: string; - productId: number; - productOfferId: number; - quantity: number; - unitAmount: CurrencyAmount; - discountAmount: CurrencyAmount; - taxAmount: CurrencyAmount; - totalAmount: CurrencyAmount; - isShippingRequired: boolean; - updatedAt: string; - createdAt: string; - product?: Product; - offer?: ProductOffer; - links?: HalLinks; + id?: string; + [key: string]: any; }; -export type CartItemsListResponse = Paginated; - /** @internal */ -export const CartItem$inboundSchema: z.ZodType = z.object({ - resource: z.string(), - id: z.string(), - cartId: z.string(), - productId: z.number(), - productOfferId: z.number(), - quantity: z.number(), - unitAmount: CurrencyAmount$inboundSchema, - discountAmount: CurrencyAmount$inboundSchema, - taxAmount: CurrencyAmount$inboundSchema, - totalAmount: CurrencyAmount$inboundSchema, - isShippingRequired: z.boolean(), - updatedAt: z.string(), - createdAt: z.string(), - _links: HalLinks$inboundSchema.optional(), - _embedded: z.object({ - product: Product$inboundSchema.optional(), - offer: ProductOffer$inboundSchema.optional(), - }).loose().optional(), -}).transform((v) => { - const { _embedded } = v; - const remapped = remap$(v, { _links: "links", _embedded: null }); - - if (_embedded?.product !== undefined) { - (remapped as CartItem).product = _embedded.product; - } - if (_embedded?.offer !== undefined) { - (remapped as CartItem).offer = _embedded.offer; - } - - return remapped as CartItem; -}); +export const CartItem$inboundSchema: z.ZodType = z + .object({ + id: z.string().optional(), + }) + .passthrough() as unknown as z.ZodType; /** @internal */ -export const CartItemsListResponse$inboundSchema: z.ZodType< - Paginated -> = z.object({ - _embedded: z.object({ - cart_items: z.array(CartItem$inboundSchema), - }), - count: z.number(), - _links: HalLinks$inboundSchema.optional(), -}).transform((v) => - buildPaginated( - v._embedded.cart_items, - v.count, - v._links, - ) -); +export const CartItem$outboundSchema: z.ZodType = z + .object({ + id: z.string().optional(), + }) + .passthrough() as unknown as z.ZodType; + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace CartItem$ { + /** @deprecated use `CartItem$inboundSchema` instead. */ + export const inboundSchema = CartItem$inboundSchema; + /** @deprecated use `CartItem$outboundSchema` instead. */ + export const outboundSchema = CartItem$outboundSchema; +} diff --git a/src/models/commerce/cart.ts b/src/models/commerce/cart.ts index 5262d7c..521c373 100644 --- a/src/models/commerce/cart.ts +++ b/src/models/commerce/cart.ts @@ -1,38 +1,69 @@ -/* - * Cart model. - */ - import * as z from "zod/v4"; import { remap as remap$ } from "../../lib/primitives.js"; -import * as openEnums from "../../types/enums.js"; -import { OpenEnum } from "../../types/enums.js"; -import { Address, Address$inboundSchema } from "./address.js"; -import { CurrencyAmount, CurrencyAmount$inboundSchema } from "../common/amount.js"; -import { HalLinks, HalLinks$inboundSchema } from "../hal.js"; -import { buildPaginated, Paginated } from "../pagination.js"; -import { CartItem, CartItem$inboundSchema } from "./cart-item.js"; +import { + CurrencyAmount, + CurrencyAmount$inboundSchema, + CurrencyAmount$outboundSchema, +} from "../common/amount.js"; +import { + Address, + Address$inboundSchema, + Address$outboundSchema, +} from "./address.js"; + +export type CartLinks = { + self: { + href: string; + type: string; + }; + customer?: { + href: string; + type: string; + }; +}; -export const CartStatus = { - Open: "open", - Completed: "completed", - Abandoned: "abandoned", - Expired: "expired", -} as const; -export type CartStatus = OpenEnum; +/** @internal */ +export const CartLinks$inboundSchema: z.ZodType = z.object({ + self: z.object({ + href: z.string(), + type: z.string(), + }), + customer: z.object({ + href: z.string(), + type: z.string(), + }).optional(), +}) as unknown as z.ZodType; -export const CartType = { - Shared: "shared", - Default: "default", -} as const; -export type CartType = OpenEnum; +/** @internal */ +export const CartLinks$outboundSchema: z.ZodType = z.object({ + self: z.object({ + href: z.string(), + type: z.string(), + }), + customer: z.object({ + href: z.string(), + type: z.string(), + }).optional(), +}) as unknown as z.ZodType; + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace CartLinks$ { + /** @deprecated use `CartLinks$inboundSchema` instead. */ + export const inboundSchema = CartLinks$inboundSchema; + /** @deprecated use `CartLinks$outboundSchema` instead. */ + export const outboundSchema = CartLinks$outboundSchema; +} export type Cart = { resource: string; id: string; - status: CartStatus; - type: CartType; - channelId?: number; - languageId?: number | null; + status: string; + type: string; + channelId: number; + languageId?: string | null; customerId?: number | null; userId?: number | null; email?: string; @@ -40,89 +71,106 @@ export type Cart = { companyVat?: string; billingAddress?: Address; shippingAddress?: Address; - subtotalAmount?: CurrencyAmount; - shippingAmount?: CurrencyAmount; - discountAmount?: CurrencyAmount; - taxAmount?: CurrencyAmount; - totalAmount?: CurrencyAmount; - country?: string; - currency?: string; - isShippingRequired?: boolean; - shippingMethodId?: number | null; - isTaxExempt?: boolean; - items?: CartItem[]; - itemsCount?: number; - itemsExists?: boolean; - shippingMethod?: unknown; - shippingMethodCount?: number; - shippingMethodExists?: boolean; - totalQuantity?: number; - promotionCodes?: string[]; - updatedAt?: string; - createdAt?: string; - links?: HalLinks; + subtotalAmount: CurrencyAmount; + shippingAmount: CurrencyAmount; + discountAmount: CurrencyAmount; + taxAmount: CurrencyAmount; + totalAmount: CurrencyAmount; + country: string; + currency: string; + isShippingRequired: boolean; + shippingMethodId?: string | null; + isTaxExempt: boolean; + totalQuantity: number; + promotionCodes?: Array; + updatedAt: string; + createdAt: string; + links: CartLinks; }; /** @internal */ -export const CartStatus$inboundSchema: z.ZodType = openEnums - .inboundSchema(CartStatus); -/** @internal */ -export const CartType$inboundSchema: z.ZodType = openEnums - .inboundSchema(CartType); +export const Cart$inboundSchema: z.ZodType = z + .object({ + resource: z.string(), + id: z.string(), + status: z.string(), + type: z.string(), + channelId: z.number().int(), + languageId: z.nullable(z.string()).optional(), + customerId: z.nullable(z.number().int()).optional(), + userId: z.nullable(z.number().int()).optional(), + email: z.string().optional(), + companyName: z.string().optional(), + companyVat: z.string().optional(), + billingAddress: Address$inboundSchema.optional(), + shippingAddress: Address$outboundSchema.optional(), + subtotalAmount: CurrencyAmount$inboundSchema, + shippingAmount: CurrencyAmount$inboundSchema, + discountAmount: CurrencyAmount$inboundSchema, + taxAmount: CurrencyAmount$inboundSchema, + totalAmount: CurrencyAmount$inboundSchema, + country: z.string(), + currency: z.string(), + isShippingRequired: z.boolean(), + shippingMethodId: z.nullable(z.string()).optional(), + isTaxExempt: z.boolean(), + totalQuantity: z.number().int(), + promotionCodes: z.array(z.string()).optional(), + updatedAt: z.string(), + createdAt: z.string(), + _links: CartLinks$inboundSchema, + }) + .transform((v) => { + return remap$(v, { + _links: "links", + }); + }) as unknown as z.ZodType; /** @internal */ -export const Cart$inboundSchema: z.ZodType = z.object({ - resource: z.string(), - id: z.string(), - status: CartStatus$inboundSchema, - type: CartType$inboundSchema, - channelId: z.number().optional(), - languageId: z.number().nullable().optional(), - customerId: z.number().nullable().optional(), - userId: z.number().nullable().optional(), - email: z.string().optional(), - companyName: z.string().optional(), - companyVat: z.string().optional(), - billingAddress: Address$inboundSchema.optional(), - shippingAddress: Address$inboundSchema.optional(), - subtotalAmount: CurrencyAmount$inboundSchema.optional(), - shippingAmount: CurrencyAmount$inboundSchema.optional(), - discountAmount: CurrencyAmount$inboundSchema.optional(), - taxAmount: CurrencyAmount$inboundSchema.optional(), - totalAmount: CurrencyAmount$inboundSchema.optional(), - country: z.string().optional(), - currency: z.string().optional(), - isShippingRequired: z.boolean().optional(), - shippingMethodId: z.number().nullable().optional(), - isTaxExempt: z.boolean().optional(), - items: z.array(CartItem$inboundSchema).optional(), - itemsCount: z.number().optional(), - itemsExists: z.boolean().optional(), - shippingMethod: z.any().optional(), - shippingMethodCount: z.number().optional(), - shippingMethodExists: z.boolean().optional(), - totalQuantity: z.number().optional(), - promotionCodes: z.array(z.string()).optional(), - updatedAt: z.string().optional(), - createdAt: z.string().optional(), - _links: HalLinks$inboundSchema.optional(), -}).transform((v) => remap$(v, { _links: "links" }) as Cart); - -export type CartsListResponse = Paginated; +export const Cart$outboundSchema: z.ZodType = z + .object({ + resource: z.string(), + id: z.string(), + status: z.string(), + type: z.string(), + channelId: z.number().int(), + languageId: z.nullable(z.string()).optional(), + customerId: z.nullable(z.number().int()).optional(), + userId: z.nullable(z.number().int()).optional(), + email: z.string().optional(), + companyName: z.string().optional(), + companyVat: z.string().optional(), + billingAddress: Address$outboundSchema.optional(), + shippingAddress: Address$outboundSchema.optional(), + subtotalAmount: CurrencyAmount$outboundSchema, + shippingAmount: CurrencyAmount$outboundSchema, + discountAmount: CurrencyAmount$outboundSchema, + taxAmount: CurrencyAmount$outboundSchema, + totalAmount: CurrencyAmount$outboundSchema, + country: z.string(), + currency: z.string(), + isShippingRequired: z.boolean(), + shippingMethodId: z.nullable(z.string()).optional(), + isTaxExempt: z.boolean(), + totalQuantity: z.number().int(), + promotionCodes: z.array(z.string()).optional(), + updatedAt: z.string(), + createdAt: z.string(), + links: CartLinks$outboundSchema, + }) + .transform((v) => { + return remap$(v, { + links: "_links", + }); + }) as unknown as z.ZodType; -/** @internal */ -export const CartsListResponse$inboundSchema: z.ZodType< - CartsListResponse -> = z.object({ - _embedded: z.object({ - carts: z.array(Cart$inboundSchema), - }), - count: z.number(), - _links: HalLinks$inboundSchema.optional(), -}).transform((v) => - buildPaginated( - v._embedded.carts, - v.count, - v._links, - ) -); +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace Cart$ { + /** @deprecated use `Cart$inboundSchema` instead. */ + export const inboundSchema = Cart$inboundSchema; + /** @deprecated use `Cart$outboundSchema` instead. */ + export const outboundSchema = Cart$outboundSchema; +} diff --git a/src/models/commerce/currency.ts b/src/models/commerce/currency.ts new file mode 100644 index 0000000..8f96060 --- /dev/null +++ b/src/models/commerce/currency.ts @@ -0,0 +1,117 @@ +import * as z from "zod/v4"; +import { remap as remap$ } from "../../lib/primitives.js"; + +export type CurrencyFormat = { + prefix: string; + thousandsSeparator: string; + decimalSeparator: string; + suffix?: string | null; +}; + +/** @internal */ +export const CurrencyFormat$inboundSchema: z.ZodType = z.object({ + prefix: z.string(), + thousandsSeparator: z.string(), + decimalSeparator: z.string(), + suffix: z.nullable(z.string()).optional(), +}) as unknown as z.ZodType; + +/** @internal */ +export const CurrencyFormat$outboundSchema: z.ZodType = z.object({ + prefix: z.string(), + thousandsSeparator: z.string(), + decimalSeparator: z.string(), + suffix: z.nullable(z.string()).optional(), +}) as unknown as z.ZodType; + +export type CurrencyLinks = { + self: { + href: string; + type: string; + }; +}; + +/** @internal */ +export const CurrencyLinks$inboundSchema: z.ZodType = z.object({ + self: z.object({ + href: z.string(), + type: z.string(), + }), +}) as unknown as z.ZodType; + +/** @internal */ +export const CurrencyLinks$outboundSchema: z.ZodType = z.object({ + self: z.object({ + href: z.string(), + type: z.string(), + }), +}) as unknown as z.ZodType; + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace CurrencyLinks$ { + /** @deprecated use `CurrencyLinks$inboundSchema` instead. */ + export const inboundSchema = CurrencyLinks$inboundSchema; + /** @deprecated use `CurrencyLinks$outboundSchema` instead. */ + export const outboundSchema = CurrencyLinks$outboundSchema; +} + +export type Currency = { + resource: string; + code: string; + name: string; + conversion: number; + format: CurrencyFormat; + isEnabled: boolean; + isDefault: boolean; + links: CurrencyLinks; +}; + +/** @internal */ +export const Currency$inboundSchema: z.ZodType = z + .object({ + resource: z.string(), + code: z.string(), + name: z.string(), + conversion: z.number(), + format: CurrencyFormat$inboundSchema, + isEnabled: z.boolean(), + isDefault: z.boolean(), + _links: CurrencyLinks$inboundSchema, + }) + .transform((v) => { + return remap$(v, { + _links: "links", + }); + }) as unknown as z.ZodType; + +/** @internal */ +export const Currency$outboundSchema: z.ZodType = z + .object({ + resource: z.string(), + code: z.string(), + name: z.string(), + conversion: z.number(), + format: CurrencyFormat$outboundSchema, + isEnabled: z.boolean(), + isDefault: z.boolean(), + links: CurrencyLinks$outboundSchema, + }) + .transform((v) => { + return remap$(v, { + links: "_links", + }); + }) as unknown as z.ZodType; + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace Currency$ { + /** @deprecated use `Currency$inboundSchema` instead. */ + export const inboundSchema = Currency$inboundSchema; + /** @deprecated use `Currency$outboundSchema` instead. */ + export const outboundSchema = Currency$outboundSchema; +} diff --git a/src/models/commerce/customer-user.ts b/src/models/commerce/customer-user.ts new file mode 100644 index 0000000..b8b9918 --- /dev/null +++ b/src/models/commerce/customer-user.ts @@ -0,0 +1,40 @@ +/* + * Customer User model. + */ + +import * as z from "zod/v4"; +import { remap as remap$ } from "../../lib/primitives.js"; +import { HalLinks, HalLinks$inboundSchema } from "../hal.js"; + +export type CustomerUser = { + resource: "customer_user"; + userId: number; + customerId: number; + roleId: number; + firstName: string; + lastName: string; + email: string; + avatar?: string | null; + updatedAt: string; + createdAt: string; + links?: HalLinks; +}; + +/** @internal */ +export const CustomerUser$inboundSchema: z.ZodType = z.object({ + resource: z.literal("customer_user"), + userId: z.number().int(), + customerId: z.number().int(), + roleId: z.number().int(), + firstName: z.string(), + lastName: z.string(), + email: z.string(), + avatar: z.string().nullable().optional(), + updatedAt: z.string(), + createdAt: z.string(), + _links: HalLinks$inboundSchema.optional(), +}).loose().transform((v) => { + return remap$(v, { + "_links": "links", + }) as CustomerUser; +}); diff --git a/src/models/commerce/index.ts b/src/models/commerce/index.ts index 112d3be..cd581b5 100644 --- a/src/models/commerce/index.ts +++ b/src/models/commerce/index.ts @@ -11,3 +11,13 @@ export * from "./cart-item.js"; export * from "./address.js"; export * from "./money.js"; export * from "./route.js"; +export * from "./subscription-interval.js"; + +export * from "./invoice.js"; +export * from "./order.js"; +export * from "./payment.js"; +export * from "./vat-validation.js"; +export * from "./shipping-method.js"; +export * from "./shipping-zone.js"; +export * from "./review.js"; +export * from "./currency.js"; diff --git a/src/models/commerce/invoice.ts b/src/models/commerce/invoice.ts new file mode 100644 index 0000000..ca9e5b4 --- /dev/null +++ b/src/models/commerce/invoice.ts @@ -0,0 +1,76 @@ +/* + * Invoice model. + */ + +import * as z from "zod/v4"; +import { remap as remap$ } from "../../lib/primitives.js"; +import * as openEnums from "../../types/enums.js"; +import { OpenEnum } from "../../types/enums.js"; +import { Address, Address$inboundSchema } from "./address.js"; +import { CurrencyAmount, CurrencyAmount$inboundSchema } from "../common/amount.js"; +import { HalLinks, HalLinks$inboundSchema } from "../hal.js"; + +export const InvoiceStatus = { + Paid: "paid", + Credited: "credited", + Open: "open", + Overdue: "overdue", + Voided: "voided", + Draft: "draft", +} as const; +export type InvoiceStatus = OpenEnum; + +export type Invoice = { + resource: string; + id: number; + customerId: number; + number: string; + status: InvoiceStatus; + email: string; + companyName: string; + companyVat: string; + billingAddress: Address; + subtotalAmount: CurrencyAmount; + discountAmount: CurrencyAmount; + vatAmount: CurrencyAmount; + totalAmount: CurrencyAmount; + amountPaid: CurrencyAmount; + isTaxExempt: boolean; + notes: string; + invoicedAt: string; + dueAt: string; + paidAt: string; + updatedAt: string; + createdAt: string; + links?: HalLinks; +}; + +/** @internal */ +export const InvoiceStatus$inboundSchema: z.ZodType = openEnums + .inboundSchema(InvoiceStatus); + +/** @internal */ +export const Invoice$inboundSchema: z.ZodType = z.object({ + resource: z.string(), + id: z.number(), + customerId: z.number(), + number: z.string(), + status: InvoiceStatus$inboundSchema, + email: z.string(), + companyName: z.string(), + companyVat: z.string(), + billingAddress: Address$inboundSchema, + subtotalAmount: CurrencyAmount$inboundSchema, + discountAmount: CurrencyAmount$inboundSchema, + vatAmount: CurrencyAmount$inboundSchema, + totalAmount: CurrencyAmount$inboundSchema, + amountPaid: CurrencyAmount$inboundSchema, + isTaxExempt: z.boolean(), + notes: z.string(), + invoicedAt: z.string(), + dueAt: z.string(), + paidAt: z.string(), + updatedAt: z.string(), + createdAt: z.string(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => remap$(v, { _links: "links" }) as Invoice); diff --git a/src/models/commerce/order.ts b/src/models/commerce/order.ts new file mode 100644 index 0000000..f8add10 --- /dev/null +++ b/src/models/commerce/order.ts @@ -0,0 +1,85 @@ +/* + * Commerce Order model. + */ + +import * as z from "zod/v4"; +import { remap as remap$ } from "../../lib/primitives.js"; +import { HalLinks, HalLinks$inboundSchema } from "../hal.js"; +import { Address, Address$inboundSchema } from "./address.js"; +import { CurrencyAmount, CurrencyAmount$inboundSchema } from "../common/amount.js"; + +export type ShippingTotals = { + shippingAmount: CurrencyAmount; + discountAmount: CurrencyAmount; + vatAmount: CurrencyAmount; + totalAmount: CurrencyAmount; +}; + +export type Order = { + resource: string; + id: number; + customerId: number; + cartId: string | null; + channelId: number; + languageId: number | null; + number: string; + invoiceId: number | null; + status: string; + companyName: string; + companyVat: string; + billingAddress: Address; + shippingAddress: Address; + subtotalAmount: CurrencyAmount; + shipping: ShippingTotals; + discountAmount: CurrencyAmount; + vatAmount: CurrencyAmount; + totalAmount: CurrencyAmount; + promotionCodes: Array; + shippingMethodId: number | null; + isTaxExempt: boolean; + notes: string; + updatedAt: string; + createdAt: string; + links?: HalLinks; +}; + +/** @internal */ +export const ShippingTotals$inboundSchema: z.ZodType = z.object({ + shippingAmount: CurrencyAmount$inboundSchema, + discountAmount: CurrencyAmount$inboundSchema, + vatAmount: CurrencyAmount$inboundSchema, + totalAmount: CurrencyAmount$inboundSchema, +}); + +/** @internal */ +export const Order$inboundSchema: z.ZodType = z.object({ + resource: z.string(), + id: z.number(), + customerId: z.number(), + cartId: z.string().nullable(), + channelId: z.number(), + languageId: z.number().nullable(), + number: z.string(), + invoiceId: z.number().nullable(), + status: z.string(), + companyName: z.string(), + companyVat: z.string(), + billingAddress: Address$inboundSchema, + shippingAddress: Address$inboundSchema, + subtotalAmount: CurrencyAmount$inboundSchema, + shipping: ShippingTotals$inboundSchema, + discountAmount: CurrencyAmount$inboundSchema, + vatAmount: CurrencyAmount$inboundSchema, + totalAmount: CurrencyAmount$inboundSchema, + promotionCodes: z.array(z.string()), + shippingMethodId: z.number().nullable(), + isTaxExempt: z.boolean(), + notes: z.string(), + updatedAt: z.string(), + createdAt: z.string(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => { + return remap$(v, { + "_links": "links", + }) as Order; +}); diff --git a/src/models/commerce/payment.ts b/src/models/commerce/payment.ts new file mode 100644 index 0000000..9f675ed --- /dev/null +++ b/src/models/commerce/payment.ts @@ -0,0 +1,47 @@ +/* + * Commerce Payment model. + */ + +import * as z from "zod/v4"; +import { remap as remap$ } from "../../lib/primitives.js"; +import { HalLinks, HalLinks$inboundSchema } from "../hal.js"; +import { CurrencyAmount, CurrencyAmount$inboundSchema } from "../common/amount.js"; + +export type Payment = { + resource: string; + id: number; + customerId: number; + paymentmethodId: number; + status: string; + type: string; + amount: CurrencyAmount; + description: string; + invoiceId: number | null; + expiresAt: string | null; + completedAt: string | null; + updatedAt: string; + createdAt: string; + links?: HalLinks; +}; + +/** @internal */ +export const Payment$inboundSchema: z.ZodType = z.object({ + resource: z.string(), + id: z.number(), + customerId: z.number(), + paymentmethodId: z.number(), + status: z.string(), + type: z.string(), + amount: CurrencyAmount$inboundSchema, + description: z.string(), + invoiceId: z.nullable(z.number()), + expiresAt: z.string().nullable(), + completedAt: z.string().nullable(), + updatedAt: z.string(), + createdAt: z.string(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => { + return remap$(v, { + "_links": "links", + }) as Payment; +}); diff --git a/src/models/commerce/product-group.ts b/src/models/commerce/product-group.ts index 30bcf5f..043ccd1 100644 --- a/src/models/commerce/product-group.ts +++ b/src/models/commerce/product-group.ts @@ -1,5 +1,5 @@ /* - * Product group model. + * Commerce Product Group model. */ import * as z from "zod/v4"; @@ -7,17 +7,36 @@ import { remap as remap$ } from "../../lib/primitives.js"; import { HalLinks, HalLinks$inboundSchema } from "../hal.js"; export type ProductGroup = { - resource?: string; - id?: number; - name?: string; + resource: string; + id: number; + name: string; + slug: string; + description: string | null; + parentId: number | null; + metaTitle: string | null; + metaDescription: string | null; + metaKeywords: string | null; + createdAt: string; + updatedAt: string; links?: HalLinks; - [key: string]: unknown; }; /** @internal */ export const ProductGroup$inboundSchema: z.ZodType = z.object({ - resource: z.string().optional(), - id: z.number().optional(), - name: z.string().optional(), + resource: z.string(), + id: z.number(), + name: z.string(), + slug: z.string(), + description: z.nullable(z.string()), + parentId: z.nullable(z.number()), + metaTitle: z.nullable(z.string()), + metaDescription: z.nullable(z.string()), + metaKeywords: z.nullable(z.string()), + createdAt: z.string(), + updatedAt: z.string(), _links: HalLinks$inboundSchema.optional(), -}).loose().transform((v) => remap$(v, { _links: "links" }) as ProductGroup); +}).transform((v) => { + return remap$(v, { + "_links": "links", + }) as ProductGroup; +}); diff --git a/src/models/commerce/product-offer.ts b/src/models/commerce/product-offer.ts index 94dd60a..374ab6c 100644 --- a/src/models/commerce/product-offer.ts +++ b/src/models/commerce/product-offer.ts @@ -1,5 +1,5 @@ /* - * Product offer model. + * Commerce Product Offer model. */ import * as z from "zod/v4"; @@ -12,7 +12,7 @@ export type ProductOffer = { id: number; productId: number; type: string; - intervalId?: number | null; + intervalId: number | null; quantity: number; prices: PriceMap; links?: HalLinks; @@ -24,8 +24,12 @@ export const ProductOffer$inboundSchema: z.ZodType = z.object({ id: z.number(), productId: z.number(), type: z.string(), - intervalId: z.number().nullable().optional(), + intervalId: z.nullable(z.number()), quantity: z.number(), prices: PriceMap$inboundSchema, _links: HalLinks$inboundSchema.optional(), -}).transform((v) => remap$(v, { _links: "links" }) as ProductOffer); +}).transform((v) => { + return remap$(v, { + "_links": "links", + }) as ProductOffer; +}); diff --git a/src/models/commerce/product.ts b/src/models/commerce/product.ts index b40e1d3..0117409 100644 --- a/src/models/commerce/product.ts +++ b/src/models/commerce/product.ts @@ -1,153 +1,139 @@ /* - * Commerce product models. + * Commerce Product model. */ import * as z from "zod/v4"; import { remap as remap$ } from "../../lib/primitives.js"; import { HalLinks, HalLinks$inboundSchema } from "../hal.js"; -import { Paginated, buildPaginated } from "../pagination.js"; -import { Category, Category$inboundSchema } from "./category.js"; -import { ProductGroup, ProductGroup$inboundSchema } from "./product-group.js"; -import { ProductOffer, ProductOffer$inboundSchema } from "./product-offer.js"; -import { Route, Route$inboundSchema } from "./route.js"; -export type ReviewSummary = { - total: number; - rating: number | null; - breakdown: unknown[]; +export type ProductRoute = { + resource: string; + name: string; + locale: string; + parameters: Record; }; -export type MeasurementValue = { +export type ProductMeasurement = { value: number; unit: string; }; -export type Measurements = { - height?: MeasurementValue; - width?: MeasurementValue; - depth?: MeasurementValue; - weight?: MeasurementValue; +export type ProductMeasurements = { + height?: ProductMeasurement; + width?: ProductMeasurement; + depth?: ProductMeasurement; + weight?: ProductMeasurement; +}; + +export type ProductReviewBreakdown = { + rating: number; + count: number; +}; + +export type ProductReviews = { + total: number; + rating: number | null; + breakdown: Array; }; export type Product = { resource: string; id: number; sku: string; - ean?: string | null; - mpn?: string | null; - asin?: string | null; + ean: string | null; + mpn: string | null; + asin: string | null; title: string; - shortTitle?: string | null; - coverImage?: string | null; - additionalImages?: string[]; - shortDescription?: string | null; - description?: string | null; - bulletpoints?: string[]; - boxContent?: string | null; - type?: string; - condition?: string; - categoryId?: number | null; - stock?: number | null; - isBackorderAllowed?: boolean; - routes?: Record; - offers?: ProductOffer[]; - reviews?: ReviewSummary; - searches?: string[]; - customFields?: unknown[]; - publishedAt?: string | null; - videos?: unknown[]; - updatedAt?: string; - createdAt?: string; - measurements?: Measurements; - category?: Category; - productGroups?: ProductGroup[]; + shortTitle: string | null; + coverImage: string | null; + additionalImages: Array; + shortDescription: string | null; + description: string | null; + bulletpoints: Array; + boxContent: string | null; + type: string; + condition: string; + categoryId: number; + stock: number; + isBackorderAllowed: boolean; + routes: Record; + measurements?: ProductMeasurements; + reviews?: ProductReviews; + searches: Array; + customFields: Array; + publishedAt: string | null; + updatedAt: string; + createdAt: string; links?: HalLinks; }; -export type ProductsListResponse = Paginated; +/** @internal */ +export const ProductRoute$inboundSchema: z.ZodType = z.object({ + resource: z.string(), + name: z.string(), + locale: z.string(), + parameters: z.record(z.string(), z.any()), +}); -const MeasurementValue$inboundSchema = z.object({ +/** @internal */ +export const ProductMeasurement$inboundSchema: z.ZodType = z.object({ value: z.number(), unit: z.string(), }); -const Measurements$inboundSchema = z.object({ - height: MeasurementValue$inboundSchema.optional(), - width: MeasurementValue$inboundSchema.optional(), - depth: MeasurementValue$inboundSchema.optional(), - weight: MeasurementValue$inboundSchema.optional(), +/** @internal */ +export const ProductMeasurements$inboundSchema: z.ZodType = z.object({ + height: ProductMeasurement$inboundSchema.optional(), + width: ProductMeasurement$inboundSchema.optional(), + depth: ProductMeasurement$inboundSchema.optional(), + weight: ProductMeasurement$inboundSchema.optional(), +}) as unknown as z.ZodType; + +/** @internal */ +export const ProductReviewBreakdown$inboundSchema: z.ZodType = z.object({ + rating: z.number(), + count: z.number(), }); -const ReviewSummary$inboundSchema = z.object({ +/** @internal */ +export const ProductReviews$inboundSchema: z.ZodType = z.object({ total: z.number(), - rating: z.number().nullable(), - breakdown: z.array(z.any()), + rating: z.nullable(z.number()), + breakdown: z.array(ProductReviewBreakdown$inboundSchema), }); -const ProductEmbedded$inboundSchema = z.object({ - category: Category$inboundSchema.optional(), - product_groups: z.array(ProductGroup$inboundSchema).optional(), -}).loose(); - /** @internal */ export const Product$inboundSchema: z.ZodType = z.object({ resource: z.string(), id: z.number(), sku: z.string(), - ean: z.string().nullable().optional(), - mpn: z.string().nullable().optional(), - asin: z.string().nullable().optional(), + ean: z.nullable(z.string()), + mpn: z.nullable(z.string()), + asin: z.nullable(z.string()), title: z.string(), - shortTitle: z.string().nullable().optional(), - coverImage: z.string().nullable().optional(), - additionalImages: z.array(z.string()).optional(), - shortDescription: z.string().nullable().optional(), - description: z.string().nullable().optional(), - bulletpoints: z.array(z.string()).optional(), - boxContent: z.string().nullable().optional(), - type: z.string().optional(), - condition: z.string().optional(), - categoryId: z.number().nullable().optional(), - stock: z.number().nullable().optional(), - isBackorderAllowed: z.boolean().optional(), - routes: z.record(z.string(), Route$inboundSchema).optional(), - offers: z.array(ProductOffer$inboundSchema).optional(), - reviews: ReviewSummary$inboundSchema.optional(), - searches: z.array(z.string()).optional(), - customFields: z.array(z.any()).optional(), - publishedAt: z.string().nullable().optional(), - videos: z.array(z.any()).optional(), - updatedAt: z.string().optional(), - createdAt: z.string().optional(), - measurements: Measurements$inboundSchema.optional(), + shortTitle: z.nullable(z.string()), + coverImage: z.nullable(z.string()), + additionalImages: z.array(z.string()), + shortDescription: z.nullable(z.string()), + description: z.nullable(z.string()), + bulletpoints: z.array(z.string()), + boxContent: z.nullable(z.string()), + type: z.string(), + condition: z.string(), + categoryId: z.number(), + stock: z.number(), + isBackorderAllowed: z.boolean(), + routes: z.record(z.string(), ProductRoute$inboundSchema), + measurements: ProductMeasurements$inboundSchema.optional(), + reviews: ProductReviews$inboundSchema.optional(), + searches: z.array(z.string()), + customFields: z.array(z.any()), + publishedAt: z.nullable(z.string()), + updatedAt: z.string(), + createdAt: z.string(), _links: HalLinks$inboundSchema.optional(), - _embedded: ProductEmbedded$inboundSchema.optional(), }).transform((v) => { - const { _embedded } = v; - const category = _embedded?.category; - const productGroups = _embedded?.product_groups; - - const remapped = remap$(v, { _links: "links", _embedded: null }); - - if (category !== undefined) { - (remapped as Product).category = category; - } - if (productGroups !== undefined) { - (remapped as Product).productGroups = productGroups; - } - - return remapped as Product; + return remap$(v, { + "_links": "links", + }) as Product; }); - -/** @internal */ -export const ProductsListResponse$inboundSchema: z.ZodType< - ProductsListResponse -> = z.object({ - _embedded: z.object({ - products: z.array(Product$inboundSchema), - }), - count: z.number(), - _links: HalLinks$inboundSchema.optional(), -}).transform((v) => - buildPaginated(v._embedded.products, v.count, v._links) -); diff --git a/src/models/commerce/review.ts b/src/models/commerce/review.ts new file mode 100644 index 0000000..edb1e20 --- /dev/null +++ b/src/models/commerce/review.ts @@ -0,0 +1,33 @@ +import * as z from "zod/v4"; + + +// Placeholder - waiting for actual data structure from user +export type Review = { + id?: string; + [key: string]: any; +}; + +/** @internal */ +export const Review$inboundSchema: z.ZodType = z + .object({ + id: z.string().optional(), + }) + .passthrough() as unknown as z.ZodType; + +/** @internal */ +export const Review$outboundSchema: z.ZodType = z + .object({ + id: z.string().optional(), + }) + .passthrough() as unknown as z.ZodType; + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace Review$ { + /** @deprecated use `Review$inboundSchema` instead. */ + export const inboundSchema = Review$inboundSchema; + /** @deprecated use `Review$outboundSchema` instead. */ + export const outboundSchema = Review$outboundSchema; +} diff --git a/src/models/commerce/shipping-method.ts b/src/models/commerce/shipping-method.ts new file mode 100644 index 0000000..66785dc --- /dev/null +++ b/src/models/commerce/shipping-method.ts @@ -0,0 +1,36 @@ +import * as z from "zod/v4"; + + +// Placeholder - waiting for actual data structure from user +export type ShippingMethod = { + id?: string; + name?: string; + [key: string]: any; +}; + +/** @internal */ +export const ShippingMethod$inboundSchema: z.ZodType = z + .object({ + id: z.string().optional(), + name: z.string().optional(), + }) + .passthrough() as unknown as z.ZodType; + +/** @internal */ +export const ShippingMethod$outboundSchema: z.ZodType = z + .object({ + id: z.string().optional(), + name: z.string().optional(), + }) + .passthrough() as unknown as z.ZodType; + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace ShippingMethod$ { + /** @deprecated use `ShippingMethod$inboundSchema` instead. */ + export const inboundSchema = ShippingMethod$inboundSchema; + /** @deprecated use `ShippingMethod$outboundSchema` instead. */ + export const outboundSchema = ShippingMethod$outboundSchema; +} diff --git a/src/models/commerce/shipping-zone.ts b/src/models/commerce/shipping-zone.ts new file mode 100644 index 0000000..0e2f93f --- /dev/null +++ b/src/models/commerce/shipping-zone.ts @@ -0,0 +1,101 @@ +import * as z from "zod/v4"; +import { remap as remap$ } from "../../lib/primitives.js"; + +export type ShippingZoneLinks = { + self: { + href: string; + type: string; + }; +}; + +/** @internal */ +export const ShippingZoneLinks$inboundSchema: z.ZodType = z.object({ + self: z.object({ + href: z.string(), + type: z.string(), + }), +}); + +/** @internal */ +export const ShippingZoneLinks$outboundSchema: z.ZodType = z.object({ + self: z.object({ + href: z.string(), + type: z.string(), + }), +}); + + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace ShippingZoneLinks$ { + /** @deprecated use `ShippingZoneLinks$inboundSchema` instead. */ + export const inboundSchema = ShippingZoneLinks$inboundSchema; + /** @deprecated use `ShippingZoneLinks$outboundSchema` instead. */ + export const outboundSchema = ShippingZoneLinks$outboundSchema; +} + +export type ShippingZone = { + resource: string; + id: string; + name: string; + regions?: Array | null; + order?: number | null; + isActive: boolean; + isDefault: boolean; + updatedAt: string; + createdAt: string; + links: ShippingZoneLinks; +}; + +/** @internal */ +export const ShippingZone$inboundSchema: z.ZodType = z + .object({ + resource: z.string(), + id: z.string(), + name: z.string(), + regions: z.array(z.string()).optional().nullable(), + order: z.number().int().optional().nullable(), + isActive: z.boolean(), + isDefault: z.boolean(), + updatedAt: z.string(), + createdAt: z.string(), + _links: ShippingZoneLinks$inboundSchema, + }) + .transform((v) => { + return remap$(v, { + _links: "links", + }); + }) as unknown as z.ZodType; + +/** @internal */ +export const ShippingZone$outboundSchema: z.ZodType = z + .object({ + resource: z.string(), + id: z.string(), + name: z.string(), + regions: z.array(z.string()).optional().nullable(), + order: z.number().int().optional().nullable(), + isActive: z.boolean(), + isDefault: z.boolean(), + updatedAt: z.string(), + createdAt: z.string(), + links: ShippingZoneLinks$outboundSchema, + }) + .transform((v) => { + return remap$(v, { + links: "_links", + }); + }) as unknown as z.ZodType; + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace ShippingZone$ { + /** @deprecated use `ShippingZone$inboundSchema` instead. */ + export const inboundSchema = ShippingZone$inboundSchema; + /** @deprecated use `ShippingZone$outboundSchema` instead. */ + export const outboundSchema = ShippingZone$outboundSchema; +} diff --git a/src/models/commerce/subscription-interval.ts b/src/models/commerce/subscription-interval.ts new file mode 100644 index 0000000..f94ac14 --- /dev/null +++ b/src/models/commerce/subscription-interval.ts @@ -0,0 +1,40 @@ +/* + * Commerce Subscription Interval model. + */ + +import * as z from "zod/v4"; +import { remap as remap$ } from "../../lib/primitives.js"; +import { HalLinks, HalLinks$inboundSchema } from "../hal.js"; + +export type SubscriptionInterval = { + resource: string; + id: number; + name: string; + frequency: number; + intervalUnit: string; + daysOfWeek: Array; + daysOfMonth: Array; + months: Array; + updatedAt: string; + createdAt: string; + links?: HalLinks; +}; + +/** @internal */ +export const SubscriptionInterval$inboundSchema: z.ZodType = z.object({ + resource: z.string(), + id: z.number(), + name: z.string(), + frequency: z.number(), + intervalUnit: z.string(), + daysOfWeek: z.array(z.string()), + daysOfMonth: z.array(z.number()), + months: z.array(z.string()), + updatedAt: z.string(), + createdAt: z.string(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => { + return remap$(v, { + "_links": "links", + }) as SubscriptionInterval; +}); diff --git a/src/models/commerce/vat-validation.ts b/src/models/commerce/vat-validation.ts new file mode 100644 index 0000000..f2e4922 --- /dev/null +++ b/src/models/commerce/vat-validation.ts @@ -0,0 +1,30 @@ +/* + * Commerce VAT Validation model. + */ + +import * as z from "zod/v4"; +import { remap as remap$ } from "../../lib/primitives.js"; +import { HalLinks, HalLinks$inboundSchema } from "../hal.js"; + +export type VatValidation = { + resource: string; + vatNumber: string; + isValid: boolean; + updatedAt: string; + createdAt: string; + links?: HalLinks; +}; + +/** @internal */ +export const VatValidation$inboundSchema: z.ZodType = z.object({ + resource: z.string(), + vatNumber: z.string(), + isValid: z.boolean(), + updatedAt: z.string(), + createdAt: z.string(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => { + return remap$(v, { + "_links": "links", + }) as VatValidation; +}); diff --git a/src/models/common/amount.ts b/src/models/common/amount.ts index 278f96b..6e413b4 100644 --- a/src/models/common/amount.ts +++ b/src/models/common/amount.ts @@ -1,16 +1,25 @@ /* - * Currency amount model (string value + currency code). + * Commerce Amount model. */ import * as z from "zod/v4"; export type CurrencyAmount = { - value: string; + value?: string | undefined; + amount?: string | undefined; currency: string; }; /** @internal */ export const CurrencyAmount$inboundSchema: z.ZodType = z.object({ - value: z.string(), + value: z.string().optional(), + amount: z.string().optional(), + currency: z.string(), +}); + +/** @internal */ +export const CurrencyAmount$outboundSchema: z.ZodType = z.object({ + value: z.string().optional(), + amount: z.string().optional(), currency: z.string(), }); diff --git a/src/models/identity/user-mfa-method.ts b/src/models/identity/user-mfa-method.ts new file mode 100644 index 0000000..ca13726 --- /dev/null +++ b/src/models/identity/user-mfa-method.ts @@ -0,0 +1,34 @@ +/* + * User MFA Method model. + */ + +import * as z from "zod/v4"; +import { remap as remap$ } from "../../lib/primitives.js"; +import { HalLinks, HalLinks$inboundSchema } from "../hal.js"; + +export type UserMfaMethod = { + resource: "user_mfa_method"; + userId: number; + method: string; + isEnabled: boolean; + verifiedAt?: string | null; + lastUsedAt?: string | null; + lastSentAt?: string | null; + links?: HalLinks; +}; + +/** @internal */ +export const UserMfaMethod$inboundSchema: z.ZodType = z.object({ + resource: z.literal("user_mfa_method"), + userId: z.number().int(), + method: z.string(), + isEnabled: z.boolean(), + verifiedAt: z.string().nullable().optional(), + lastUsedAt: z.string().nullable().optional(), + lastSentAt: z.string().nullable().optional(), + _links: HalLinks$inboundSchema.optional(), +}).loose().transform((v) => { + return remap$(v, { + "_links": "links", + }) as UserMfaMethod; +}); diff --git a/src/models/identity/user-recovery-code.ts b/src/models/identity/user-recovery-code.ts new file mode 100644 index 0000000..828de5d --- /dev/null +++ b/src/models/identity/user-recovery-code.ts @@ -0,0 +1,34 @@ +/* + * User Recovery Code model. + */ + +import * as z from "zod/v4"; +import { remap as remap$ } from "../../lib/primitives.js"; +import { HalLinks, HalLinks$inboundSchema } from "../hal.js"; + +export type UserRecoveryCode = { + resource: "user_recovery_code"; + userId: number; + code: string; + isUsed: boolean; + usedAt?: string | null; + createdAt: string; + updatedAt: string; + links?: HalLinks; +}; + +/** @internal */ +export const UserRecoveryCode$inboundSchema: z.ZodType = z.object({ + resource: z.literal("user_recovery_code"), + userId: z.number().int(), + code: z.string(), + isUsed: z.boolean(), + usedAt: z.string().nullable().optional(), + createdAt: z.string(), + updatedAt: z.string(), + _links: HalLinks$inboundSchema.optional(), +}).loose().transform((v) => { + return remap$(v, { + "_links": "links", + }) as UserRecoveryCode; +}); diff --git a/src/models/index.ts b/src/models/index.ts index 4dc4ac3..960a9c5 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -1,6 +1,5 @@ export * from "./security.js"; export * from "./common/index.js"; export * from "./commerce/index.js"; -export * from "./identity/index.js"; export * from "./hal.js"; export * from "./pagination.js"; diff --git a/src/models/operations/admins.ts b/src/models/operations/admins.ts new file mode 100644 index 0000000..7f083a3 --- /dev/null +++ b/src/models/operations/admins.ts @@ -0,0 +1,67 @@ +/* + * Admin operations. + */ + +import * as z from "zod/v4"; +import { buildPaginated, Paginated } from "../pagination.js"; +import { Admin, Admin$inboundSchema } from "../identity/admin.js"; +import { HalLinks$inboundSchema } from "../hal.js"; + +export type ListAdminsRequest = { + /** + * Page number. + */ + page?: number | undefined; + /** + * Page limit. + */ + limit?: number | undefined; +}; + +export type ListAdminsResponse = Paginated; + +/** @internal */ +export const ListAdminsRequest$outboundSchema: z.ZodType< + ListAdminsRequest +> = z.object({ + page: z.number().optional(), + limit: z.number().optional(), +}); + +/** @internal */ +export const ListAdminsResponse$inboundSchema: z.ZodType< + ListAdminsResponse +> = z.object({ + _embedded: z.object({ + admins: z.array(Admin$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.admins, + v.count, + v._links, + ) +); + +export type GetAdminRequest = { + /** + * Admin ID. + */ + id: number; +}; + +export type GetAdminResponse = Admin; + +/** @internal */ +export const GetAdminRequest$outboundSchema: z.ZodType< + GetAdminRequest +> = z.object({ + id: z.number(), +}); + +/** @internal */ +export const GetAdminResponse$inboundSchema: z.ZodType< + GetAdminResponse +> = Admin$inboundSchema; diff --git a/src/models/operations/cms-components.ts b/src/models/operations/cms-components.ts new file mode 100644 index 0000000..a9e1f07 --- /dev/null +++ b/src/models/operations/cms-components.ts @@ -0,0 +1,104 @@ +/* + * CMS Components operations. + */ + +import * as z from "zod/v4"; +import { remap as remap$ } from "../../lib/primitives.js"; +import { buildPaginated, Paginated } from "../pagination.js"; +import { Component, Component$inboundSchema } from "../cms/component.js"; +import { HalLinks$inboundSchema } from "../hal.js"; + +export type ListComponentsRequest = { + /** + * Filter by component ID. + */ + filterId?: number | undefined; + /** + * Filter by component slug. + */ + filterSlug?: string | undefined; + /** + * Filter by component name. + */ + filterName?: string | undefined; + /** + * Include related resources. + */ + include?: string | undefined; + /** + * Sort results. + */ + sort?: string | undefined; + /** + * Page number. + */ + page?: number | undefined; + /** + * Page limit. + */ + limit?: number | undefined; +}; + +export type ListComponentsResponse = Paginated; + +/** @internal */ +export const ListComponentsRequest$outboundSchema: z.ZodType< + ListComponentsRequest +> = z.object({ + filterId: z.number().optional(), + filterSlug: z.string().optional(), + filterName: z.string().optional(), + include: z.string().optional(), + sort: z.string().optional(), + page: z.number().optional(), + limit: z.number().optional(), +}).transform((v) => { + return remap$(v, { + filterId: "filter[id]", + filterSlug: "filter[slug]", + filterName: "filter[name]", + }); +}); + +/** @internal */ +export const ListComponentsResponse$inboundSchema: z.ZodType< + ListComponentsResponse +> = z.object({ + _embedded: z.object({ + components: z.array(Component$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.components, + v.count, + v._links, + ) +); + +export type GetComponentRequest = { + /** + * Component ID. + */ + id: number; + /** + * Include related resources. + */ + include?: string | undefined; +}; + +export type GetComponentResponse = Component; + +/** @internal */ +export const GetComponentRequest$outboundSchema: z.ZodType< + GetComponentRequest +> = z.object({ + id: z.number(), + include: z.string().optional(), +}); + +/** @internal */ +export const GetComponentResponse$inboundSchema: z.ZodType< + GetComponentResponse +> = Component$inboundSchema; diff --git a/src/models/operations/cms-layouts.ts b/src/models/operations/cms-layouts.ts new file mode 100644 index 0000000..dcb0e3d --- /dev/null +++ b/src/models/operations/cms-layouts.ts @@ -0,0 +1,68 @@ +/* + * CMS Layouts operations. + */ + +import * as z from "zod/v4"; + +import { buildPaginated, Paginated } from "../pagination.js"; +import { Layout, Layout$inboundSchema } from "../cms/layout.js"; +import { HalLinks$inboundSchema } from "../hal.js"; + +export type ListLayoutsRequest = { + /** + * Page number. + */ + page?: number | undefined; + /** + * Page limit. + */ + limit?: number | undefined; +}; + +export type ListLayoutsResponse = Paginated; + +/** @internal */ +export const ListLayoutsRequest$outboundSchema: z.ZodType< + ListLayoutsRequest +> = z.object({ + page: z.number().optional(), + limit: z.number().optional(), +}); + +/** @internal */ +export const ListLayoutsResponse$inboundSchema: z.ZodType< + ListLayoutsResponse +> = z.object({ + _embedded: z.object({ + layouts: z.array(Layout$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.layouts, + v.count, + v._links, + ) +); + +export type GetLayoutRequest = { + /** + * Layout ID. + */ + id: number; +}; + +export type GetLayoutResponse = Layout; + +/** @internal */ +export const GetLayoutRequest$outboundSchema: z.ZodType< + GetLayoutRequest +> = z.object({ + id: z.number(), +}); + +/** @internal */ +export const GetLayoutResponse$inboundSchema: z.ZodType< + GetLayoutResponse +> = Layout$inboundSchema; diff --git a/src/models/operations/cms-menus.ts b/src/models/operations/cms-menus.ts new file mode 100644 index 0000000..b6a94c1 --- /dev/null +++ b/src/models/operations/cms-menus.ts @@ -0,0 +1,67 @@ +/* + * CMS Menus operations. + */ + +import * as z from "zod/v4"; +import { buildPaginated, Paginated } from "../pagination.js"; +import { Menu, Menu$inboundSchema } from "../cms/menu.js"; +import { HalLinks$inboundSchema } from "../hal.js"; + +export type ListMenusRequest = { + /** + * Page number. + */ + page?: number | undefined; + /** + * Page limit. + */ + limit?: number | undefined; +}; + +export type ListMenusResponse = Paginated; + +/** @internal */ +export const ListMenusRequest$outboundSchema: z.ZodType< + ListMenusRequest +> = z.object({ + page: z.number().optional(), + limit: z.number().optional(), +}); + +/** @internal */ +export const ListMenusResponse$inboundSchema: z.ZodType< + ListMenusResponse +> = z.object({ + _embedded: z.object({ + menus: z.array(Menu$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.menus, + v.count, + v._links, + ) +); + +export type GetMenuRequest = { + /** + * Menu ID. + */ + id: number; +}; + +export type GetMenuResponse = Menu; + +/** @internal */ +export const GetMenuRequest$outboundSchema: z.ZodType< + GetMenuRequest +> = z.object({ + id: z.number(), +}); + +/** @internal */ +export const GetMenuResponse$inboundSchema: z.ZodType< + GetMenuResponse +> = Menu$inboundSchema; diff --git a/src/models/operations/cms-pages.ts b/src/models/operations/cms-pages.ts new file mode 100644 index 0000000..73d1d8f --- /dev/null +++ b/src/models/operations/cms-pages.ts @@ -0,0 +1,137 @@ +/* + * CMS Pages operations. + */ + +import * as z from "zod/v4"; +import { remap as remap$ } from "../../lib/primitives.js"; +import { buildPaginated, Paginated } from "../pagination.js"; +import { Page, Page$inboundSchema } from "../cms/page.js"; +import { PageComponent, PageComponent$inboundSchema } from "../cms/page-component.js"; +import { HalLinks$inboundSchema } from "../hal.js"; + +export type ListPagesRequest = { + /** + * Filter by page slug. + */ + filterSlug?: string | undefined; + /** + * Filter by published status. + */ + filterPublished?: boolean | undefined; + /** + * Include related resources. + */ + include?: string | undefined; + /** + * Page number. + */ + page?: number | undefined; + /** + * Page limit. + */ + limit?: number | undefined; +}; + +export type ListPagesResponse = Paginated; + +/** @internal */ +export const ListPagesRequest$outboundSchema: z.ZodType< + ListPagesRequest +> = z.object({ + filterSlug: z.string().optional(), + filterPublished: z.boolean().optional(), + include: z.string().optional(), + page: z.number().optional(), + limit: z.number().optional(), +}).transform((v) => { + return remap$(v, { + filterSlug: "filter[slug]", + filterPublished: "filter[published]", + }); +}); + +/** @internal */ +export const ListPagesResponse$inboundSchema: z.ZodType< + ListPagesResponse +> = z.object({ + _embedded: z.object({ + pages: z.array(Page$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.pages, + v.count, + v._links, + ) +); + +export type GetPageRequest = { + /** + * Page ID. + */ + id: number; + /** + * Include related resources. + */ + include?: string | undefined; +}; + +export type GetPageResponse = Page; + +/** @internal */ +export const GetPageRequest$outboundSchema: z.ZodType< + GetPageRequest +> = z.object({ + id: z.number(), + include: z.string().optional(), +}); + +/** @internal */ +export const GetPageResponse$inboundSchema: z.ZodType< + GetPageResponse +> = Page$inboundSchema; + +export type ListPageComponentsRequest = { + /** + * Page ID. + */ + id: number; + /** + * Page number. + */ + page?: number | undefined; + /** + * Page limit. + */ + limit?: number | undefined; +}; + +export type ListPageComponentsResponse = Paginated; + +/** @internal */ +export const ListPageComponentsRequest$outboundSchema: z.ZodType< + ListPageComponentsRequest +> = z.object({ + id: z.number(), + page: z.number().optional(), + limit: z.number().optional(), +}); + +/** @internal */ +export const ListPageComponentsResponse$inboundSchema: z.ZodType< + ListPageComponentsResponse +> = z.object({ + _embedded: z.object({ + page_components: z.array(PageComponent$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.page_components, + v.count, + v._links, + ) +); diff --git a/src/models/operations/commerce-cart-items.ts b/src/models/operations/commerce-cart-items.ts index 4042f7a..68aa625 100644 --- a/src/models/operations/commerce-cart-items.ts +++ b/src/models/operations/commerce-cart-items.ts @@ -1,125 +1,141 @@ /* - * Commerce cart items operations. + * Commerce Cart Items operations. */ import * as z from "zod/v4"; -import { CartItem, CartItemsListResponse } from "../commerce/cart-item.js"; - -export type CartItemsListParams = { +import { buildPaginated, Paginated } from "../pagination.js"; +import { CartItem, CartItem$inboundSchema } from "../commerce/cart-item.js"; +import { HalLinks$inboundSchema } from "../hal.js"; + +export type ListCartItemsRequest = { + /** + * Cart ID. + */ + cartId: string; + /** + * Include related resources. + */ + include?: string | undefined; + /** + * Filter by fields. + */ + filter?: Record | undefined; + /** + * Sort by fields. + */ + sort?: string | undefined; + /** + * Page number. + */ page?: number | undefined; + /** + * Page limit. + */ limit?: number | undefined; - include?: string | string[] | undefined; - filter?: Record | string | undefined; - sort?: string | string[] | undefined; }; -export type CartItemGetParams = { - include?: string | string[] | undefined; -}; +export type ListCartItemsResponse = Paginated; -export type ListCartItemsRequest = CartItemsListParams & { - cartId: string; -}; -export type ListCartItemsResponse = CartItemsListResponse; +/** @internal */ +export const ListCartItemsRequest$outboundSchema: z.ZodType< + ListCartItemsRequest +> = z.object({ + cartId: z.string(), + include: z.string().optional(), + filter: z.record(z.string(), z.any()).optional(), + sort: z.string().optional(), + page: z.number().optional(), + limit: z.number().optional(), +}); -export type GetCartItemRequest = CartItemGetParams & { +/** @internal */ +export const ListCartItemsResponse$inboundSchema: z.ZodType< + ListCartItemsResponse +> = z.object({ + _embedded: z.object({ + cart_items: z.array(CartItem$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.cart_items, + v.count, + v._links, + ) +); + +export type GetCartItemRequest = { + /** + * Cart ID. + */ cartId: string; + /** + * Cart Item ID. + */ itemId: string; + /** + * Include related resources. + */ + include?: string | undefined; }; + export type GetCartItemResponse = CartItem; -export type CartItemCreateInput = { - productId: number; - productOfferId?: number | undefined; - quantity?: number | undefined; -}; -export type CartItemUpdateInput = { - quantity?: number | undefined; -}; +/** @internal */ +export const GetCartItemRequest$outboundSchema: z.ZodType< + GetCartItemRequest +> = z.object({ + cartId: z.string(), + itemId: z.string(), + include: z.string().optional(), +}); + +/** @internal */ +export const GetCartItemResponse$inboundSchema: z.ZodType< + GetCartItemResponse +> = CartItem$inboundSchema; export type CreateCartItemRequest = { cartId: string; - body: CartItemCreateInput; + data: Record; }; export type CreateCartItemResponse = CartItem; +/** @internal */ +export const CreateCartItemRequest$outboundSchema: z.ZodType = z.object({ + cartId: z.string(), + data: z.record(z.string(), z.any()), +}); +/** @internal */ +export const CreateCartItemResponse$inboundSchema: z.ZodType = CartItem$inboundSchema; + export type UpdateCartItemRequest = { cartId: string; itemId: string; - body: CartItemUpdateInput; + data: Record; }; export type UpdateCartItemResponse = CartItem; -export type DeleteCartItemRequest = { - cartId: string; - itemId: string; -}; -export type DeleteCartItemResponse = void; - -/** @internal */ -export const CartItemsListParams$outboundSchema: z.ZodType = - z.object({ - page: z.number().int().optional(), - limit: z.number().int().optional(), - include: z.union([z.string(), z.array(z.string())]).optional(), - filter: z.union([z.string(), z.record(z.string(), z.any())]).optional(), - sort: z.union([z.string(), z.array(z.string())]).optional(), - }).loose(); - -/** @internal */ -export const CartItemGetParams$outboundSchema: z.ZodType = z - .object({ - include: z.union([z.string(), z.array(z.string())]).optional(), - }) - .loose(); - /** @internal */ -export const ListCartItemsRequest$outboundSchema: z.ZodType< - ListCartItemsRequest -> = z.object({ +export const UpdateCartItemRequest$outboundSchema: z.ZodType = z.object({ cartId: z.string(), - page: z.number().int().optional(), - limit: z.number().int().optional(), - include: z.union([z.string(), z.array(z.string())]).optional(), - filter: z.union([z.string(), z.record(z.string(), z.any())]).optional(), - sort: z.union([z.string(), z.array(z.string())]).optional(), -}).loose(); - + itemId: z.string(), + data: z.record(z.string(), z.any()), +}); /** @internal */ -export const GetCartItemRequest$outboundSchema: z.ZodType = - z.object({ - cartId: z.string(), - itemId: z.string(), - include: z.union([z.string(), z.array(z.string())]).optional(), - }).loose(); +export const UpdateCartItemResponse$inboundSchema: z.ZodType = CartItem$inboundSchema; -/** @internal */ -export const CreateCartItemRequest$outboundSchema: z.ZodType< - CreateCartItemRequest -> = z.object({ - cartId: z.string(), - body: z.object({ - productId: z.number(), - productOfferId: z.number().optional(), - quantity: z.number().optional(), - }).loose(), -}); +export type DeleteCartItemRequest = { + cartId: string; + itemId: string; +}; +export type DeleteCartItemResponse = boolean; /** @internal */ -export const UpdateCartItemRequest$outboundSchema: z.ZodType< - UpdateCartItemRequest -> = z.object({ +export const DeleteCartItemRequest$outboundSchema: z.ZodType = z.object({ cartId: z.string(), itemId: z.string(), - body: z.object({ - quantity: z.number().optional(), - }).loose(), }); - /** @internal */ -export const DeleteCartItemRequest$outboundSchema: z.ZodType< - DeleteCartItemRequest -> = z.object({ - cartId: z.string(), - itemId: z.string(), -}); +export const DeleteCartItemResponse$inboundSchema: z.ZodType = z.boolean(); diff --git a/src/models/operations/commerce-carts.ts b/src/models/operations/commerce-carts.ts index b745535..ab769c4 100644 --- a/src/models/operations/commerce-carts.ts +++ b/src/models/operations/commerce-carts.ts @@ -1,158 +1,109 @@ /* - * Commerce carts operations. + * Commerce Carts operations. */ import * as z from "zod/v4"; -import { Cart, CartType, CartsListResponse } from "../commerce/cart.js"; -import { Address, Address$inboundSchema } from "../commerce/address.js"; - -export type CartsListParams = { +import { buildPaginated, Paginated } from "../pagination.js"; +import { Cart, Cart$inboundSchema } from "../commerce/cart.js"; +import { HalLinks$inboundSchema } from "../hal.js"; + +export type ListCartsRequest = { + /** + * Include related resources. + */ + include?: string | undefined; + /** + * Filter by fields. + */ + filter?: Record | undefined; + /** + * Sort by fields. + */ + sort?: string | undefined; + /** + * Page number. + */ page?: number | undefined; + /** + * Page limit. + */ limit?: number | undefined; - include?: string | string[] | undefined; - filter?: Record | string | undefined; - sort?: string | string[] | undefined; }; -export type CartGetParams = { - include?: string | string[] | undefined; -}; +export type ListCartsResponse = Paginated; -export type ListCartsRequest = CartsListParams; -export type ListCartsResponse = CartsListResponse; +/** @internal */ +export const ListCartsRequest$outboundSchema: z.ZodType< + ListCartsRequest +> = z.object({ + include: z.string().optional(), + filter: z.record(z.string(), z.any()).optional(), + sort: z.string().optional(), + page: z.number().optional(), + limit: z.number().optional(), +}); -export type GetCartRequest = CartGetParams & { +/** @internal */ +export const ListCartsResponse$inboundSchema: z.ZodType< + ListCartsResponse +> = z.object({ + _embedded: z.object({ + carts: z.array(Cart$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.carts, + v.count, + v._links, + ) +); + +export type GetCartRequest = { + /** + * Cart ID. + */ id: string; + /** + * Include related resources. + */ + include?: string | undefined; }; export type GetCartResponse = Cart; -export type CartItemInput = { - id?: string | undefined; - productId: number; - productOfferId?: number | undefined; - quantity?: number | undefined; -}; - -export type CartCreateInput = { - visitorId?: number | null | undefined; - customerId?: number | null | undefined; - userId?: number | null | undefined; - type?: CartType | undefined; - email?: string | null | undefined; - companyName?: string | null | undefined; - companyVat?: string | null | undefined; - taxExempt?: boolean | undefined; - country: string; - currency?: string | null | undefined; - billingAddress?: Address | null | undefined; - shippingAddress?: Address | null | undefined; - items?: CartItemInput[] | undefined; - shippingMethodId?: number | null | undefined; - promotionCodes?: string[] | null | undefined; -}; +/** @internal */ +export const GetCartRequest$outboundSchema: z.ZodType< + GetCartRequest +> = z.object({ + id: z.string(), + include: z.string().optional(), +}); -export type CartUpdateInput = { - visitorId?: number | null | undefined; - customerId?: number | null | undefined; - userId?: number | null | undefined; - email?: string | null | undefined; - companyName?: string | null | undefined; - companyVat?: string | null | undefined; - taxExempt?: boolean | undefined; - country?: string | undefined; - currency?: string | undefined; - billingAddress?: Address | null | undefined; - shippingAddress?: Address | null | undefined; - items?: CartItemInput[] | undefined; - shippingMethodId?: number | null | undefined; - promotionCodes?: string[] | null | undefined; -}; +/** @internal */ +export const GetCartResponse$inboundSchema: z.ZodType< + GetCartResponse +> = Cart$inboundSchema; -export type CreateCartRequest = CartCreateInput; +export type CreateCartRequest = Record; export type CreateCartResponse = Cart; +/** @internal */ +export const CreateCartRequest$outboundSchema: z.ZodType = z.record(z.string(), z.any()); +/** @internal */ +export const CreateCartResponse$inboundSchema: z.ZodType = Cart$inboundSchema; + export type UpdateCartRequest = { id: string; - body: CartUpdateInput; + data: Record; }; - export type UpdateCartResponse = Cart; /** @internal */ -export const CartsListParams$outboundSchema: z.ZodType = z - .object({ - page: z.number().int().optional(), - limit: z.number().int().optional(), - include: z.union([z.string(), z.array(z.string())]).optional(), - filter: z.union([z.string(), z.record(z.string(), z.any())]).optional(), - sort: z.union([z.string(), z.array(z.string())]).optional(), - }) - .loose(); - -/** @internal */ -export const CartGetParams$outboundSchema: z.ZodType = z.object({ - include: z.union([z.string(), z.array(z.string())]).optional(), -}).loose(); - -/** @internal */ -export const GetCartRequest$outboundSchema: z.ZodType = z.object({ +export const UpdateCartRequest$outboundSchema: z.ZodType = z.object({ id: z.string(), - include: z.union([z.string(), z.array(z.string())]).optional(), -}).loose(); - -/** @internal */ -const CartItemInput$outboundSchema: z.ZodType = z.object({ - id: z.string().optional(), - productId: z.number(), - productOfferId: z.number().optional(), - quantity: z.number().optional(), -}).loose(); - -/** @internal */ -const CartType$outboundSchema: z.ZodType = z.string().transform( - (value) => value as CartType, -); - -export const CreateCartRequest$outboundSchema: z.ZodType = z - .object({ - visitorId: z.number().nullable().optional(), - customerId: z.number().nullable().optional(), - userId: z.number().nullable().optional(), - type: CartType$outboundSchema.optional(), - email: z.string().nullable().optional(), - companyName: z.string().nullable().optional(), - companyVat: z.string().nullable().optional(), - taxExempt: z.boolean().optional(), - country: z.string(), - currency: z.string().nullable().optional(), - billingAddress: Address$inboundSchema.nullable().optional(), - shippingAddress: Address$inboundSchema.nullable().optional(), - items: z.array(CartItemInput$outboundSchema).optional(), - shippingMethodId: z.number().nullable().optional(), - promotionCodes: z.array(z.string()).nullable().optional(), - }) - .loose() - .transform((v) => v as CreateCartRequest); - + data: z.record(z.string(), z.any()), +}); /** @internal */ -export const UpdateCartRequest$outboundSchema: z.ZodType = z - .object({ - id: z.string(), - body: z.object({ - visitorId: z.number().nullable().optional(), - customerId: z.number().nullable().optional(), - userId: z.number().nullable().optional(), - email: z.string().nullable().optional(), - companyName: z.string().nullable().optional(), - companyVat: z.string().nullable().optional(), - taxExempt: z.boolean().optional(), - country: z.string().optional(), - currency: z.string().optional(), - billingAddress: Address$inboundSchema.nullable().optional(), - shippingAddress: Address$inboundSchema.nullable().optional(), - items: z.array(CartItemInput$outboundSchema).optional(), - shippingMethodId: z.number().nullable().optional(), - promotionCodes: z.array(z.string()).nullable().optional(), - }).loose(), - }).transform((v) => v as UpdateCartRequest); +export const UpdateCartResponse$inboundSchema: z.ZodType = Cart$inboundSchema; diff --git a/src/models/operations/commerce-categories.ts b/src/models/operations/commerce-categories.ts index b6ca4c7..85b8617 100644 --- a/src/models/operations/commerce-categories.ts +++ b/src/models/operations/commerce-categories.ts @@ -1,52 +1,87 @@ /* - * Commerce categories operations. + * Commerce Categories operations. */ import * as z from "zod/v4"; -import { Category, CategoriesListResponse } from "../commerce/category.js"; +import { buildPaginated, Paginated } from "../pagination.js"; +import { Category, Category$inboundSchema } from "../commerce/category.js"; +import { HalLinks$inboundSchema } from "../hal.js"; -export type CategoriesListParams = { +export type ListCategoriesRequest = { + /** + * Include related resources. + */ + include?: string | undefined; + /** + * Filter by fields. + */ + filter?: Record | undefined; + /** + * Sort by fields. + */ + sort?: string | undefined; + /** + * Page number. + */ page?: number | undefined; + /** + * Page limit. + */ limit?: number | undefined; - include?: string | string[] | undefined; - filter?: Record | string | undefined; - sort?: string | string[] | undefined; }; -export type CategoryGetParams = { - include?: string | string[] | undefined; -}; +export type ListCategoriesResponse = Paginated; + +/** @internal */ +export const ListCategoriesRequest$outboundSchema: z.ZodType< + ListCategoriesRequest +> = z.object({ + include: z.string().optional(), + filter: z.record(z.string(), z.any()).optional(), + sort: z.string().optional(), + page: z.number().optional(), + limit: z.number().optional(), +}); -export type ListCategoriesRequest = CategoriesListParams; -export type ListCategoriesResponse = CategoriesListResponse; +/** @internal */ +export const ListCategoriesResponse$inboundSchema: z.ZodType< + ListCategoriesResponse +> = z.object({ + _embedded: z.object({ + categories: z.array(Category$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.categories, + v.count, + v._links, + ) +); -export type GetCategoryRequest = CategoryGetParams & { - id: number | string; +export type GetCategoryRequest = { + /** + * Category ID. + */ + id: number; + /** + * Include related resources. + */ + include?: string | undefined; }; export type GetCategoryResponse = Category; /** @internal */ -export const CategoriesListParams$outboundSchema: z.ZodType< - CategoriesListParams +export const GetCategoryRequest$outboundSchema: z.ZodType< + GetCategoryRequest > = z.object({ - page: z.number().int().optional(), - limit: z.number().int().optional(), - include: z.union([z.string(), z.array(z.string())]).optional(), - filter: z.union([z.string(), z.record(z.string(), z.any())]).optional(), - sort: z.union([z.string(), z.array(z.string())]).optional(), -}).loose(); - -/** @internal */ -export const CategoryGetParams$outboundSchema: z.ZodType = z - .object({ - include: z.union([z.string(), z.array(z.string())]).optional(), - }) - .loose(); + id: z.number(), + include: z.string().optional(), +}); /** @internal */ -export const GetCategoryRequest$outboundSchema: z.ZodType = - z.object({ - id: z.union([z.string(), z.number()]), - include: z.union([z.string(), z.array(z.string())]).optional(), - }).loose(); +export const GetCategoryResponse$inboundSchema: z.ZodType< + GetCategoryResponse +> = Category$inboundSchema; diff --git a/src/models/operations/commerce-currencies.ts b/src/models/operations/commerce-currencies.ts new file mode 100644 index 0000000..12f0651 --- /dev/null +++ b/src/models/operations/commerce-currencies.ts @@ -0,0 +1,87 @@ +/* + * Commerce Currencies operations. + */ + +import * as z from "zod/v4"; +import { buildPaginated, Paginated } from "../pagination.js"; +import { Currency, Currency$inboundSchema } from "../commerce/currency.js"; +import { HalLinks$inboundSchema } from "../hal.js"; + +export type ListCurrenciesRequest = { + /** + * Include related resources. + */ + include?: string | undefined; + /** + * Filter by fields. + */ + filter?: Record | undefined; + /** + * Sort by fields. + */ + sort?: string | undefined; + /** + * Page number. + */ + page?: number | undefined; + /** + * Page limit. + */ + limit?: number | undefined; +}; + +export type ListCurrenciesResponse = Paginated; + +/** @internal */ +export const ListCurrenciesRequest$outboundSchema: z.ZodType< + ListCurrenciesRequest +> = z.object({ + include: z.string().optional(), + filter: z.record(z.string(), z.any()).optional(), + sort: z.string().optional(), + page: z.number().optional(), + limit: z.number().optional(), +}); + +/** @internal */ +export const ListCurrenciesResponse$inboundSchema: z.ZodType< + ListCurrenciesResponse +> = z.object({ + _embedded: z.object({ + currencies: z.array(Currency$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.currencies, + v.count, + v._links, + ) +); + +export type GetCurrencyRequest = { + /** + * Currency Code. + */ + code: string; + /** + * Include related resources. + */ + include?: string | undefined; +}; + +export type GetCurrencyResponse = Currency; + +/** @internal */ +export const GetCurrencyRequest$outboundSchema: z.ZodType< + GetCurrencyRequest +> = z.object({ + code: z.string(), + include: z.string().optional(), +}); + +/** @internal */ +export const GetCurrencyResponse$inboundSchema: z.ZodType< + GetCurrencyResponse +> = Currency$inboundSchema; diff --git a/src/models/operations/commerce-invoices.ts b/src/models/operations/commerce-invoices.ts new file mode 100644 index 0000000..315c667 --- /dev/null +++ b/src/models/operations/commerce-invoices.ts @@ -0,0 +1,87 @@ +/* + * Commerce Invoices operations. + */ + +import * as z from "zod/v4"; +import { buildPaginated, Paginated } from "../pagination.js"; +import { Invoice, Invoice$inboundSchema } from "../commerce/invoice.js"; +import { HalLinks$inboundSchema } from "../hal.js"; + +export type ListInvoicesRequest = { + /** + * Include related resources. + */ + include?: string | undefined; + /** + * Filter by fields. + */ + filter?: Record | undefined; + /** + * Sort by fields. + */ + sort?: string | undefined; + /** + * Page number. + */ + page?: number | undefined; + /** + * Page limit. + */ + limit?: number | undefined; +}; + +export type ListInvoicesResponse = Paginated; + +/** @internal */ +export const ListInvoicesRequest$outboundSchema: z.ZodType< + ListInvoicesRequest +> = z.object({ + include: z.string().optional(), + filter: z.record(z.string(), z.any()).optional(), + sort: z.string().optional(), + page: z.number().optional(), + limit: z.number().optional(), +}); + +/** @internal */ +export const ListInvoicesResponse$inboundSchema: z.ZodType< + ListInvoicesResponse +> = z.object({ + _embedded: z.object({ + invoices: z.array(Invoice$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.invoices, + v.count, + v._links, + ) +); + +export type GetInvoiceRequest = { + /** + * Invoice ID. + */ + id: number; + /** + * Include related resources. + */ + include?: string | undefined; +}; + +export type GetInvoiceResponse = Invoice; + +/** @internal */ +export const GetInvoiceRequest$outboundSchema: z.ZodType< + GetInvoiceRequest +> = z.object({ + id: z.number(), + include: z.string().optional(), +}); + +/** @internal */ +export const GetInvoiceResponse$inboundSchema: z.ZodType< + GetInvoiceResponse +> = Invoice$inboundSchema; diff --git a/src/models/operations/commerce-orders.ts b/src/models/operations/commerce-orders.ts new file mode 100644 index 0000000..4886fb7 --- /dev/null +++ b/src/models/operations/commerce-orders.ts @@ -0,0 +1,109 @@ +/* + * Commerce Orders operations. + */ + +import * as z from "zod/v4"; +import { buildPaginated, Paginated } from "../pagination.js"; +import { Order, Order$inboundSchema } from "../commerce/order.js"; +import { HalLinks$inboundSchema } from "../hal.js"; + +export type ListOrdersRequest = { + /** + * Include related resources. + */ + include?: string | undefined; + /** + * Filter by fields. + */ + filter?: Record | undefined; + /** + * Sort by fields. + */ + sort?: string | undefined; + /** + * Page number. + */ + page?: number | undefined; + /** + * Page limit. + */ + limit?: number | undefined; +}; + +export type ListOrdersResponse = Paginated; + +/** @internal */ +export const ListOrdersRequest$outboundSchema: z.ZodType< + ListOrdersRequest +> = z.object({ + include: z.string().optional(), + filter: z.record(z.string(), z.any()).optional(), + sort: z.string().optional(), + page: z.number().optional(), + limit: z.number().optional(), +}); + +/** @internal */ +export const ListOrdersResponse$inboundSchema: z.ZodType< + ListOrdersResponse +> = z.object({ + _embedded: z.object({ + orders: z.array(Order$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.orders, + v.count, + v._links, + ) +); + +export type GetOrderRequest = { + /** + * Order ID. + */ + id: string; + /** + * Include related resources. + */ + include?: string | undefined; +}; + +export type GetOrderResponse = Order; + +/** @internal */ +export const GetOrderRequest$outboundSchema: z.ZodType< + GetOrderRequest +> = z.object({ + id: z.string(), + include: z.string().optional(), +}); + +/** @internal */ +export const GetOrderResponse$inboundSchema: z.ZodType< + GetOrderResponse +> = Order$inboundSchema; + +export type CreateOrderRequest = Record; +export type CreateOrderResponse = Order; + +/** @internal */ +export const CreateOrderRequest$outboundSchema: z.ZodType = z.record(z.string(), z.any()); +/** @internal */ +export const CreateOrderResponse$inboundSchema: z.ZodType = Order$inboundSchema; + +export type UpdateOrderRequest = { + id: string; + data: Record; +}; +export type UpdateOrderResponse = Order; + +/** @internal */ +export const UpdateOrderRequest$outboundSchema: z.ZodType = z.object({ + id: z.string(), + data: z.record(z.string(), z.any()), +}); +/** @internal */ +export const UpdateOrderResponse$inboundSchema: z.ZodType = Order$inboundSchema; diff --git a/src/models/operations/commerce-payments.ts b/src/models/operations/commerce-payments.ts new file mode 100644 index 0000000..009e9ab --- /dev/null +++ b/src/models/operations/commerce-payments.ts @@ -0,0 +1,136 @@ +/* + * Commerce Payments operations. + */ + +import * as z from "zod/v4"; +import { buildPaginated, Paginated } from "../pagination.js"; +import { Payment, Payment$inboundSchema } from "../commerce/payment.js"; +import { HalLinks$inboundSchema } from "../hal.js"; + +export type ListOrderPaymentsRequest = { + /** + * Order ID. + */ + orderId: string; + /** + * Sort by fields. + */ + sort?: string | undefined; + /** + * Page number. + */ + page?: number | undefined; + /** + * Page limit. + */ + limit?: number | undefined; +}; + +export type ListOrderPaymentsResponse = Paginated; + +/** @internal */ +export const ListOrderPaymentsRequest$outboundSchema: z.ZodType< + ListOrderPaymentsRequest +> = z.object({ + orderId: z.string(), + sort: z.string().optional(), + page: z.number().optional(), + limit: z.number().optional(), +}); + +/** @internal */ +export const ListOrderPaymentsResponse$inboundSchema: z.ZodType< + ListOrderPaymentsResponse +> = z.object({ + _embedded: z.object({ + payments: z.array(Payment$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.payments, + v.count, + v._links, + ) +); + +export type ListPaymentsRequest = { + /** + * Include related resources. + */ + include?: string | undefined; + /** + * Filter by fields. + */ + filter?: Record | undefined; + /** + * Sort by fields. + */ + sort?: string | undefined; + /** + * Page number. + */ + page?: number | undefined; + /** + * Page limit. + */ + limit?: number | undefined; +}; + +export type ListPaymentsResponse = Paginated; + +/** @internal */ +export const ListPaymentsRequest$outboundSchema: z.ZodType< + ListPaymentsRequest +> = z.object({ + include: z.string().optional(), + filter: z.record(z.string(), z.any()).optional(), + sort: z.string().optional(), + page: z.number().optional(), + limit: z.number().optional(), +}); + +/** @internal */ +export const ListPaymentsResponse$inboundSchema: z.ZodType< + ListPaymentsResponse +> = z.object({ + _embedded: z.object({ + payments: z.array(Payment$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.payments, + v.count, + v._links, + ) +); + + +export type GetPaymentRequest = { + /** + * Payment ID. + */ + id: string; + /** + * Include related resources. + */ + include?: string | undefined; +}; + +export type GetPaymentResponse = Payment; + +/** @internal */ +export const GetPaymentRequest$outboundSchema: z.ZodType< + GetPaymentRequest +> = z.object({ + id: z.string(), + include: z.string().optional(), +}); + +/** @internal */ +export const GetPaymentResponse$inboundSchema: z.ZodType< + GetPaymentResponse +> = Payment$inboundSchema; diff --git a/src/models/operations/commerce-product-groups.ts b/src/models/operations/commerce-product-groups.ts new file mode 100644 index 0000000..d2c9dde --- /dev/null +++ b/src/models/operations/commerce-product-groups.ts @@ -0,0 +1,87 @@ +/* + * Commerce Product Groups operations. + */ + +import * as z from "zod/v4"; +import { buildPaginated, Paginated } from "../pagination.js"; +import { ProductGroup, ProductGroup$inboundSchema } from "../commerce/product-group.js"; +import { HalLinks$inboundSchema } from "../hal.js"; + +export type ListProductGroupsRequest = { + /** + * Include related resources. + */ + include?: string | undefined; + /** + * Filter by fields. + */ + filter?: Record | undefined; + /** + * Sort by fields. + */ + sort?: string | undefined; + /** + * Page number. + */ + page?: number | undefined; + /** + * Page limit. + */ + limit?: number | undefined; +}; + +export type ListProductGroupsResponse = Paginated; + +/** @internal */ +export const ListProductGroupsRequest$outboundSchema: z.ZodType< + ListProductGroupsRequest +> = z.object({ + include: z.string().optional(), + filter: z.record(z.string(), z.any()).optional(), + sort: z.string().optional(), + page: z.number().optional(), + limit: z.number().optional(), +}); + +/** @internal */ +export const ListProductGroupsResponse$inboundSchema: z.ZodType< + ListProductGroupsResponse +> = z.object({ + _embedded: z.object({ + product_groups: z.array(ProductGroup$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.product_groups, + v.count, + v._links, + ) +); + +export type GetProductGroupRequest = { + /** + * Product Group ID. + */ + id: number; + /** + * Include related resources. + */ + include?: string | undefined; +}; + +export type GetProductGroupResponse = ProductGroup; + +/** @internal */ +export const GetProductGroupRequest$outboundSchema: z.ZodType< + GetProductGroupRequest +> = z.object({ + id: z.number(), + include: z.string().optional(), +}); + +/** @internal */ +export const GetProductGroupResponse$inboundSchema: z.ZodType< + GetProductGroupResponse +> = ProductGroup$inboundSchema; diff --git a/src/models/operations/commerce-products.ts b/src/models/operations/commerce-products.ts index 7c52541..341f616 100644 --- a/src/models/operations/commerce-products.ts +++ b/src/models/operations/commerce-products.ts @@ -1,53 +1,146 @@ /* - * Commerce products operations. + * Commerce Products operations. */ import * as z from "zod/v4"; -import { Product, ProductsListResponse } from "../commerce/product.js"; +import { buildPaginated, Paginated } from "../pagination.js"; +import { Product, Product$inboundSchema } from "../commerce/product.js"; +import { ProductOffer, ProductOffer$inboundSchema } from "../commerce/product-offer.js"; +import { HalLinks$inboundSchema } from "../hal.js"; -export type ProductsListParams = { +export type ListProductsRequest = { + /** + * Include related resources. + */ + include?: string | undefined; + /** + * Filter by fields. + */ + filter?: Record | undefined; + /** + * Sort by fields. + */ + sort?: string | undefined; + /** + * Page number. + */ page?: number | undefined; + /** + * Page limit. + */ limit?: number | undefined; - include?: string | string[] | undefined; - filter?: Record | string | undefined; - sort?: string | string[] | undefined; }; -export type ProductGetParams = { - include?: string | string[] | undefined; -}; +export type ListProductsResponse = Paginated; + +/** @internal */ +export const ListProductsRequest$outboundSchema: z.ZodType< + ListProductsRequest +> = z.object({ + include: z.string().optional(), + filter: z.record(z.string(), z.any()).optional(), + sort: z.string().optional(), + page: z.number().optional(), + limit: z.number().optional(), +}); -export type ListProductsRequest = ProductsListParams; -export type ListProductsResponse = ProductsListResponse; +/** @internal */ +export const ListProductsResponse$inboundSchema: z.ZodType< + ListProductsResponse +> = z.object({ + _embedded: z.object({ + products: z.array(Product$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.products, + v.count, + v._links, + ) +); -export type GetProductRequest = ProductGetParams & { - id: number | string; +export type GetProductRequest = { + /** + * Product ID. + */ + id: number; + /** + * Include related resources. + */ + include?: string | undefined; }; export type GetProductResponse = Product; /** @internal */ -export const ProductsListParams$outboundSchema: z.ZodType = z - .object({ - page: z.number().int().optional(), - limit: z.number().int().optional(), - include: z.union([z.string(), z.array(z.string())]).optional(), - filter: z.union([z.string(), z.record(z.string(), z.any())]).optional(), - sort: z.union([z.string(), z.array(z.string())]).optional(), - }) - .loose(); +export const GetProductRequest$outboundSchema: z.ZodType< + GetProductRequest +> = z.object({ + id: z.number(), + include: z.string().optional(), +}); + +/** @internal */ +export const GetProductResponse$inboundSchema: z.ZodType< + GetProductResponse +> = Product$inboundSchema; + +export type ListProductOffersRequest = { + /** + * Product ID. + */ + id: number; + /** + * Include related resources. + */ + include?: string | undefined; + /** + * Filter by fields. + */ + filter?: Record | undefined; + /** + * Sort by fields. + */ + sort?: string | undefined; + /** + * Page number. + */ + page?: number | undefined; + /** + * Page limit. + */ + limit?: number | undefined; +}; + +export type ListProductOffersResponse = Paginated; /** @internal */ -export const ProductGetParams$outboundSchema: z.ZodType = z - .object({ - include: z.union([z.string(), z.array(z.string())]).optional(), - }) - .loose(); +export const ListProductOffersRequest$outboundSchema: z.ZodType< + ListProductOffersRequest +> = z.object({ + id: z.number(), + include: z.string().optional(), + filter: z.record(z.string(), z.any()).optional(), + sort: z.string().optional(), + page: z.number().optional(), + limit: z.number().optional(), +}); /** @internal */ -export const GetProductRequest$outboundSchema: z.ZodType = z - .object({ - id: z.union([z.string(), z.number()]), - include: z.union([z.string(), z.array(z.string())]).optional(), - }) - .loose(); +export const ListProductOffersResponse$inboundSchema: z.ZodType< + ListProductOffersResponse +> = z.object({ + _embedded: z.object({ + product_offers: z.array(ProductOffer$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.product_offers, + v.count, + v._links, + ) +); diff --git a/src/models/operations/commerce-reviews.ts b/src/models/operations/commerce-reviews.ts new file mode 100644 index 0000000..f2dc6a7 --- /dev/null +++ b/src/models/operations/commerce-reviews.ts @@ -0,0 +1,109 @@ +/* + * Commerce Reviews operations. + */ + +import * as z from "zod/v4"; +import { buildPaginated, Paginated } from "../pagination.js"; +import { Review, Review$inboundSchema } from "../commerce/review.js"; +import { HalLinks$inboundSchema } from "../hal.js"; + +export type ListReviewsRequest = { + /** + * Include related resources. + */ + include?: string | undefined; + /** + * Filter by fields. + */ + filter?: Record | undefined; + /** + * Sort by fields. + */ + sort?: string | undefined; + /** + * Page number. + */ + page?: number | undefined; + /** + * Page limit. + */ + limit?: number | undefined; +}; + +export type ListReviewsResponse = Paginated; + +/** @internal */ +export const ListReviewsRequest$outboundSchema: z.ZodType< + ListReviewsRequest +> = z.object({ + include: z.string().optional(), + filter: z.record(z.string(), z.any()).optional(), + sort: z.string().optional(), + page: z.number().optional(), + limit: z.number().optional(), +}); + +/** @internal */ +export const ListReviewsResponse$inboundSchema: z.ZodType< + ListReviewsResponse +> = z.object({ + _embedded: z.object({ + reviews: z.array(Review$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.reviews, + v.count, + v._links, + ) +) as unknown as z.ZodType; + +export type GetReviewRequest = { + /** + * Review ID. + */ + id: string; + /** + * Include related resources. + */ + include?: string | undefined; +}; + +export type GetReviewResponse = Review; + +/** @internal */ +export const GetReviewRequest$outboundSchema: z.ZodType< + GetReviewRequest +> = z.object({ + id: z.string(), + include: z.string().optional(), +}); + +/** @internal */ +export const GetReviewResponse$inboundSchema: z.ZodType< + GetReviewResponse +> = Review$inboundSchema; + +export type CreateReviewRequest = Record; +export type CreateReviewResponse = Review; + +/** @internal */ +export const CreateReviewRequest$outboundSchema: z.ZodType = z.record(z.string(), z.any()); +/** @internal */ +export const CreateReviewResponse$inboundSchema: z.ZodType = Review$inboundSchema; + +export type UpdateReviewRequest = { + id: string; + data: Record; +}; +export type UpdateReviewResponse = Review; + +/** @internal */ +export const UpdateReviewRequest$outboundSchema: z.ZodType = z.object({ + id: z.string(), + data: z.record(z.string(), z.any()), +}); +/** @internal */ +export const UpdateReviewResponse$inboundSchema: z.ZodType = Review$inboundSchema; diff --git a/src/models/operations/commerce-shipping-methods.ts b/src/models/operations/commerce-shipping-methods.ts new file mode 100644 index 0000000..bb84daa --- /dev/null +++ b/src/models/operations/commerce-shipping-methods.ts @@ -0,0 +1,87 @@ +/* + * Commerce Shipping Methods operations. + */ + +import * as z from "zod/v4"; +import { buildPaginated, Paginated } from "../pagination.js"; +import { ShippingMethod, ShippingMethod$inboundSchema } from "../commerce/shipping-method.js"; +import { HalLinks$inboundSchema } from "../hal.js"; + +export type ListShippingMethodsRequest = { + /** + * Include related resources. + */ + include?: string | undefined; + /** + * Filter by fields. + */ + filter?: Record | undefined; + /** + * Sort by fields. + */ + sort?: string | undefined; + /** + * Page number. + */ + page?: number | undefined; + /** + * Page limit. + */ + limit?: number | undefined; +}; + +export type ListShippingMethodsResponse = Paginated; + +/** @internal */ +export const ListShippingMethodsRequest$outboundSchema: z.ZodType< + ListShippingMethodsRequest +> = z.object({ + include: z.string().optional(), + filter: z.record(z.string(), z.any()).optional(), + sort: z.string().optional(), + page: z.number().optional(), + limit: z.number().optional(), +}); + +/** @internal */ +export const ListShippingMethodsResponse$inboundSchema: z.ZodType< + ListShippingMethodsResponse +> = z.object({ + _embedded: z.object({ + shipping_methods: z.array(ShippingMethod$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.shipping_methods, + v.count, + v._links, + ) +) as unknown as z.ZodType; + +export type GetShippingMethodRequest = { + /** + * Shipping Method ID. + */ + id: string; + /** + * Include related resources. + */ + include?: string | undefined; +}; + +export type GetShippingMethodResponse = ShippingMethod; + +/** @internal */ +export const GetShippingMethodRequest$outboundSchema: z.ZodType< + GetShippingMethodRequest +> = z.object({ + id: z.string(), + include: z.string().optional(), +}); + +/** @internal */ +export const GetShippingMethodResponse$inboundSchema: z.ZodType< + GetShippingMethodResponse +> = ShippingMethod$inboundSchema; diff --git a/src/models/operations/commerce-shipping-zones.ts b/src/models/operations/commerce-shipping-zones.ts new file mode 100644 index 0000000..4c0408b --- /dev/null +++ b/src/models/operations/commerce-shipping-zones.ts @@ -0,0 +1,87 @@ +/* + * Commerce Shipping Zones operations. + */ + +import * as z from "zod/v4"; +import { buildPaginated, Paginated } from "../pagination.js"; +import { ShippingZone, ShippingZone$inboundSchema } from "../commerce/shipping-zone.js"; +import { HalLinks$inboundSchema } from "../hal.js"; + +export type ListShippingZonesRequest = { + /** + * Include related resources. + */ + include?: string | undefined; + /** + * Filter by fields. + */ + filter?: Record | undefined; + /** + * Sort by fields. + */ + sort?: string | undefined; + /** + * Page number. + */ + page?: number | undefined; + /** + * Page limit. + */ + limit?: number | undefined; +}; + +export type ListShippingZonesResponse = Paginated; + +/** @internal */ +export const ListShippingZonesRequest$outboundSchema: z.ZodType< + ListShippingZonesRequest +> = z.object({ + include: z.string().optional(), + filter: z.record(z.string(), z.any()).optional(), + sort: z.string().optional(), + page: z.number().optional(), + limit: z.number().optional(), +}); + +/** @internal */ +export const ListShippingZonesResponse$inboundSchema: z.ZodType< + ListShippingZonesResponse +> = z.object({ + _embedded: z.object({ + shipping_zones: z.array(ShippingZone$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.shipping_zones, + v.count, + v._links, + ) +) as unknown as z.ZodType; + +export type GetShippingZoneRequest = { + /** + * Shipping Zone ID. + */ + id: string; + /** + * Include related resources. + */ + include?: string | undefined; +}; + +export type GetShippingZoneResponse = ShippingZone; + +/** @internal */ +export const GetShippingZoneRequest$outboundSchema: z.ZodType< + GetShippingZoneRequest +> = z.object({ + id: z.string(), + include: z.string().optional(), +}); + +/** @internal */ +export const GetShippingZoneResponse$inboundSchema: z.ZodType< + GetShippingZoneResponse +> = ShippingZone$inboundSchema; diff --git a/src/models/operations/commerce-subscription-intervals.ts b/src/models/operations/commerce-subscription-intervals.ts new file mode 100644 index 0000000..ae9c49b --- /dev/null +++ b/src/models/operations/commerce-subscription-intervals.ts @@ -0,0 +1,87 @@ +/* + * Commerce Subscription Intervals operations. + */ + +import * as z from "zod/v4"; +import { buildPaginated, Paginated } from "../pagination.js"; +import { SubscriptionInterval, SubscriptionInterval$inboundSchema } from "../commerce/subscription-interval.js"; +import { HalLinks$inboundSchema } from "../hal.js"; + +export type ListSubscriptionIntervalsRequest = { + /** + * Include related resources. + */ + include?: string | undefined; + /** + * Filter by fields. + */ + filter?: Record | undefined; + /** + * Sort by fields. + */ + sort?: string | undefined; + /** + * Page number. + */ + page?: number | undefined; + /** + * Page limit. + */ + limit?: number | undefined; +}; + +export type ListSubscriptionIntervalsResponse = Paginated; + +/** @internal */ +export const ListSubscriptionIntervalsRequest$outboundSchema: z.ZodType< + ListSubscriptionIntervalsRequest +> = z.object({ + include: z.string().optional(), + filter: z.record(z.string(), z.any()).optional(), + sort: z.string().optional(), + page: z.number().optional(), + limit: z.number().optional(), +}); + +/** @internal */ +export const ListSubscriptionIntervalsResponse$inboundSchema: z.ZodType< + ListSubscriptionIntervalsResponse +> = z.object({ + _embedded: z.object({ + subscription_intervals: z.array(SubscriptionInterval$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.subscription_intervals, + v.count, + v._links, + ) +); + +export type GetSubscriptionIntervalRequest = { + /** + * Subscription Interval ID. + */ + id: number; + /** + * Include related resources. + */ + include?: string | undefined; +}; + +export type GetSubscriptionIntervalResponse = SubscriptionInterval; + +/** @internal */ +export const GetSubscriptionIntervalRequest$outboundSchema: z.ZodType< + GetSubscriptionIntervalRequest +> = z.object({ + id: z.number(), + include: z.string().optional(), +}); + +/** @internal */ +export const GetSubscriptionIntervalResponse$inboundSchema: z.ZodType< + GetSubscriptionIntervalResponse +> = SubscriptionInterval$inboundSchema; diff --git a/src/models/operations/commerce-vat-validations.ts b/src/models/operations/commerce-vat-validations.ts new file mode 100644 index 0000000..d9f580c --- /dev/null +++ b/src/models/operations/commerce-vat-validations.ts @@ -0,0 +1,27 @@ +/* + * Commerce VAT Validations operations. + */ + +import * as z from "zod/v4"; +import { VatValidation, VatValidation$inboundSchema } from "../commerce/vat-validation.js"; + +export type GetVatValidationRequest = { + /** + * VAT Number. + */ + vatNumber: string; +}; + +export type GetVatValidationResponse = VatValidation; + +/** @internal */ +export const GetVatValidationRequest$outboundSchema: z.ZodType< + GetVatValidationRequest +> = z.object({ + vatNumber: z.string(), +}); + +/** @internal */ +export const GetVatValidationResponse$inboundSchema: z.ZodType< + GetVatValidationResponse +> = VatValidation$inboundSchema; diff --git a/src/models/operations/index.ts b/src/models/operations/index.ts index 9ca49da..b6d14cb 100644 --- a/src/models/operations/index.ts +++ b/src/models/operations/index.ts @@ -2,6 +2,29 @@ export * from "./commerce-products.js"; export * from "./commerce-categories.js"; export * from "./commerce-carts.js"; export * from "./commerce-cart-items.js"; +export * from "./cms-components.js"; +export * from "./cms-layouts.js"; +export * from "./cms-pages.js"; +export * from "./cms-menus.js"; +export * from "./commerce-invoices.js"; +export * from "./commerce-product-groups.js"; +export * from "./commerce-subscription-intervals.js"; +export * from "./commerce-orders.js"; +export * from "./commerce-payments.js"; +export * from "./commerce-vat-validations.js"; +export * from "./commerce-shipping-methods.js"; +export * from "./commerce-shipping-zones.js"; +export * from "./commerce-reviews.js"; +export * from "./commerce-currencies.js"; +export * from "./settings-languages.js"; +export * from "./settings-countries.js"; +export * from "./settings-social-providers.js"; +export * from "./settings-payment-methods.js"; export * from "./me.js"; export * from "./users.js"; export * from "./users-logins.js"; +export * from "./admins.js"; +export * from "./users-customers.js"; +export * from "./users-oauth-accounts.js"; +export * from "./users-mfa.js"; +export * from "./users-recovery-codes.js"; \ No newline at end of file diff --git a/src/models/operations/settings-countries.ts b/src/models/operations/settings-countries.ts new file mode 100644 index 0000000..2416312 --- /dev/null +++ b/src/models/operations/settings-countries.ts @@ -0,0 +1,83 @@ +import * as z from "zod/v4"; +import { buildPaginated, Paginated } from "../pagination.js"; +import { Country, Country$inboundSchema } from "../settings/country.js"; +import { HalLinks$inboundSchema } from "../hal.js"; + +export type ListCountriesRequest = { + /** + * Include related resources. + */ + include?: string | undefined; + /** + * Filter by fields. + */ + filter?: Record | undefined; + /** + * Sort by fields. + */ + sort?: string | undefined; + /** + * Page number. + */ + page?: number | undefined; + /** + * Page limit. + */ + limit?: number | undefined; +}; + +export type ListCountriesResponse = Paginated; + +/** @internal */ +export const ListCountriesRequest$outboundSchema: z.ZodType< + ListCountriesRequest +> = z.object({ + include: z.string().optional(), + filter: z.record(z.string(), z.any()).optional(), + sort: z.string().optional(), + page: z.number().optional(), + limit: z.number().optional(), +}); + +/** @internal */ +export const ListCountriesResponse$inboundSchema: z.ZodType< + ListCountriesResponse +> = z.object({ + _embedded: z.object({ + countries: z.array(Country$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.countries, + v.count, + v._links, + ) +); + +export type GetCountryRequest = { + /** + * Country Code. + */ + code: string; + /** + * Include related resources. + */ + include?: string | undefined; +}; + +export type GetCountryResponse = Country; + +/** @internal */ +export const GetCountryRequest$outboundSchema: z.ZodType< + GetCountryRequest +> = z.object({ + code: z.string(), + include: z.string().optional(), +}); + +/** @internal */ +export const GetCountryResponse$inboundSchema: z.ZodType< + GetCountryResponse +> = Country$inboundSchema; diff --git a/src/models/operations/settings-languages.ts b/src/models/operations/settings-languages.ts new file mode 100644 index 0000000..b496865 --- /dev/null +++ b/src/models/operations/settings-languages.ts @@ -0,0 +1,52 @@ +import * as z from "zod/v4"; +import { buildPaginated, Paginated } from "../pagination.js"; +import { Language, Language$inboundSchema } from "../settings/language.js"; +import { HalLinks$inboundSchema } from "../hal.js"; + +export type ListLanguagesRequest = { + /** + * Filter by fields. + */ + filter?: Record | undefined; + /** + * Sort by fields. + */ + sort?: string | undefined; + /** + * Page number. + */ + page?: number | undefined; + /** + * Page limit. + */ + limit?: number | undefined; +}; + +export type ListLanguagesResponse = Paginated; + +/** @internal */ +export const ListLanguagesRequest$outboundSchema: z.ZodType< + ListLanguagesRequest +> = z.object({ + filter: z.record(z.string(), z.any()).optional(), + sort: z.string().optional(), + page: z.number().optional(), + limit: z.number().optional(), +}); + +/** @internal */ +export const ListLanguagesResponse$inboundSchema: z.ZodType< + ListLanguagesResponse +> = z.object({ + _embedded: z.object({ + languages: z.array(Language$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.languages, + v.count, + v._links, + ) +); diff --git a/src/models/operations/settings-payment-methods.ts b/src/models/operations/settings-payment-methods.ts new file mode 100644 index 0000000..9d82b7d --- /dev/null +++ b/src/models/operations/settings-payment-methods.ts @@ -0,0 +1,63 @@ +import * as z from "zod/v4"; +import { buildPaginated, Paginated } from "../pagination.js"; +import { PaymentMethod, PaymentMethod$inboundSchema } from "../settings/payment-method.js"; +import { HalLinks$inboundSchema } from "../hal.js"; + +export type ListPaymentMethodsRequest = { + /** + * Page number. + */ + page?: number | undefined; + /** + * Page limit. + */ + limit?: number | undefined; +}; + +export type ListPaymentMethodsResponse = Paginated; + +/** @internal */ +export const ListPaymentMethodsRequest$outboundSchema: z.ZodType< + ListPaymentMethodsRequest +> = z.object({ + page: z.number().optional(), + limit: z.number().optional(), +}); + +/** @internal */ +export const ListPaymentMethodsResponse$inboundSchema: z.ZodType< + ListPaymentMethodsResponse +> = z.object({ + _embedded: z.object({ + paymentmethods: z.array(PaymentMethod$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.paymentmethods, + v.count, + v._links, + ) +); + +export type GetPaymentMethodRequest = { + /** + * Payment Method ID. + */ + id: number; +}; + +export type GetPaymentMethodResponse = PaymentMethod; + +/** @internal */ +export const GetPaymentMethodRequest$outboundSchema: z.ZodType< + GetPaymentMethodRequest +> = z.object({ + id: z.number(), +}); + +/** @internal */ +export const GetPaymentMethodResponse$inboundSchema: z.ZodType< + GetPaymentMethodResponse +> = PaymentMethod$inboundSchema; diff --git a/src/models/operations/settings-social-providers.ts b/src/models/operations/settings-social-providers.ts new file mode 100644 index 0000000..21f335c --- /dev/null +++ b/src/models/operations/settings-social-providers.ts @@ -0,0 +1,63 @@ +import * as z from "zod/v4"; +import { buildPaginated, Paginated } from "../pagination.js"; +import { SocialProvider, SocialProvider$inboundSchema } from "../settings/social-provider.js"; +import { HalLinks$inboundSchema } from "../hal.js"; + +export type ListSocialProvidersRequest = { + /** + * Page number. + */ + page?: number | undefined; + /** + * Page limit. + */ + limit?: number | undefined; +}; + +export type ListSocialProvidersResponse = Paginated; + +/** @internal */ +export const ListSocialProvidersRequest$outboundSchema: z.ZodType< + ListSocialProvidersRequest +> = z.object({ + page: z.number().optional(), + limit: z.number().optional(), +}); + +/** @internal */ +export const ListSocialProvidersResponse$inboundSchema: z.ZodType< + ListSocialProvidersResponse +> = z.object({ + _embedded: z.object({ + socialproviders: z.array(SocialProvider$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.socialproviders, + v.count, + v._links, + ) +); + +export type GetSocialProviderRequest = { + /** + * Social Provider ID. + */ + id: number; +}; + +export type GetSocialProviderResponse = SocialProvider; + +/** @internal */ +export const GetSocialProviderRequest$outboundSchema: z.ZodType< + GetSocialProviderRequest +> = z.object({ + id: z.number(), +}); + +/** @internal */ +export const GetSocialProviderResponse$inboundSchema: z.ZodType< + GetSocialProviderResponse +> = SocialProvider$inboundSchema; diff --git a/src/models/operations/users-customers.ts b/src/models/operations/users-customers.ts new file mode 100644 index 0000000..8e9211d --- /dev/null +++ b/src/models/operations/users-customers.ts @@ -0,0 +1,51 @@ +/* + * User Customers operations. + */ + +import * as z from "zod/v4"; +import { buildPaginated, Paginated } from "../pagination.js"; +import { CustomerUser, CustomerUser$inboundSchema } from "../commerce/customer-user.js"; +import { HalLinks$inboundSchema } from "../hal.js"; + +export type ListUserCustomersRequest = { + /** + * User ID. + */ + id: number; + /** + * Page number. + */ + page?: number | undefined; + /** + * Page limit. + */ + limit?: number | undefined; +}; + +export type ListUserCustomersResponse = Paginated; + +/** @internal */ +export const ListUserCustomersRequest$outboundSchema: z.ZodType< + ListUserCustomersRequest +> = z.object({ + id: z.number(), + page: z.number().optional(), + limit: z.number().optional(), +}); + +/** @internal */ +export const ListUserCustomersResponse$inboundSchema: z.ZodType< + ListUserCustomersResponse +> = z.object({ + _embedded: z.object({ + customer_users: z.array(CustomerUser$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.customer_users, + v.count, + v._links, + ) +); diff --git a/src/models/operations/users-mfa.ts b/src/models/operations/users-mfa.ts new file mode 100644 index 0000000..85d298c --- /dev/null +++ b/src/models/operations/users-mfa.ts @@ -0,0 +1,160 @@ +/* + * User MFA operations. + */ + +import * as z from "zod/v4"; +import { buildPaginated, Paginated } from "../pagination.js"; +import { UserMfaMethod, UserMfaMethod$inboundSchema } from "../identity/user-mfa-method.js"; +import { HalLinks$inboundSchema } from "../hal.js"; + +export type ListUserMfaMethodsRequest = { + /** + * User ID. + */ + id: number; + /** + * Page number. + */ + page?: number | undefined; + /** + * Page limit. + */ + limit?: number | undefined; +}; + +export type ListUserMfaMethodsResponse = Paginated; + +/** @internal */ +export const ListUserMfaMethodsRequest$outboundSchema: z.ZodType< + ListUserMfaMethodsRequest +> = z.object({ + id: z.number(), + page: z.number().optional(), + limit: z.number().optional(), +}); + +/** @internal */ +export const ListUserMfaMethodsResponse$inboundSchema: z.ZodType< + ListUserMfaMethodsResponse +> = z.object({ + _embedded: z.object({ + user_mfa_methods: z.array(UserMfaMethod$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.user_mfa_methods, + v.count, + v._links, + ) +); + +export type EnableMfaRequest = { + /** + * User ID. + */ + id: number; + /** + * MFA Method. + */ + method: string; +}; + +export type EnableMfaResponse = UserMfaMethod; + +/** @internal */ +export const EnableMfaRequest$outboundSchema: z.ZodType< + EnableMfaRequest +> = z.object({ + id: z.number(), + method: z.string(), +}); + +/** @internal */ +export const EnableMfaResponse$inboundSchema: z.ZodType< + EnableMfaResponse +> = UserMfaMethod$inboundSchema; + +export type DisableMfaRequest = { + /** + * User ID. + */ + id: number; + /** + * MFA Method. + */ + method: string; +}; + +export type DisableMfaResponse = void; + +/** @internal */ +export const DisableMfaRequest$outboundSchema: z.ZodType< + DisableMfaRequest +> = z.object({ + id: z.number(), + method: z.string(), +}); + +/** @internal */ +export const DisableMfaResponse$inboundSchema: z.ZodType< + DisableMfaResponse +> = z.void(); + +export type ValidateMfaRequest = { + /** + * User ID. + */ + id: number; + /** + * MFA Method. + */ + method: string; + /** + * MFA Code. + */ + code: string; +}; + +export type ValidateMfaResponse = UserMfaMethod; + +/** @internal */ +export const ValidateMfaRequest$outboundSchema: z.ZodType< + ValidateMfaRequest +> = z.object({ + id: z.number(), + method: z.string(), + code: z.string(), +}); + +/** @internal */ +export const ValidateMfaResponse$inboundSchema: z.ZodType< + ValidateMfaResponse +> = UserMfaMethod$inboundSchema; + +export type SendMfaRequest = { + /** + * User ID. + */ + id: number; + /** + * MFA Method. + */ + method: string; +}; + +export type SendMfaResponse = void; + +/** @internal */ +export const SendMfaRequest$outboundSchema: z.ZodType< + SendMfaRequest +> = z.object({ + id: z.number(), + method: z.string(), +}); + +/** @internal */ +export const SendMfaResponse$inboundSchema: z.ZodType< + SendMfaResponse +> = z.void(); diff --git a/src/models/operations/users-oauth-accounts.ts b/src/models/operations/users-oauth-accounts.ts new file mode 100644 index 0000000..51918c5 --- /dev/null +++ b/src/models/operations/users-oauth-accounts.ts @@ -0,0 +1,51 @@ +/* + * User OAuth Accounts operations. + */ + +import * as z from "zod/v4"; +import { buildPaginated, Paginated } from "../pagination.js"; +import { SocialProviderUser, SocialProviderUser$inboundSchema } from "../settings/social-provider-user.js"; +import { HalLinks$inboundSchema } from "../hal.js"; + +export type ListUserOAuthAccountsRequest = { + /** + * User ID. + */ + id: number; + /** + * Page number. + */ + page?: number | undefined; + /** + * Page limit. + */ + limit?: number | undefined; +}; + +export type ListUserOAuthAccountsResponse = Paginated; + +/** @internal */ +export const ListUserOAuthAccountsRequest$outboundSchema: z.ZodType< + ListUserOAuthAccountsRequest +> = z.object({ + id: z.number(), + page: z.number().optional(), + limit: z.number().optional(), +}); + +/** @internal */ +export const ListUserOAuthAccountsResponse$inboundSchema: z.ZodType< + ListUserOAuthAccountsResponse +> = z.object({ + _embedded: z.object({ + socialprovider_users: z.array(SocialProviderUser$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.socialprovider_users, + v.count, + v._links, + ) +); diff --git a/src/models/operations/users-recovery-codes.ts b/src/models/operations/users-recovery-codes.ts new file mode 100644 index 0000000..57816d1 --- /dev/null +++ b/src/models/operations/users-recovery-codes.ts @@ -0,0 +1,98 @@ +/* + * User Recovery Code operations. + */ + +import * as z from "zod/v4"; +import { buildPaginated, Paginated } from "../pagination.js"; +import { UserRecoveryCode, UserRecoveryCode$inboundSchema } from "../identity/user-recovery-code.js"; +import { HalLinks$inboundSchema } from "../hal.js"; + +export type ListUserRecoveryCodesRequest = { + /** + * User ID. + */ + id: number; + /** + * Page number. + */ + page?: number | undefined; + /** + * Page limit. + */ + limit?: number | undefined; +}; + +export type ListUserRecoveryCodesResponse = Paginated; + +/** @internal */ +export const ListUserRecoveryCodesRequest$outboundSchema: z.ZodType< + ListUserRecoveryCodesRequest +> = z.object({ + id: z.number(), + page: z.number().optional(), + limit: z.number().optional(), +}); + +/** @internal */ +export const ListUserRecoveryCodesResponse$inboundSchema: z.ZodType< + ListUserRecoveryCodesResponse +> = z.object({ + _embedded: z.object({ + user_recovery_codes: z.array(UserRecoveryCode$inboundSchema), + }), + count: z.number(), + _links: HalLinks$inboundSchema.optional(), +}).transform((v) => + buildPaginated( + v._embedded.user_recovery_codes, + v.count, + v._links, + ) +); + +export type RegenerateRecoveryCodesRequest = { + /** + * User ID. + */ + id: number; +}; + +export type RegenerateRecoveryCodesResponse = Array; + +/** @internal */ +export const RegenerateRecoveryCodesRequest$outboundSchema: z.ZodType< + RegenerateRecoveryCodesRequest +> = z.object({ + id: z.number(), +}); + +/** @internal */ +export const RegenerateRecoveryCodesResponse$inboundSchema: z.ZodType< + RegenerateRecoveryCodesResponse +> = z.array(UserRecoveryCode$inboundSchema); + +export type ValidateRecoveryCodeRequest = { + /** + * User ID. + */ + id: number; + /** + * Recovery Code. + */ + code: string; +}; + +export type ValidateRecoveryCodeResponse = void; + +/** @internal */ +export const ValidateRecoveryCodeRequest$outboundSchema: z.ZodType< + ValidateRecoveryCodeRequest +> = z.object({ + id: z.number(), + code: z.string(), +}); + +/** @internal */ +export const ValidateRecoveryCodeResponse$inboundSchema: z.ZodType< + ValidateRecoveryCodeResponse +> = z.void(); diff --git a/src/models/settings/country.ts b/src/models/settings/country.ts new file mode 100644 index 0000000..58d839c --- /dev/null +++ b/src/models/settings/country.ts @@ -0,0 +1,105 @@ +import * as z from "zod/v4"; +import { remap as remap$ } from "../../lib/primitives.js"; +import { Currency, Currency$inboundSchema, Currency$outboundSchema } from "../commerce/currency.js"; + +export type CountryLinks = { + self: { + href: string; + type: string; + }; +}; + +/** @internal */ +export const CountryLinks$inboundSchema: z.ZodType = z.object({ + self: z.object({ + href: z.string(), + type: z.string(), + }), +}); + +/** @internal */ +export const CountryLinks$outboundSchema: z.ZodType = z.object({ + self: z.object({ + href: z.string(), + type: z.string(), + }), +}); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace CountryLinks$ { + /** @deprecated use `CountryLinks$inboundSchema` instead. */ + export const inboundSchema = CountryLinks$inboundSchema; + /** @deprecated use `CountryLinks$outboundSchema` instead. */ + export const outboundSchema = CountryLinks$outboundSchema; +} + +export type Country = { + resource: string; + code: string; + name: string; + currency: string; + language: string; + isEnabled: boolean; + updatedAt: string; + createdAt: string; + links: CountryLinks; + embedded?: { + currency?: Currency; + }; +}; + +/** @internal */ +export const Country$inboundSchema: z.ZodType = z.object({ + resource: z.string(), + code: z.string(), + name: z.string(), + currency: z.string(), + language: z.string(), + isEnabled: z.boolean(), + updatedAt: z.string(), + createdAt: z.string(), + _links: CountryLinks$inboundSchema, + _embedded: z.object({ + currency: Currency$inboundSchema.optional(), + }).optional(), +}).transform((v) => { + return remap$(v, { + _links: "links", + _embedded: "embedded", + }); +}) as unknown as z.ZodType; + +/** @internal */ +export const Country$outboundSchema: z.ZodType = z.object({ + resource: z.string(), + code: z.string(), + name: z.string(), + currency: z.string(), + language: z.string(), + isEnabled: z.boolean(), + updatedAt: z.string(), + createdAt: z.string(), + links: CountryLinks$outboundSchema, + embedded: z.object({ + currency: Currency$outboundSchema.optional(), + }).optional(), +}).transform((v) => { + return remap$(v, { + links: "_links", + embedded: "_embedded", + }); +}) as unknown as z.ZodType; + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace Country$ { + /** @deprecated use `Country$inboundSchema` instead. */ + export const inboundSchema = Country$inboundSchema; + /** @deprecated use `Country$outboundSchema` instead. */ + export const outboundSchema = Country$outboundSchema; +} diff --git a/src/models/settings/index.ts b/src/models/settings/index.ts new file mode 100644 index 0000000..71f98df --- /dev/null +++ b/src/models/settings/index.ts @@ -0,0 +1,4 @@ +export * from "./language.js"; +export * from "./country.js"; +export * from "./social-provider.js"; +export * from "./payment-method.js"; diff --git a/src/models/settings/language.ts b/src/models/settings/language.ts new file mode 100644 index 0000000..010d130 --- /dev/null +++ b/src/models/settings/language.ts @@ -0,0 +1,41 @@ +import * as z from "zod/v4"; + +export type Language = { + resource: string; + code: string; + name: string; + native: string; + isDefault: boolean; + isEnabled: boolean; +}; + +/** @internal */ +export const Language$inboundSchema: z.ZodType = z.object({ + resource: z.string(), + code: z.string(), + name: z.string(), + native: z.string(), + isDefault: z.boolean(), + isEnabled: z.boolean(), +}); + +/** @internal */ +export const Language$outboundSchema: z.ZodType = z.object({ + resource: z.string(), + code: z.string(), + name: z.string(), + native: z.string(), + isDefault: z.boolean(), + isEnabled: z.boolean(), +}); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace Language$ { + /** @deprecated use `Language$inboundSchema` instead. */ + export const inboundSchema = Language$inboundSchema; + /** @deprecated use `Language$outboundSchema` instead. */ + export const outboundSchema = Language$outboundSchema; +} diff --git a/src/models/settings/payment-method.ts b/src/models/settings/payment-method.ts new file mode 100644 index 0000000..83695ba --- /dev/null +++ b/src/models/settings/payment-method.ts @@ -0,0 +1,109 @@ +import * as z from "zod/v4"; +import { remap as remap$ } from "../../lib/primitives.js"; +import { CurrencyAmount, CurrencyAmount$inboundSchema, CurrencyAmount$outboundSchema } from "../common/amount.js"; + +export type PaymentMethodLinks = { + self: { + href: string; + type: string; + }; +}; + +/** @internal */ +export const PaymentMethodLinks$inboundSchema: z.ZodType = z.object({ + self: z.object({ + href: z.string(), + type: z.string(), + }), +}); + +/** @internal */ +export const PaymentMethodLinks$outboundSchema: z.ZodType = z.object({ + self: z.object({ + href: z.string(), + type: z.string(), + }), +}); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace PaymentMethodLinks$ { + /** @deprecated use `PaymentMethodLinks$inboundSchema` instead. */ + export const inboundSchema = PaymentMethodLinks$inboundSchema; + /** @deprecated use `PaymentMethodLinks$outboundSchema` instead. */ + export const outboundSchema = PaymentMethodLinks$outboundSchema; +} + +export type PaymentMethod = { + resource: string; + id: number; + gateway: string; + method: string; + label: string; + icon: string; + isEnabled: boolean; + minimumAmount?: CurrencyAmount | null; + maximumAmount?: CurrencyAmount | null; + issuers?: any[]; + features?: Record; + updatedAt: string; + createdAt: string; + links: PaymentMethodLinks; +}; + +/** @internal */ +export const PaymentMethod$inboundSchema: z.ZodType = z.object({ + resource: z.string(), + id: z.number(), + gateway: z.string(), + method: z.string(), + label: z.string(), + icon: z.string(), + isEnabled: z.boolean(), + minimumAmount: z.nullable(CurrencyAmount$inboundSchema).optional(), + maximumAmount: z.nullable(CurrencyAmount$inboundSchema).optional(), + issuers: z.array(z.any()).optional(), + features: z.record(z.string(), z.any()).optional(), + updatedAt: z.string(), + createdAt: z.string(), + _links: PaymentMethodLinks$inboundSchema, +}).transform((v) => { + return remap$(v, { + _links: "links", + }); +}) as unknown as z.ZodType; + +/** @internal */ +export const PaymentMethod$outboundSchema: z.ZodType = z.object({ + resource: z.string(), + id: z.number(), + gateway: z.string(), + method: z.string(), + label: z.string(), + icon: z.string(), + isEnabled: z.boolean(), + minimumAmount: z.nullable(CurrencyAmount$outboundSchema).optional(), + maximumAmount: z.nullable(CurrencyAmount$outboundSchema).optional(), + issuers: z.array(z.any()).optional(), + features: z.record(z.string(), z.any()).optional(), + updatedAt: z.string(), + createdAt: z.string(), + links: PaymentMethodLinks$outboundSchema, +}).transform((v) => { + return remap$(v, { + links: "_links", + }); +}) as unknown as z.ZodType; + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace PaymentMethod$ { + /** @deprecated use `PaymentMethod$inboundSchema` instead. */ + export const inboundSchema = PaymentMethod$inboundSchema; + /** @deprecated use `PaymentMethod$outboundSchema` instead. */ + export const outboundSchema = PaymentMethod$outboundSchema; +} diff --git a/src/models/settings/social-provider-user.ts b/src/models/settings/social-provider-user.ts new file mode 100644 index 0000000..00bf0a4 --- /dev/null +++ b/src/models/settings/social-provider-user.ts @@ -0,0 +1,38 @@ +/* + * Social Provider User model. + */ + +import * as z from "zod/v4"; +import { remap as remap$ } from "../../lib/primitives.js"; +import { HalLinks, HalLinks$inboundSchema } from "../hal.js"; + +export type SocialProviderUser = { + resource: "socialprovider_user"; + id: number; + userId: number; + provider: string; + identifier?: string; + name?: string; + avatar?: string | null; + updatedAt: string; + createdAt: string; + links?: HalLinks; +}; + +/** @internal */ +export const SocialProviderUser$inboundSchema: z.ZodType = z.object({ + resource: z.literal("socialprovider_user"), + id: z.number().int(), + userId: z.number().int(), + provider: z.string(), + identifier: z.string().optional(), + name: z.string().optional(), + avatar: z.string().nullable().optional(), + updatedAt: z.string(), + createdAt: z.string(), + _links: HalLinks$inboundSchema.optional(), +}).loose().transform((v) => { + return remap$(v, { + "_links": "links", + }) as SocialProviderUser; +}); diff --git a/src/models/settings/social-provider.ts b/src/models/settings/social-provider.ts new file mode 100644 index 0000000..ea271e7 --- /dev/null +++ b/src/models/settings/social-provider.ts @@ -0,0 +1,93 @@ +import * as z from "zod/v4"; +import { remap as remap$ } from "../../lib/primitives.js"; + +export type SocialProviderLinks = { + self: { + href: string; + type: string; + }; +}; + +/** @internal */ +export const SocialProviderLinks$inboundSchema: z.ZodType = z.object({ + self: z.object({ + href: z.string(), + type: z.string(), + }), +}); + +/** @internal */ +export const SocialProviderLinks$outboundSchema: z.ZodType = z.object({ + self: z.object({ + href: z.string(), + type: z.string(), + }), +}); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace SocialProviderLinks$ { + /** @deprecated use `SocialProviderLinks$inboundSchema` instead. */ + export const inboundSchema = SocialProviderLinks$inboundSchema; + /** @deprecated use `SocialProviderLinks$outboundSchema` instead. */ + export const outboundSchema = SocialProviderLinks$outboundSchema; +} + +export type SocialProvider = { + resource: string; + id: number; + provider: string; + name: string; + icon: string; + isEnabled: boolean; + updatedAt: string; + createdAt: string; + links: SocialProviderLinks; +}; + +/** @internal */ +export const SocialProvider$inboundSchema: z.ZodType = z.object({ + resource: z.string(), + id: z.number(), + provider: z.string(), + name: z.string(), + icon: z.string(), + isEnabled: z.boolean(), + updatedAt: z.string(), + createdAt: z.string(), + _links: SocialProviderLinks$inboundSchema, +}).transform((v) => { + return remap$(v, { + _links: "links", + }); +}) as unknown as z.ZodType; + +/** @internal */ +export const SocialProvider$outboundSchema: z.ZodType = z.object({ + resource: z.string(), + id: z.number(), + provider: z.string(), + name: z.string(), + icon: z.string(), + isEnabled: z.boolean(), + updatedAt: z.string(), + createdAt: z.string(), + links: SocialProviderLinks$outboundSchema, +}).transform((v) => { + return remap$(v, { + links: "_links", + }); +}) as unknown as z.ZodType; + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace SocialProvider$ { + /** @deprecated use `SocialProvider$inboundSchema` instead. */ + export const inboundSchema = SocialProvider$inboundSchema; + /** @deprecated use `SocialProvider$outboundSchema` instead. */ + export const outboundSchema = SocialProvider$outboundSchema; +} diff --git a/src/sdk/admins.ts b/src/sdk/admins.ts new file mode 100644 index 0000000..b3ae8ff --- /dev/null +++ b/src/sdk/admins.ts @@ -0,0 +1,33 @@ +/* + * Admins SDK. + */ + +import { ClientSDK, RequestOptions } from "../lib/sdks.js"; +import { unwrapAsync } from "../types/fp.js"; +import * as operations from "../models/operations/index.js"; +import { adminsGet } from "../funcs/admins/adminsGet.js"; +import { adminsList } from "../funcs/admins/adminsList.js"; + +export class Admins extends ClientSDK { + async list( + request?: operations.ListAdminsRequest | undefined, + options?: RequestOptions, + ): Promise { + return unwrapAsync(adminsList( + this, + request, + options, + )); + } + + async get( + request: operations.GetAdminRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(adminsGet( + this, + request, + options, + )); + } +} diff --git a/src/sdk/cms/components.ts b/src/sdk/cms/components.ts new file mode 100644 index 0000000..dfb370e --- /dev/null +++ b/src/sdk/cms/components.ts @@ -0,0 +1,25 @@ +/* + * CMS Components SDK. + */ + +import { componentsList } from "../../funcs/cms/componentsList.js"; +import { componentsGet } from "../../funcs/cms/componentsGet.js"; +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import { unwrapAsync } from "../../types/fp.js"; + +export class Components extends ClientSDK { + async list( + request?: operations.ListComponentsRequest | undefined, + options?: RequestOptions, + ): Promise { + return unwrapAsync(componentsList(this, request, options)); + } + + async get( + request: operations.GetComponentRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(componentsGet(this, request, options)); + } +} diff --git a/src/sdk/cms/index.ts b/src/sdk/cms/index.ts index ed085b3..4e9451e 100644 --- a/src/sdk/cms/index.ts +++ b/src/sdk/cms/index.ts @@ -3,5 +3,35 @@ */ import { ClientSDK } from "../../lib/sdks.js"; +import { Components } from "./components.js"; +import { Layouts } from "./layouts.js"; +import { Pages } from "./pages.js"; +import { Menus } from "./menus.js"; -export class Cms extends ClientSDK {} +export { Components } from "./components.js"; +export { Layouts } from "./layouts.js"; +export { Pages } from "./pages.js"; +export { Menus } from "./menus.js"; + +export class Cms extends ClientSDK { + private _components?: Components; + private _layouts?: Layouts; + private _pages?: Pages; + private _menus?: Menus; + + get components(): Components { + return (this._components ??= new Components(this._options)); + } + + get layouts(): Layouts { + return (this._layouts ??= new Layouts(this._options)); + } + + get pages(): Pages { + return (this._pages ??= new Pages(this._options)); + } + + get menus(): Menus { + return (this._menus ??= new Menus(this._options)); + } +} diff --git a/src/sdk/cms/layouts.ts b/src/sdk/cms/layouts.ts new file mode 100644 index 0000000..2b231f9 --- /dev/null +++ b/src/sdk/cms/layouts.ts @@ -0,0 +1,25 @@ +/* + * CMS Layouts SDK. + */ + +import { layoutsList } from "../../funcs/cms/layoutsList.js"; +import { layoutsGet } from "../../funcs/cms/layoutsGet.js"; +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import { unwrapAsync } from "../../types/fp.js"; + +export class Layouts extends ClientSDK { + async list( + request?: operations.ListLayoutsRequest | undefined, + options?: RequestOptions, + ): Promise { + return unwrapAsync(layoutsList(this, request, options)); + } + + async get( + request: operations.GetLayoutRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(layoutsGet(this, request, options)); + } +} diff --git a/src/sdk/cms/menus.ts b/src/sdk/cms/menus.ts new file mode 100644 index 0000000..497e83d --- /dev/null +++ b/src/sdk/cms/menus.ts @@ -0,0 +1,25 @@ +/* + * CMS Menus SDK. + */ + +import { menusList } from "../../funcs/cms/menusList.js"; +import { menusGet } from "../../funcs/cms/menusGet.js"; +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import { unwrapAsync } from "../../types/fp.js"; + +export class Menus extends ClientSDK { + async list( + request?: operations.ListMenusRequest | undefined, + options?: RequestOptions, + ): Promise { + return unwrapAsync(menusList(this, request, options)); + } + + async get( + request: operations.GetMenuRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(menusGet(this, request, options)); + } +} diff --git a/src/sdk/cms/pages.ts b/src/sdk/cms/pages.ts new file mode 100644 index 0000000..ffbd5c9 --- /dev/null +++ b/src/sdk/cms/pages.ts @@ -0,0 +1,33 @@ +/* + * CMS Pages SDK. + */ + +import { pagesList } from "../../funcs/cms/pagesList.js"; +import { pagesGet } from "../../funcs/cms/pagesGet.js"; +import { pagesComponentsList } from "../../funcs/cms/pagesComponentsList.js"; +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import { unwrapAsync } from "../../types/fp.js"; + +export class Pages extends ClientSDK { + async list( + request?: operations.ListPagesRequest | undefined, + options?: RequestOptions, + ): Promise { + return unwrapAsync(pagesList(this, request, options)); + } + + async get( + request: operations.GetPageRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(pagesGet(this, request, options)); + } + + async listComponents( + request: operations.ListPageComponentsRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(pagesComponentsList(this, request, options)); + } +} diff --git a/src/sdk/commerce/cart-items.ts b/src/sdk/commerce/cart-items.ts index 7be5b22..099d07b 100644 --- a/src/sdk/commerce/cart-items.ts +++ b/src/sdk/commerce/cart-items.ts @@ -1,112 +1,90 @@ /* - * SDK module: Commerce Cart Items + * Commerce Cart Items SDK. */ +import { cartItemsList } from "../../funcs/commerce/cartItemsList.js"; import { cartItemsCreate } from "../../funcs/commerce/cartItemsCreate.js"; -import { cartItemsDelete } from "../../funcs/commerce/cartItemsDelete.js"; import { cartItemsGet } from "../../funcs/commerce/cartItemsGet.js"; -import { cartItemsList } from "../../funcs/commerce/cartItemsList.js"; import { cartItemsUpdate } from "../../funcs/commerce/cartItemsUpdate.js"; +import { cartItemsDelete } from "../../funcs/commerce/cartItemsDelete.js"; import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; import * as operations from "../../models/operations/index.js"; import { unwrapAsync } from "../../types/fp.js"; -export type CartItemsListParams = operations.CartItemsListParams; -export type CartItemGetParams = operations.CartItemGetParams; -export type CartItemCreateInput = operations.CartItemCreateInput; -export type CartItemUpdateInput = operations.CartItemUpdateInput; - export class CartItems extends ClientSDK { /** - * List cart items + * List cart items. */ async list( cartId: string, - params?: CartItemsListParams, + request?: operations.ListCartItemsRequest | undefined, options?: RequestOptions, ): Promise { return unwrapAsync(cartItemsList( this, - { - cartId, - ...(params ?? {}), - }, + { ...request, cartId }, options, )); } /** - * Get a cart item by ID + * Create cart item. */ - async get( + async create( cartId: string, - itemId: string, - params?: CartItemGetParams, + productId: string, + quantity: number, options?: RequestOptions, - ): Promise { - return unwrapAsync(cartItemsGet( + ): Promise { + return unwrapAsync(cartItemsCreate( this, - { - cartId, - itemId, - ...(params ?? {}), - }, + { cartId, data: { product_id: productId, quantity } }, options, )); } /** - * Create a cart item + * Get cart item. */ - async create( + async get( cartId: string, - body: CartItemCreateInput, - options?: RequestOptions, - ): Promise { - return unwrapAsync(cartItemsCreate( + itemId: string, + options?: RequestOptions & { include?: string }, + ): Promise { + return unwrapAsync(cartItemsGet( this, - { - cartId, - body, - }, + { cartId, itemId, include: options?.include }, options, )); } /** - * Update a cart item + * Update cart item. */ async update( cartId: string, itemId: string, - body: CartItemUpdateInput, + data: Record, options?: RequestOptions, ): Promise { return unwrapAsync(cartItemsUpdate( this, - { - cartId, - itemId, - body, - }, + { cartId, itemId, data }, options, )); } /** - * Delete a cart item + * Delete cart item. */ async delete( cartId: string, itemId: string, options?: RequestOptions, - ): Promise { + ): Promise { return unwrapAsync(cartItemsDelete( this, - { - cartId, - itemId, - }, + { cartId, itemId }, options, )); } diff --git a/src/sdk/commerce/carts.ts b/src/sdk/commerce/carts.ts index 59119cf..50fd1b9 100644 --- a/src/sdk/commerce/carts.ts +++ b/src/sdk/commerce/carts.ts @@ -1,49 +1,38 @@ /* - * SDK module: Commerce Carts + * Commerce Carts SDK. */ +import { cartsList } from "../../funcs/commerce/cartsList.js"; import { cartsCreate } from "../../funcs/commerce/cartsCreate.js"; import { cartsGet } from "../../funcs/commerce/cartsGet.js"; -import { cartsList } from "../../funcs/commerce/cartsList.js"; import { cartsUpdate } from "../../funcs/commerce/cartsUpdate.js"; import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; import * as operations from "../../models/operations/index.js"; import { unwrapAsync } from "../../types/fp.js"; -export type CartsListParams = operations.CartsListParams; -export type CartGetParams = operations.CartGetParams; -export type CartCreateInput = operations.CartCreateInput; -export type CartUpdateInput = operations.CartUpdateInput; - export class Carts extends ClientSDK { /** - * List carts + * List carts. */ async list( - params?: CartsListParams, + request?: operations.ListCartsRequest | undefined, options?: RequestOptions, ): Promise { return unwrapAsync(cartsList( this, - params, + request, options, )); } /** - * Get a cart by ID + * Create cart. */ - async get( - id: string, - params?: CartGetParams, + async create( + request: operations.CreateCartRequest, options?: RequestOptions, - ): Promise { - const request: operations.GetCartRequest = { - id, - ...(params ?? {}), - }; - - return unwrapAsync(cartsGet( + ): Promise { + return unwrapAsync(cartsCreate( this, request, options, @@ -51,30 +40,30 @@ export class Carts extends ClientSDK { } /** - * Create a cart + * Get cart. */ - async create( - body: CartCreateInput, - options?: RequestOptions, - ): Promise { - return unwrapAsync(cartsCreate( + async get( + id: string, + options?: RequestOptions & { include?: string }, + ): Promise { + return unwrapAsync(cartsGet( this, - body, + { id, include: options?.include }, options, )); } /** - * Update a cart + * Update cart. */ async update( id: string, - body: CartUpdateInput, + data: Record, options?: RequestOptions, ): Promise { return unwrapAsync(cartsUpdate( this, - { id, body }, + { id, data }, options, )); } diff --git a/src/sdk/commerce/categories.ts b/src/sdk/commerce/categories.ts index b0ecaf2..6001ad0 100644 --- a/src/sdk/commerce/categories.ts +++ b/src/sdk/commerce/categories.ts @@ -1,48 +1,25 @@ /* - * SDK module: Commerce Categories + * Commerce Categories SDK. */ -import { categoriesGet } from "../../funcs/commerce/categoriesGet.js"; import { categoriesList } from "../../funcs/commerce/categoriesList.js"; +import { categoriesGet } from "../../funcs/commerce/categoriesGet.js"; import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; import * as operations from "../../models/operations/index.js"; import { unwrapAsync } from "../../types/fp.js"; -export type CategoriesListParams = operations.CategoriesListParams; -export type CategoryGetParams = operations.CategoryGetParams; - export class Categories extends ClientSDK { - /** - * List categories - */ async list( - params?: CategoriesListParams, + request?: operations.ListCategoriesRequest | undefined, options?: RequestOptions, ): Promise { - return unwrapAsync(categoriesList( - this, - params, - options, - )); + return unwrapAsync(categoriesList(this, request, options)); } - /** - * Get a category by ID - */ async get( - id: number | string, - params?: CategoryGetParams, + request: operations.GetCategoryRequest, options?: RequestOptions, ): Promise { - const request: operations.GetCategoryRequest = { - id, - ...(params ?? {}), - }; - - return unwrapAsync(categoriesGet( - this, - request, - options, - )); + return unwrapAsync(categoriesGet(this, request, options)); } } diff --git a/src/sdk/commerce/currencies.ts b/src/sdk/commerce/currencies.ts new file mode 100644 index 0000000..8a32a10 --- /dev/null +++ b/src/sdk/commerce/currencies.ts @@ -0,0 +1,39 @@ +/* + * Commerce Currencies SDK. + */ + +import { currenciesList } from "../../funcs/commerce/currenciesList.js"; +import { currenciesGet } from "../../funcs/commerce/currenciesGet.js"; +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import { unwrapAsync } from "../../types/fp.js"; + +export class Currencies extends ClientSDK { + /** + * List currencies. + */ + async list( + request?: operations.ListCurrenciesRequest | undefined, + options?: RequestOptions, + ): Promise { + return unwrapAsync(currenciesList( + this, + request, + options, + )); + } + + /** + * Get currency. + */ + async get( + code: string, + options?: RequestOptions, + ): Promise { + return unwrapAsync(currenciesGet( + this, + { code }, + options, + )); + } +} diff --git a/src/sdk/commerce/index.ts b/src/sdk/commerce/index.ts index aabc070..ae6fa70 100644 --- a/src/sdk/commerce/index.ts +++ b/src/sdk/commerce/index.ts @@ -7,12 +7,47 @@ import { CartItems } from "./cart-items.js"; import { Carts } from "./carts.js"; import { Categories } from "./categories.js"; import { Products } from "./products.js"; +import { Invoices } from "./invoices.js"; +import { ProductGroups } from "./product-groups.js"; +import { SubscriptionIntervals } from "./subscription-intervals.js"; +import { Orders } from "./orders.js"; +import { Payments } from "./payments.js"; +import { VatValidations } from "./vat-validations.js"; +import { ShippingMethods } from "./shipping-methods.js"; +import { ShippingZones } from "./shipping-zones.js"; +import { Reviews } from "./reviews.js"; +import { Currencies } from "./currencies.js"; + +export { CartItems } from "./cart-items.js"; +export { Carts } from "./carts.js"; +export { Categories } from "./categories.js"; +export { Products } from "./products.js"; +export { Invoices } from "./invoices.js"; +export { ProductGroups } from "./product-groups.js"; +export { SubscriptionIntervals } from "./subscription-intervals.js"; +export { Orders } from "./orders.js"; +export { Payments } from "./payments.js"; +export { VatValidations } from "./vat-validations.js"; +export { ShippingMethods } from "./shipping-methods.js"; +export { ShippingZones } from "./shipping-zones.js"; +export { Reviews } from "./reviews.js"; +export { Currencies } from "./currencies.js"; export class Commerce extends ClientSDK { private _cartItems?: CartItems; private _carts?: Carts; private _categories?: Categories; private _products?: Products; + private _invoices?: Invoices; + private _productGroups?: ProductGroups; + private _subscriptionIntervals?: SubscriptionIntervals; + private _orders?: Orders; + private _payments?: Payments; + private _vatValidations?: VatValidations; + private _shippingMethods?: ShippingMethods; + private _shippingZones?: ShippingZones; + private _reviews?: Reviews; + private _currencies?: Currencies; get cartItems(): CartItems { return (this._cartItems ??= new CartItems(this._options)); @@ -29,4 +64,44 @@ export class Commerce extends ClientSDK { get products(): Products { return (this._products ??= new Products(this._options)); } + + get invoices(): Invoices { + return (this._invoices ??= new Invoices(this._options)); + } + + get productGroups(): ProductGroups { + return (this._productGroups ??= new ProductGroups(this._options)); + } + + get subscriptionIntervals(): SubscriptionIntervals { + return (this._subscriptionIntervals ??= new SubscriptionIntervals(this._options)); + } + + get orders(): Orders { + return (this._orders ??= new Orders(this._options)); + } + + get payments(): Payments { + return (this._payments ??= new Payments(this._options)); + } + + get vatValidations(): VatValidations { + return (this._vatValidations ??= new VatValidations(this._options)); + } + + get shippingMethods(): ShippingMethods { + return (this._shippingMethods ??= new ShippingMethods(this._options)); + } + + get shippingZones(): ShippingZones { + return (this._shippingZones ??= new ShippingZones(this._options)); + } + + get reviews(): Reviews { + return (this._reviews ??= new Reviews(this._options)); + } + + get currencies(): Currencies { + return (this._currencies ??= new Currencies(this._options)); + } } diff --git a/src/sdk/commerce/invoices.ts b/src/sdk/commerce/invoices.ts new file mode 100644 index 0000000..5a51522 --- /dev/null +++ b/src/sdk/commerce/invoices.ts @@ -0,0 +1,39 @@ +/* + * Commerce Invoices SDK. + */ + +import { invoicesGet } from "../../funcs/commerce/invoicesGet.js"; +import { invoicesList } from "../../funcs/commerce/invoicesList.js"; +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import { unwrapAsync } from "../../types/fp.js"; + +export class Invoices extends ClientSDK { + /** + * List invoices. + */ + async list( + request?: operations.ListInvoicesRequest | undefined, + options?: RequestOptions, + ): Promise { + return unwrapAsync(invoicesList( + this, + request, + options, + )); + } + + /** + * Get invoice. + */ + async get( + request: operations.GetInvoiceRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(invoicesGet( + this, + request, + options, + )); + } +} diff --git a/src/sdk/commerce/orders.ts b/src/sdk/commerce/orders.ts new file mode 100644 index 0000000..9361457 --- /dev/null +++ b/src/sdk/commerce/orders.ts @@ -0,0 +1,86 @@ +/* + * Commerce Orders SDK. + */ + +import { ordersList } from "../../funcs/commerce/ordersList.js"; +import { ordersCreate } from "../../funcs/commerce/ordersCreate.js"; +import { ordersGet } from "../../funcs/commerce/ordersGet.js"; +import { ordersUpdate } from "../../funcs/commerce/ordersUpdate.js"; +import { ordersPaymentsList } from "../../funcs/commerce/ordersPaymentsList.js"; +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import { unwrapAsync } from "../../types/fp.js"; + +export class Orders extends ClientSDK { + /** + * List orders. + */ + async list( + request?: operations.ListOrdersRequest | undefined, + options?: RequestOptions, + ): Promise { + return unwrapAsync(ordersList( + this, + request, + options, + )); + } + + /** + * Create order. + */ + async create( + request: operations.CreateOrderRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(ordersCreate( + this, + request, + options, + )); + } + + /** + * Get order. + */ + async get( + id: string, + options?: RequestOptions & { include?: string }, + ): Promise { + return unwrapAsync(ordersGet( + this, + { id, include: options?.include }, + options, + )); + } + + /** + * Update order. + */ + async update( + id: string, + data: Record, + options?: RequestOptions, + ): Promise { + return unwrapAsync(ordersUpdate( + this, + { id, data }, + options, + )); + } + + /** + * List order payments. + */ + async listPayments( + orderId: string, + request?: operations.ListOrderPaymentsRequest | undefined, + options?: RequestOptions, + ): Promise { + return unwrapAsync(ordersPaymentsList( + this, + { ...request, orderId }, + options, + )); + } +} diff --git a/src/sdk/commerce/payments.ts b/src/sdk/commerce/payments.ts new file mode 100644 index 0000000..d540fa4 --- /dev/null +++ b/src/sdk/commerce/payments.ts @@ -0,0 +1,24 @@ +/* + * Commerce Payments SDK. + */ + +import { paymentsGet } from "../../funcs/commerce/paymentsGet.js"; +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import { unwrapAsync } from "../../types/fp.js"; + +export class Payments extends ClientSDK { + /** + * Get payment. + */ + async get( + id: string, + options?: RequestOptions & { include?: string }, + ): Promise { + return unwrapAsync(paymentsGet( + this, + { id, include: options?.include }, + options, + )); + } +} diff --git a/src/sdk/commerce/product-groups.ts b/src/sdk/commerce/product-groups.ts new file mode 100644 index 0000000..5e6c750 --- /dev/null +++ b/src/sdk/commerce/product-groups.ts @@ -0,0 +1,25 @@ +/* + * Commerce Product Groups SDK. + */ + +import { productGroupsList } from "../../funcs/commerce/productGroupsList.js"; +import { productGroupsGet } from "../../funcs/commerce/productGroupsGet.js"; +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import { unwrapAsync } from "../../types/fp.js"; + +export class ProductGroups extends ClientSDK { + async list( + request?: operations.ListProductGroupsRequest | undefined, + options?: RequestOptions, + ): Promise { + return unwrapAsync(productGroupsList(this, request, options)); + } + + async get( + request: operations.GetProductGroupRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(productGroupsGet(this, request, options)); + } +} diff --git a/src/sdk/commerce/products.ts b/src/sdk/commerce/products.ts index b953115..6afc37c 100644 --- a/src/sdk/commerce/products.ts +++ b/src/sdk/commerce/products.ts @@ -1,48 +1,33 @@ /* - * SDK module: Commerce Products + * Commerce Products SDK. */ -import { productsGet } from "../../funcs/commerce/productsGet.js"; import { productsList } from "../../funcs/commerce/productsList.js"; +import { productsGet } from "../../funcs/commerce/productsGet.js"; +import { productsOffersList } from "../../funcs/commerce/productsOffersList.js"; import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; import * as operations from "../../models/operations/index.js"; import { unwrapAsync } from "../../types/fp.js"; -export type ProductsListParams = operations.ProductsListParams; -export type ProductGetParams = operations.ProductGetParams; - export class Products extends ClientSDK { - /** - * List products - */ async list( - params?: ProductsListParams, + request?: operations.ListProductsRequest | undefined, options?: RequestOptions, ): Promise { - return unwrapAsync(productsList( - this, - params, - options, - )); + return unwrapAsync(productsList(this, request, options)); } - /** - * Get a product by ID - */ async get( - id: number | string, - params?: ProductGetParams, + request: operations.GetProductRequest, options?: RequestOptions, ): Promise { - const request: operations.GetProductRequest = { - id, - ...(params ?? {}), - }; + return unwrapAsync(productsGet(this, request, options)); + } - return unwrapAsync(productsGet( - this, - request, - options, - )); + async listOffers( + request: operations.ListProductOffersRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(productsOffersList(this, request, options)); } } diff --git a/src/sdk/commerce/reviews.ts b/src/sdk/commerce/reviews.ts new file mode 100644 index 0000000..6db5fdf --- /dev/null +++ b/src/sdk/commerce/reviews.ts @@ -0,0 +1,70 @@ +/* + * Commerce Reviews SDK. + */ + +import { reviewsList } from "../../funcs/commerce/reviewsList.js"; +import { reviewsCreate } from "../../funcs/commerce/reviewsCreate.js"; +import { reviewsGet } from "../../funcs/commerce/reviewsGet.js"; +import { reviewsUpdate } from "../../funcs/commerce/reviewsUpdate.js"; +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import { unwrapAsync } from "../../types/fp.js"; + +export class Reviews extends ClientSDK { + /** + * List reviews. + */ + async list( + request?: operations.ListReviewsRequest | undefined, + options?: RequestOptions, + ): Promise { + return unwrapAsync(reviewsList( + this, + request, + options, + )); + } + + /** + * Create review. + */ + async create( + request: operations.CreateReviewRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(reviewsCreate( + this, + request, + options, + )); + } + + /** + * Get review. + */ + async get( + id: string, + options?: RequestOptions & { include?: string }, + ): Promise { + return unwrapAsync(reviewsGet( + this, + { id, include: options?.include }, + options, + )); + } + + /** + * Update review. + */ + async update( + id: string, + data: Record, + options?: RequestOptions, + ): Promise { + return unwrapAsync(reviewsUpdate( + this, + { id, data }, + options, + )); + } +} diff --git a/src/sdk/commerce/shipping-methods.ts b/src/sdk/commerce/shipping-methods.ts new file mode 100644 index 0000000..ea0f851 --- /dev/null +++ b/src/sdk/commerce/shipping-methods.ts @@ -0,0 +1,39 @@ +/* + * Commerce Shipping Methods SDK. + */ + +import { shippingMethodsList } from "../../funcs/commerce/shippingMethodsList.js"; +import { shippingMethodsGet } from "../../funcs/commerce/shippingMethodsGet.js"; +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import { unwrapAsync } from "../../types/fp.js"; + +export class ShippingMethods extends ClientSDK { + /** + * List shipping methods. + */ + async list( + request?: operations.ListShippingMethodsRequest | undefined, + options?: RequestOptions, + ): Promise { + return unwrapAsync(shippingMethodsList( + this, + request, + options, + )); + } + + /** + * Get shipping method. + */ + async get( + id: string, + options?: RequestOptions & { include?: string }, + ): Promise { + return unwrapAsync(shippingMethodsGet( + this, + { id, include: options?.include }, + options, + )); + } +} diff --git a/src/sdk/commerce/shipping-zones.ts b/src/sdk/commerce/shipping-zones.ts new file mode 100644 index 0000000..1857b01 --- /dev/null +++ b/src/sdk/commerce/shipping-zones.ts @@ -0,0 +1,39 @@ +/* + * Commerce Shipping Zones SDK. + */ + +import { shippingZonesList } from "../../funcs/commerce/shippingZonesList.js"; +import { shippingZonesGet } from "../../funcs/commerce/shippingZonesGet.js"; +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import { unwrapAsync } from "../../types/fp.js"; + +export class ShippingZones extends ClientSDK { + /** + * List shipping zones. + */ + async list( + request?: operations.ListShippingZonesRequest | undefined, + options?: RequestOptions, + ): Promise { + return unwrapAsync(shippingZonesList( + this, + request, + options, + )); + } + + /** + * Get shipping zone. + */ + async get( + id: string, + options?: RequestOptions & { include?: string }, + ): Promise { + return unwrapAsync(shippingZonesGet( + this, + { id, include: options?.include }, + options, + )); + } +} diff --git a/src/sdk/commerce/subscription-intervals.ts b/src/sdk/commerce/subscription-intervals.ts new file mode 100644 index 0000000..9077c86 --- /dev/null +++ b/src/sdk/commerce/subscription-intervals.ts @@ -0,0 +1,25 @@ +/* + * Commerce Subscription Intervals SDK. + */ + +import { subscriptionIntervalsList } from "../../funcs/commerce/subscriptionIntervalsList.js"; +import { subscriptionIntervalsGet } from "../../funcs/commerce/subscriptionIntervalsGet.js"; +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import { unwrapAsync } from "../../types/fp.js"; + +export class SubscriptionIntervals extends ClientSDK { + async list( + request?: operations.ListSubscriptionIntervalsRequest | undefined, + options?: RequestOptions, + ): Promise { + return unwrapAsync(subscriptionIntervalsList(this, request, options)); + } + + async get( + request: operations.GetSubscriptionIntervalRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(subscriptionIntervalsGet(this, request, options)); + } +} diff --git a/src/sdk/commerce/vat-validations.ts b/src/sdk/commerce/vat-validations.ts new file mode 100644 index 0000000..e841035 --- /dev/null +++ b/src/sdk/commerce/vat-validations.ts @@ -0,0 +1,24 @@ +/* + * Commerce VAT Validations SDK. + */ + +import { vatValidationsGet } from "../../funcs/commerce/vatValidationsGet.js"; +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import { unwrapAsync } from "../../types/fp.js"; + +export class VatValidations extends ClientSDK { + /** + * Validate VAT. + */ + async get( + number: string, + options?: RequestOptions, + ): Promise { + return unwrapAsync(vatValidationsGet( + this, + { vatNumber: number }, + options, + )); + } +} diff --git a/src/sdk/sdk.ts b/src/sdk/sdk.ts index 6353d01..bf75706 100644 --- a/src/sdk/sdk.ts +++ b/src/sdk/sdk.ts @@ -6,6 +6,7 @@ import { Http } from "./http.js"; import { Me } from "./me.js"; import { Settings } from "./settings/index.js"; import { Users } from "./users/index.js"; +import { Admins } from "./admins.js"; import type { SDKOptions } from "../lib/config.js"; import type { OminityModuleInput, @@ -66,4 +67,9 @@ export class Ominity extends ClientSDK { get users(): Users { return (this._users ??= new Users(this._options)); } + + private _admins?: Admins; + get admins(): Admins { + return (this._admins ??= new Admins(this._options)); + } } diff --git a/src/sdk/settings/countries.ts b/src/sdk/settings/countries.ts new file mode 100644 index 0000000..3a7d8e4 --- /dev/null +++ b/src/sdk/settings/countries.ts @@ -0,0 +1,35 @@ +import { countriesGet } from "../../funcs/settings/countriesGet.js"; +import { countriesList } from "../../funcs/settings/countriesList.js"; +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import { unwrapAsync } from "../../types/fp.js"; + +export class Countries extends ClientSDK { + /** + * List countries. + */ + async list( + request?: operations.ListCountriesRequest | undefined, + options?: RequestOptions, + ): Promise { + return unwrapAsync(countriesList( + this, + request, + options, + )); + } + + /** + * Get country. + */ + async get( + request: operations.GetCountryRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(countriesGet( + this, + request, + options, + )); + } +} diff --git a/src/sdk/settings/index.ts b/src/sdk/settings/index.ts index 54c7968..238245b 100644 --- a/src/sdk/settings/index.ts +++ b/src/sdk/settings/index.ts @@ -3,5 +3,35 @@ */ import { ClientSDK } from "../../lib/sdks.js"; +import { Languages } from "./languages.js"; +import { Countries } from "./countries.js"; +import { SocialProviders } from "./social-providers.js"; +import { PaymentMethods } from "./payment-methods.js"; -export class Settings extends ClientSDK {} +export { Languages } from "./languages.js"; +export { Countries } from "./countries.js"; +export { SocialProviders } from "./social-providers.js"; +export { PaymentMethods } from "./payment-methods.js"; + +export class Settings extends ClientSDK { + private _languages?: Languages; + private _countries?: Countries; + private _socialProviders?: SocialProviders; + private _paymentMethods?: PaymentMethods; + + get languages(): Languages { + return (this._languages ??= new Languages(this._options)); + } + + get countries(): Countries { + return (this._countries ??= new Countries(this._options)); + } + + get socialProviders(): SocialProviders { + return (this._socialProviders ??= new SocialProviders(this._options)); + } + + get paymentMethods(): PaymentMethods { + return (this._paymentMethods ??= new PaymentMethods(this._options)); + } +} diff --git a/src/sdk/settings/languages.ts b/src/sdk/settings/languages.ts new file mode 100644 index 0000000..1c1d1b3 --- /dev/null +++ b/src/sdk/settings/languages.ts @@ -0,0 +1,20 @@ +import { languagesList } from "../../funcs/settings/languagesList.js"; +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import { unwrapAsync } from "../../types/fp.js"; + +export class Languages extends ClientSDK { + /** + * List languages. + */ + async list( + request?: operations.ListLanguagesRequest | undefined, + options?: RequestOptions, + ): Promise { + return unwrapAsync(languagesList( + this, + request, + options, + )); + } +} diff --git a/src/sdk/settings/payment-methods.ts b/src/sdk/settings/payment-methods.ts new file mode 100644 index 0000000..11ed4c9 --- /dev/null +++ b/src/sdk/settings/payment-methods.ts @@ -0,0 +1,35 @@ +import { paymentMethodsGet } from "../../funcs/settings/paymentMethodsGet.js"; +import { paymentMethodsList } from "../../funcs/settings/paymentMethodsList.js"; +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import { unwrapAsync } from "../../types/fp.js"; + +export class PaymentMethods extends ClientSDK { + /** + * List payment methods. + */ + async list( + request?: operations.ListPaymentMethodsRequest | undefined, + options?: RequestOptions, + ): Promise { + return unwrapAsync(paymentMethodsList( + this, + request, + options, + )); + } + + /** + * Get payment method. + */ + async get( + request: operations.GetPaymentMethodRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(paymentMethodsGet( + this, + request, + options, + )); + } +} diff --git a/src/sdk/settings/social-providers.ts b/src/sdk/settings/social-providers.ts new file mode 100644 index 0000000..2d1e30b --- /dev/null +++ b/src/sdk/settings/social-providers.ts @@ -0,0 +1,35 @@ +import { socialProvidersGet } from "../../funcs/settings/socialProvidersGet.js"; +import { socialProvidersList } from "../../funcs/settings/socialProvidersList.js"; +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; +import * as operations from "../../models/operations/index.js"; +import { unwrapAsync } from "../../types/fp.js"; + +export class SocialProviders extends ClientSDK { + /** + * List social providers. + */ + async list( + request?: operations.ListSocialProvidersRequest | undefined, + options?: RequestOptions, + ): Promise { + return unwrapAsync(socialProvidersList( + this, + request, + options, + )); + } + + /** + * Get social provider. + */ + async get( + request: operations.GetSocialProviderRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(socialProvidersGet( + this, + request, + options, + )); + } +} diff --git a/src/sdk/users/index.ts b/src/sdk/users/index.ts index 037e727..5d2aa9e 100644 --- a/src/sdk/users/index.ts +++ b/src/sdk/users/index.ts @@ -9,6 +9,16 @@ import { usersCreate } from "../../funcs/users/usersCreate.js"; import { usersGet } from "../../funcs/users/usersGet.js"; import { usersList } from "../../funcs/users/usersList.js"; import { usersUpdate } from "../../funcs/users/usersUpdate.js"; +import { usersListCustomers } from "../../funcs/users/usersListCustomers.js"; +import { usersListOAuthAccounts } from "../../funcs/users/usersListOAuthAccounts.js"; +import { usersListMfaMethods } from "../../funcs/users/usersListMfaMethods.js"; +import { usersEnableMfa } from "../../funcs/users/usersEnableMfa.js"; +import { usersDisableMfa } from "../../funcs/users/usersDisableMfa.js"; +import { usersValidateMfa } from "../../funcs/users/usersValidateMfa.js"; +import { usersSendMfa } from "../../funcs/users/usersSendMfa.js"; +import { usersListRecoveryCodes } from "../../funcs/users/usersListRecoveryCodes.js"; +import { usersRegenerateRecoveryCodes } from "../../funcs/users/usersRegenerateRecoveryCodes.js"; +import { usersValidateRecoveryCode } from "../../funcs/users/usersValidateRecoveryCode.js"; import { UserLogins } from "./logins.js"; export class Users extends ClientSDK { @@ -61,4 +71,114 @@ export class Users extends ClientSDK { options, )); } + + async listCustomers( + request: operations.ListUserCustomersRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(usersListCustomers( + this, + request, + options, + )); + } + + async listOAuthAccounts( + request: operations.ListUserOAuthAccountsRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(usersListOAuthAccounts( + this, + request, + options, + )); + } + + async listMfaMethods( + request: operations.ListUserMfaMethodsRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(usersListMfaMethods( + this, + request, + options, + )); + } + + async enableMfa( + request: operations.EnableMfaRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(usersEnableMfa( + this, + request, + options, + )); + } + + async disableMfa( + request: operations.DisableMfaRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(usersDisableMfa( + this, + request, + options, + )); + } + + async validateMfa( + request: operations.ValidateMfaRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(usersValidateMfa( + this, + request, + options, + )); + } + + async sendMfa( + request: operations.SendMfaRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(usersSendMfa( + this, + request, + options, + )); + } + + async listRecoveryCodes( + request: operations.ListUserRecoveryCodesRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(usersListRecoveryCodes( + this, + request, + options, + )); + } + + async regenerateRecoveryCodes( + request: operations.RegenerateRecoveryCodesRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(usersRegenerateRecoveryCodes( + this, + request, + options, + )); + } + + async validateRecoveryCode( + request: operations.ValidateRecoveryCodeRequest, + options?: RequestOptions, + ): Promise { + return unwrapAsync(usersValidateRecoveryCode( + this, + request, + options, + )); + } }