Skip to content

Commit

Permalink
Merge pull request #45 from gabrielMatosBoubee/cep-vnda-PDP
Browse files Browse the repository at this point in the history
Cep vnda pdp & start.ts FIX
  • Loading branch information
matheusgr authored Sep 13, 2023
2 parents b6a7dca + 21ea6b5 commit 617199d
Show file tree
Hide file tree
Showing 16 changed files with 383 additions and 206 deletions.
24 changes: 12 additions & 12 deletions compat/$live/manifest.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
// This file is automatically updated during development when running `dev.ts`.

import * as $$$0 from "./loaders/state.ts";
import * as $$$$0 from "./handlers/router.ts";
import * as $$$$1 from "./handlers/devPage.ts";
import * as $$$$0 from "./handlers/devPage.ts";
import * as $$$$1 from "./handlers/router.ts";
import * as $$$$$$0 from "./sections/UseSlot.tsx";
import * as $$$$$$1 from "./sections/Slot.tsx";
import * as $$$$$$2 from "./sections/EmptySection.tsx";
import * as $$$$$$3 from "./sections/PageInclude.tsx";
import * as $$$$$$4 from "./sections/Conditional_Beta.tsx";
import * as $$$$$$1 from "./sections/EmptySection.tsx";
import * as $$$$$$2 from "./sections/Conditional_Beta.tsx";
import * as $$$$$$3 from "./sections/Slot.tsx";
import * as $$$$$$4 from "./sections/PageInclude.tsx";

