Compare commits

..

No commits in common. "5d795107808b02afc810fa743e74502b5c9b1aca" and "689dc2485095a3dce998a93ef364d6e652fff8a5" have entirely different histories.

15 changed files with 60 additions and 45 deletions

2
.gitignore vendored
View file

@ -1,2 +1,2 @@
dist/ build/
node_modules/ node_modules/

View file

View file

@ -1,2 +1,2 @@
pnpm-lock.yaml pnpm-lock.yaml
dist/ build/

View file

@ -1,3 +1,6 @@
// const HOST = 'https://tiendas.axoft.com'
export const HOST = "http://sutty.vm:4001";
export interface Paging { export interface Paging {
/** /**
* Si hay más páginas disponibles * Si hay más páginas disponibles

View file

@ -1,5 +1,6 @@
import { import {
QueryCustomer, QueryCustomer,
HOST,
Paginacion, Paginacion,
paginacionToSearchParams, paginacionToSearchParams,
Paging, Paging,
@ -77,7 +78,6 @@ export interface CustomerResponse {
} }
export async function getCustomers( export async function getCustomers(
host: string,
token: string, token: string,
options: CustomerQuery options: CustomerQuery
): Promise<CustomerResponse> { ): Promise<CustomerResponse> {
@ -87,7 +87,7 @@ export async function getCustomers(
queryCustomerToSearchParams(options.customer, searchParams); queryCustomerToSearchParams(options.customer, searchParams);
} }
const res = await fetch( const res = await fetch(
`${host}/api/Aperture/Customer?${searchParams.toString()}`, `${HOST}/api/Aperture/Customer?${searchParams.toString()}`,
{ {
headers: { headers: {
accesstoken: token, accesstoken: token,

View file

@ -11,11 +11,9 @@ import {
Producto, Producto,
Precio, Precio,
getPublications, getPublications,
Publication,
} from "../index.js"; } from "../index.js";
// TODO: hacerlo input
const HOST = "http://sutty.vm:4001";
const tokenInput = document.querySelector<HTMLInputElement>("#token-input")!; const tokenInput = document.querySelector<HTMLInputElement>("#token-input")!;
if (localStorage.token) { if (localStorage.token) {
@ -82,19 +80,17 @@ function setupForm(selector: string, listener: (event: Event) => Promise<any>) {
}); });
} }
setupForm("#token", () => dummy(HOST, token())); setupForm("#token", () => dummy(token()));
setupForm("#save-token", async () => { setupForm("#save-token", async () => {
localStorage.token = token(); localStorage.token = token();
}); });
setupForm("#productos", () => getProductos(HOST, token(), {})); setupForm("#productos", () => getProductos(token(), {}));
setupForm("#publicaciones", () => getPublications(HOST, token(), {})); setupForm("#publicaciones", () => getPublications(token(), {}));
setupForm("#price", () => getPrices(HOST, token(), {})); setupForm("#price", () => getPrices(token(), {}));
setupForm("#price-by-customer", (event) => setupForm("#price-by-customer", (event) =>
getPricesByCustomer(HOST, token(), { getPricesByCustomer(token(), { filter: (event.target! as any).filter.value })
filter: (event.target! as any).filter.value,
})
); );
setupForm("#customers", () => getCustomers(HOST, token(), {})); setupForm("#customers", () => getCustomers(token(), {}));
let customer: Customer | null = null; let customer: Customer | null = null;
@ -102,7 +98,7 @@ setupForm("#pedido-customer", async (event) => {
const cuit = (event.target! as any).cuit.value; const cuit = (event.target! as any).cuit.value;
if (cuit.length === 0) throw new Error("No pusiste un CUIT."); if (cuit.length === 0) throw new Error("No pusiste un CUIT.");
const customers = await getCustomers(HOST, token(), { const customers = await getCustomers(token(), {
customer: { customer: {
type: TipoDeDocumento.CUIT, type: TipoDeDocumento.CUIT,
number: cuit, number: cuit,
@ -139,11 +135,11 @@ setupForm("#pedido-item", async (event) => {
const sku = (event.target! as any).sku.value; const sku = (event.target! as any).sku.value;
if (sku.length === 0) throw new Error("No pusiste un SKU."); if (sku.length === 0) throw new Error("No pusiste un SKU.");
const productosResponse = await getProductos(HOST, token(), { filter: sku }); const productosResponse = await getProductos(token(), { filter: sku });
if (productosResponse.Data.length !== 1) if (productosResponse.Data.length !== 1)
throw new Error("Encontré más de un producto."); throw new Error("Encontré más de un producto.");
const preciosDelClienteResponse = await getPricesByCustomer(HOST, token(), { const preciosDelClienteResponse = await getPricesByCustomer(token(), {
SKUCode: sku, SKUCode: sku,
customer: { customer: {
type: customer.DocumentType, type: customer.DocumentType,
@ -162,7 +158,7 @@ setupForm("#pedido-item", async (event) => {
return productosResponse; return productosResponse;
}); });
setupForm("#pedido", async () => { setupForm("#pedido", async (event) => {
if (!customer) throw new Error("No seteaste lx cliente todavía."); if (!customer) throw new Error("No seteaste lx cliente todavía.");
// Se supone que Total es: // Se supone que Total es:
@ -195,5 +191,5 @@ setupForm("#pedido", async () => {
}, },
}; };
return await order(HOST, token(), orderJson); return await order(token(), orderJson);
}); });

View file

@ -82,4 +82,4 @@
</form> </form>
</section> </section>
<script type="module" src="../dist/demo/demo.js"></script> <script type="module" src="../build/demo/demo.js"></script>

View file

@ -1,5 +1,7 @@
export async function dummy(host: string, token: string) { import { HOST } from "./common.js";
const res = await fetch(`${host}/api/Aperture/dummy`, {
export async function dummy(token: string) {
const res = await fetch(`${HOST}/api/Aperture/dummy`, {
method: "POST", method: "POST",
headers: { headers: {
accesstoken: token, accesstoken: token,

View file

@ -1,3 +1,10 @@
import {
HOST,
Paginacion,
paginacionToSearchParams,
Paging,
} from "./common.js";
export interface OrderDto { export interface OrderDto {
SituacionOrden?: null | string; SituacionOrden?: null | string;
Date: string; Date: string;
@ -111,11 +118,10 @@ export interface PaymentDto {
export interface OrderResponse {} export interface OrderResponse {}
export async function order( export async function order(
host: string,
token: string, token: string,
order: OrderDto order: OrderDto
): Promise<OrderResponse> { ): Promise<OrderResponse> {
const res = await fetch(`${host}/api/Aperture/order`, { const res = await fetch(`${HOST}/api/Aperture/order`, {
method: "POST", method: "POST",
headers: { headers: {
accesstoken: token, accesstoken: token,

View file

@ -1,11 +1,10 @@
{ {
"name": "@suttyweb/hyperpop", "name": "hyperpop",
"version": "0.1.1", "version": "0.0.0",
"description": "Un cliente de API de https://github.com/TangoSoftware/ApiTiendas", "description": "Un cliente de API de https://github.com/TangoSoftware/ApiTiendas",
"license": "SEE LICENSE IN LICENSE", "main": "index.js",
"scripts": { "scripts": {
"build": "tsc", "build": "tsc",
"prepublish": "tsc",
"watch-build": "tsc --watch", "watch-build": "tsc --watch",
"format": "prettier --write .", "format": "prettier --write .",
"check-format": "prettier --check .", "check-format": "prettier --check .",
@ -20,8 +19,7 @@
"api" "api"
], ],
"author": "Sutty <hi@sutty.nl>", "author": "Sutty <hi@sutty.nl>",
"main": "dist/index.js", "license": "SEE LICENSE IN LICENSE",
"types": "dist/index.d.ts",
"devDependencies": { "devDependencies": {
"prettier": "^2.4.1", "prettier": "^2.4.1",
"typescript": "^4.4.3" "typescript": "^4.4.3"

View file

@ -1,4 +1,9 @@
import { Paginacion, paginacionToSearchParams, Paging } from "./common.js"; import {
HOST,
Paginacion,
paginacionToSearchParams,
Paging,
} from "./common.js";
export interface PriceQuery { export interface PriceQuery {
paginacion?: Paginacion; paginacion?: Paginacion;
@ -20,7 +25,6 @@ export interface PriceResponse {
} }
export async function getPrices( export async function getPrices(
host: string,
token: string, token: string,
options: PriceQuery options: PriceQuery
): Promise<PriceResponse> { ): Promise<PriceResponse> {
@ -33,7 +37,7 @@ export async function getPrices(
searchParams.set("SKUCode", options.SKUCode); searchParams.set("SKUCode", options.SKUCode);
} }
const res = await fetch( const res = await fetch(
`${host}/api/Aperture/Price?${searchParams.toString()}`, `${HOST}/api/Aperture/Price?${searchParams.toString()}`,
{ {
headers: { headers: {
accesstoken: token, accesstoken: token,

View file

@ -1,6 +1,7 @@
import { import {
QueryCustomer, QueryCustomer,
queryCustomerToSearchParams, queryCustomerToSearchParams,
HOST,
Paginacion, Paginacion,
paginacionToSearchParams, paginacionToSearchParams,
Paging, Paging,
@ -27,7 +28,6 @@ export interface PreciosResponse {
} }
export async function getPricesByCustomer( export async function getPricesByCustomer(
host: string,
token: string, token: string,
options: PriceByCustomerQuery options: PriceByCustomerQuery
): Promise<PreciosResponse> { ): Promise<PreciosResponse> {
@ -43,7 +43,7 @@ export async function getPricesByCustomer(
queryCustomerToSearchParams(options.customer, searchParams); queryCustomerToSearchParams(options.customer, searchParams);
} }
const res = await fetch( const res = await fetch(
`${host}/api/Aperture/PriceByCustomer?${searchParams.toString()}`, `${HOST}/api/Aperture/PriceByCustomer?${searchParams.toString()}`,
{ {
headers: { headers: {
accesstoken: token, accesstoken: token,

View file

@ -1,4 +1,9 @@
import { Paginacion, paginacionToSearchParams, Paging } from "./common.js"; import {
HOST,
Paginacion,
paginacionToSearchParams,
Paging,
} from "./common.js";
export interface ProductosQuery { export interface ProductosQuery {
paginacion?: Paginacion; paginacion?: Paginacion;
@ -49,7 +54,6 @@ export interface ProductosResponse {
// https://github.com/TangoSoftware/ApiTiendas#art%C3%ADculos // https://github.com/TangoSoftware/ApiTiendas#art%C3%ADculos
export async function getProductos( export async function getProductos(
host: string,
token: string, token: string,
options: ProductosQuery options: ProductosQuery
): Promise<ProductosResponse> { ): Promise<ProductosResponse> {
@ -62,7 +66,7 @@ export async function getProductos(
searchParams.set("filter", options.filter); searchParams.set("filter", options.filter);
} }
const res = await fetch( const res = await fetch(
`${host}/api/Aperture/Product?${searchParams.toString()}`, `${HOST}/api/Aperture/Product?${searchParams.toString()}`,
{ {
headers: { headers: {
accesstoken: token, accesstoken: token,

View file

@ -1,4 +1,9 @@
import { Paginacion, paginacionToSearchParams, Paging } from "./common.js"; import {
HOST,
Paginacion,
paginacionToSearchParams,
Paging,
} from "./common.js";
export interface PublicationsQuery { export interface PublicationsQuery {
paginacion?: Paginacion; paginacion?: Paginacion;
@ -22,7 +27,6 @@ export interface PublicationsResponse {
// https://github.com/TangoSoftware/ApiTiendas#art%C3%ADculos // https://github.com/TangoSoftware/ApiTiendas#art%C3%ADculos
export async function getPublications( export async function getPublications(
host: string,
token: string, token: string,
options: PublicationsQuery options: PublicationsQuery
): Promise<PublicationsResponse> { ): Promise<PublicationsResponse> {
@ -38,7 +42,7 @@ export async function getPublications(
searchParams.set("variantCode", options.variantCode); searchParams.set("variantCode", options.variantCode);
} }
const res = await fetch( const res = await fetch(
`${host}/api/Aperture/Publications?${searchParams.toString()}`, `${HOST}/api/Aperture/Publications?${searchParams.toString()}`,
{ {
headers: { headers: {
accesstoken: token, accesstoken: token,

View file

@ -6,7 +6,7 @@
"module": "es6", "module": "es6",
"moduleResolution": "node", "moduleResolution": "node",
"outDir": "./dist", "outDir": "./build",
"allowJs": false, "allowJs": false,
@ -15,8 +15,6 @@
"strict": true, "strict": true,
"declaration": true,
"skipLibCheck": true "skipLibCheck": true
} }
} }