const manifest = {
"loaders": {
"$live/loaders/state.ts": $$$0,
},
"handlers": {
"$live/handlers/devPage.ts": $$$$1,
"$live/handlers/router.ts": $$$$0,
"$live/handlers/devPage.ts": $$$$0,
"$live/handlers/router.ts": $$$$1,
},
"sections": {
"$live/sections/Conditional_Beta.tsx": $$$$$$4,
"$live/sections/EmptySection.tsx": $$$$$$2,
"$live/sections/PageInclude.tsx": $$$$$$3,
"$live/sections/Slot.tsx": $$$$$$1,
"$live/sections/Conditional_Beta.tsx": $$$$$$2,
"$live/sections/EmptySection.tsx": $$$$$$1,
"$live/sections/PageInclude.tsx": $$$$$$4,
"$live/sections/Slot.tsx": $$$$$$3,
"$live/sections/UseSlot.tsx": $$$$$$0,
},
"name": "$live",
Expand Down
16 changes: 8 additions & 8 deletions compat/std/manifest.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import * as $0 from "./functions/requestToParam.ts";
import * as $$$0 from "./loaders/x/redirects.ts";
import * as $$$1 from "./loaders/x/font.ts";
import * as $$$$$$0 from "./sections/SEOPLP.tsx";
import * as $$$$$$1 from "./sections/Analytics.tsx";
import * as $$$$$$2 from "./sections/VTEXPortalDataLayerCompatibility.tsx";
import * as $$$$$$3 from "./sections/SEOPDP.tsx";
import * as $$$$$$0 from "./sections/SEOPDP.tsx";
import * as $$$$$$1 from "./sections/SEOPLP.tsx";
import * as $$$$$$2 from "./sections/Analytics.tsx";
import * as $$$$$$3 from "./sections/VTEXPortalDataLayerCompatibility.tsx";

const manifest = {
"functions": {
Expand All @@ -19,10 +19,10 @@ const manifest = {
"deco-sites/std/loaders/x/redirects.ts": $$$0,
},
"sections": {
"deco-sites/std/sections/Analytics.tsx": $$$$$$1,
"deco-sites/std/sections/SEOPDP.tsx": $$$$$$3,
"deco-sites/std/sections/SEOPLP.tsx": $$$$$$0,
"deco-sites/std/sections/VTEXPortalDataLayerCompatibility.tsx": $$$$$$2,
"deco-sites/std/sections/Analytics.tsx": $$$$$$2,
"deco-sites/std/sections/SEOPDP.tsx": $$$$$$0,
"deco-sites/std/sections/SEOPLP.tsx": $$$$$$1,
"deco-sites/std/sections/VTEXPortalDataLayerCompatibility.tsx": $$$$$$3,
},
"name": "deco-sites/std",
"baseUrl": import.meta.url,
Expand Down
8 changes: 4 additions & 4 deletions decohub/manifest.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
// This file is automatically updated during development when running `dev.ts`.

import * as $$$$$$$$$$$0 from "./apps/workflows.ts";
import * as $$$$$$$$$$$1 from "./apps/handlebars.ts";
import * as $$$$$$$$$$$2 from "./apps/verified-reviews.ts";
import * as $$$$$$$$$$$1 from "./apps/verified-reviews.ts";
import * as $$$$$$$$$$$2 from "./apps/handlebars.ts";

const manifest = {
"apps": {
"decohub/apps/handlebars.ts": $$$$$$$$$$$1,
"decohub/apps/verified-reviews.ts": $$$$$$$$$$$2,
"decohub/apps/handlebars.ts": $$$$$$$$$$$2,
"decohub/apps/verified-reviews.ts": $$$$$$$$$$$1,
"decohub/apps/workflows.ts": $$$$$$$$$$$0,
},
"name": "decohub",
Expand Down
30 changes: 25 additions & 5 deletions scripts/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ const GRAPHQL_EXTENSION = ".graphql.json";
const allOpenAPIPaths: string[] = [];
const allGraphqlPaths: string[] = [];

function processTypeInNestedObject(obj: any) {
if (typeof obj === "object" && obj !== null) {
if ("nullable" in obj && obj.nullable === true) {
if ("type" in obj) {
if (Array.isArray(obj.type)) {
obj.type.unshift("null");
} else {
obj.type = ["null", obj.type];
}
}
}

for (const key in obj) {
obj[key] = processTypeInNestedObject(obj[key]);
}
}

return obj;
}

for await (const entry of walk(".")) {
if (entry.isFile) {
if (entry.path.endsWith(OPENAPI_EXTENSION)) {
Expand Down Expand Up @@ -106,7 +126,6 @@ const generateOpenAPI = async () => {
if (!item) {
continue;
}

const {
parameters = [],
requestBody,
Expand All @@ -128,7 +147,6 @@ const generateOpenAPI = async () => {
.reduce((schema, item) => {
if (item?.schema && item.in === "query") {
hasParams = true;

schema.properties[item.name] = {
description: item.description,
...item.schema,
Expand All @@ -148,15 +166,17 @@ const generateOpenAPI = async () => {

if (hasParams) {
schema.required?.push("searchParams");
schema.properties!["searchParams"] = searchParams;
schema.properties!["searchParams"] = processTypeInNestedObject(
searchParams,
);
}

const body = resolve(requestBody)
?.content[MEDIA_TYPE_JSON]?.schema;

if (body) {
schema.required?.push("body");
schema.properties!["body"] = body;
schema.properties!["body"] = processTypeInNestedObject(body);
}

const ok = responses?.["200"] ||
Expand All @@ -166,7 +186,7 @@ const generateOpenAPI = async () => {

if (response) {
schema.required?.push("response");
schema.properties!["response"] = response;
schema.properties!["response"] = processTypeInNestedObject(response);
}

const type = `${verb.toUpperCase()} ${pathTemplate}`;
Expand Down
16 changes: 8 additions & 8 deletions shopify/manifest.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
// This file is automatically updated during development when running `dev.ts`.

import * as $$$0 from "./loaders/ProductList.ts";
import * as $$$1 from "./loaders/ProductDetailsPage.ts";
import * as $$$2 from "./loaders/ProductListingPage.ts";
import * as $$$3 from "./loaders/proxy.ts";
import * as $$$4 from "./loaders/cart.ts";
import * as $$$1 from "./loaders/ProductListingPage.ts";
import * as $$$2 from "./loaders/proxy.ts";
import * as $$$3 from "./loaders/cart.ts";
import * as $$$4 from "./loaders/ProductDetailsPage.ts";
import * as $$$$0 from "./handlers/sitemap.ts";
import * as $$$$$$$$$0 from "./actions/cart/updateCoupons.ts";
import * as $$$$$$$$$1 from "./actions/cart/updateItems.ts";
import * as $$$$$$$$$2 from "./actions/cart/addItems.ts";

const manifest = {
"loaders": {
"shopify/loaders/cart.ts": $$$4,
"shopify/loaders/ProductDetailsPage.ts": $$$1,
"shopify/loaders/cart.ts": $$$3,
"shopify/loaders/ProductDetailsPage.ts": $$$4,
"shopify/loaders/ProductList.ts": $$$0,
"shopify/loaders/ProductListingPage.ts": $$$2,
"shopify/loaders/proxy.ts": $$$3,
"shopify/loaders/ProductListingPage.ts": $$$1,
"shopify/loaders/proxy.ts": $$$2,
},
"handlers": {
"shopify/handlers/sitemap.ts": $$$$0,
Expand Down
32 changes: 32 additions & 0 deletions vnda/actions/cart/simulation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { AppContext } from "../../mod.ts";
import type { ShippingMethod } from "../../utils/client/types.ts";
import { badRequest } from "deco/mod.ts";

export interface Props {
skuId: string;
quantity: number;
zip: string;
}

const action = async (
props: Props,
_req: Request,
ctx: AppContext,
): Promise<ShippingMethod[]> => {
const { api } = ctx;
const { skuId, quantity, zip } = props;

if (!skuId || !quantity || !zip) {
badRequest({
message: "could not find some props",
});
}
const cep = await api["GET /api/v2/variants/:sku/shipping_methods"]({
sku: skuId,
quantity,
zip,
});
return cep.json();
};

export default action;
1 change: 1 addition & 0 deletions vnda/hooks/useCart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const state = {
update: enqueue("vnda/actions/cart/updateCart.ts"),
addItem: enqueue("vnda/actions/cart/addItem.ts"),
updateItem: enqueue("vnda/actions/cart/updateItem.ts"),
simulate: invoke.vnda.actions.cart.simulation,
};

export const useCart = () => state;
34 changes: 18 additions & 16 deletions vnda/manifest.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@
// This file SHOULD be checked into source version control.
// This file is automatically updated during development when running `dev.ts`.

import * as $$$0 from "./loaders/productList.ts";
import * as $$$1 from "./loaders/productDetailsPage.ts";
import * as $$$2 from "./loaders/productListingPage.ts";
import * as $$$3 from "./loaders/proxy.ts";
import * as $$$4 from "./loaders/cart.ts";
import * as $$$$$$$$$0 from "./actions/cart/updateItem.ts";
import * as $$$$$$$$$1 from "./actions/cart/updateCart.ts";
import * as $$$$$$$$$2 from "./actions/cart/addItem.ts";
import * as $$$0 from "./loaders/proxy.ts";
import * as $$$1 from "./loaders/cart.ts";
import * as $$$2 from "./loaders/productList.ts";
import * as $$$3 from "./loaders/productListingPage.ts";
import * as $$$4 from "./loaders/productDetailsPage.ts";
import * as $$$$$$$$$0 from "./actions/cart/addItem.ts";
import * as $$$$$$$$$1 from "./actions/cart/simulation.ts";
import * as $$$$$$$$$2 from "./actions/cart/updateCart.ts";
import * as $$$$$$$$$3 from "./actions/cart/updateItem.ts";

const manifest = {
"loaders": {
"vnda/loaders/cart.ts": $$$4,
"vnda/loaders/productDetailsPage.ts": $$$1,
"vnda/loaders/productList.ts": $$$0,
"vnda/loaders/productListingPage.ts": $$$2,
"vnda/loaders/proxy.ts": $$$3,
"vnda/loaders/cart.ts": $$$1,
"vnda/loaders/productDetailsPage.ts": $$$4,
"vnda/loaders/productList.ts": $$$2,
"vnda/loaders/productListingPage.ts": $$$3,
"vnda/loaders/proxy.ts": $$$0,
},
"actions": {
"vnda/actions/cart/addItem.ts": $$$$$$$$$2,
"vnda/actions/cart/updateCart.ts": $$$$$$$$$1,
"vnda/actions/cart/updateItem.ts": $$$$$$$$$0,
"vnda/actions/cart/addItem.ts": $$$$$$$$$0,
"vnda/actions/cart/simulation.ts": $$$$$$$$$1,
"vnda/actions/cart/updateCart.ts": $$$$$$$$$2,
"vnda/actions/cart/updateItem.ts": $$$$$$$$$3,
},
"name": "vnda",
"baseUrl": import.meta.url,
Expand Down
121 changes: 121 additions & 0 deletions vnda/utils/client/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import {
Item,
OrderForm,
ProductGroup,
ProductSearchResult,
RelatedItemTag,
SEO,
ShippingMethod,
Sort,
TagsSearchParams,
} from "./types.ts";

export interface API {
/** @docs https://developers.vnda.com.br/reference/get-api-v2-products-id */
"GET /api/v2/products/:id": {
response: ProductGroup;
searchParams: { include_images: boolean };
};

/** @docs https://developers.vnda.com.br/reference/get-api-v2-banners */
"GET /api/v2/banners": {
searchParams: {
only_valid: boolean;
tag: "listagem-banner-principal";
};
};

/** @docs https://developers.vnda.com.br/reference/get-api-v2-tags-name */
"GET /api/v2/tags/:name": {
response: RelatedItemTag;
};

/** @docs https://developers.vnda.com.br/reference/get-api-v2-tags */
"GET /api/v2/tags": {
response: RelatedItemTag[];
searchParams: TagsSearchParams;
};

"GET /api/v2/seo_data": {
response: SEO[];
searchParams: {
resource_type: "Product" | "Page";
resource_id: string | number;
type: "category";
} | {
resource_type: "Tag";
code: string;
type: "category";
};
};

/** @docs https://developers.vnda.com.br/reference/get-api-v2-products-search */
"GET /api/v2/products/search": {
response: Omit<ProductSearchResult, "pagination">;
searchParams: {
term?: string | undefined;
page?: number;
"tags[]"?: string[];
sort?: Sort;
per_page?: number;
wildcard?: boolean;
} & { [x: string]: unknown };
};

/** @docs https://developers.vnda.com.br/reference/get-api-v2-carts-id */
"GET /api/v2/carts/:cartId": {
response: OrderForm;
};

/** @docs https://developers.vnda.com.br/reference/post-api-v2-carts */
"POST /api/v2/carts": {
response: OrderForm;
};

/** @docs https://developers.vnda.com.br/reference/get-api-v2-carts-id */
"PATCH /api/v2/carts/:cartId": {
response: OrderForm;
body: {
agent?: string;
zip?: string;
client_id?: number;
coupon_code?: string;
rebate_token?: string;
};
};

/** @docs https://developers.vnda.com.br/reference/post-api-v2-carts-cart_id-items */
"POST /api/v2/carts/:cartId/items": {
response: Item;
body: {
sku: string;
quantity: number;
place_id?: number;
store_coupon_code?: string;
customizations?: Record<string, unknown>;
extra?: Record<string, unknown>;
};
};

/** @docs https://developers.vnda.com.br/reference/patch-api-v2-carts-cart_id-items-id */
"PATCH /api/v2/carts/:cartId/items/:itemId": {
response: Item;
body: {
sku?: string;
quantity: number;
place_id?: number;
store_coupon_code?: string;
customizations?: Record<string, unknown>;
extra?: Record<string, unknown>;
};
};

/** @docs https://developers.vnda.com.br/reference/delete-api-v2-carts-cart_id-items-id */
"DELETE /api/v2/carts/:cartId/items/:itemId": undefined;

/** @docs https://developers.vnda.com.br/reference/get-api-v2-variants-variant_sku-shipping_methods */
"GET /api/v2/variants/:sku/shipping_methods": {
response: ShippingMethod[];
searchParams: { quantity: number; zip: string };
};
}
Loading

0 comments on commit 617199d

Please sign in to comment.