Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error:update #58

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .deco/blocks/app-tags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"__resolveType": "site/apps/local/app-tags.ts"
}
2 changes: 1 addition & 1 deletion .deco/metadata/blocks.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,5 @@ deno.lock
.config.json
# Fresh build directory
_fresh/

_docker_deps.ts
8 changes: 0 additions & 8 deletions _docker_deps.ts

This file was deleted.

1 change: 1 addition & 0 deletions app-tags/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# app-tags
25 changes: 25 additions & 0 deletions app-tags/actions/myAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { AppContext } from "../mod.ts";
import { GithubUser } from "../utils/types.ts";

interface Props {
username: string;
}

/**
* @title This name will appear on the admin
*/
const action = async (
props: Props,
_req: Request,
ctx: AppContext,
): Promise<GithubUser> => {
const response = await ctx.api[`POST /users/:username`]({
username: props.username,
}, { body: { filter: "filter" } });

const result = await response.json();

return result;
};

export default action;
70 changes: 70 additions & 0 deletions app-tags/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"imports": {
"$fresh/": "https://denopkg.com/denoland/[email protected]/",
"preact": "npm:[email protected]",
"preact-render-to-string": "npm:[email protected]",
"@preact/signals": "https://esm.sh/*@preact/[email protected]",
"@preact/signals-core": "https://esm.sh/@preact/[email protected]",
"std/": "https://deno.land/[email protected]/",
"partytown/": "https://deno.land/x/[email protected]/",
"deco-sites/std/": "https://denopkg.com/deco-sites/[email protected]/",
"deco/": "https://denopkg.com/deco-cx/[email protected]/",
"apps/": "https://denopkg.com/deco-cx/[email protected]/",
"@deco/deco": "jsr:@deco/[email protected]",
"@std/assert": "jsr:@std/assert@^1.0.2",
"@std/async": "jsr:@std/async@^0.224.1",
"@std/crypto": "jsr:@std/[email protected]",
"@std/datetime": "jsr:@std/datetime@^0.224.0",
"@std/encoding": "jsr:@std/encoding@^1.0.0-rc.1",
"@std/flags": "jsr:@std/flags@^0.224.0",
"@std/fmt": "jsr:@std/fmt@^0.225.3",
"@std/fs": "jsr:@std/fs@^0.229.1",
"@std/http": "jsr:@std/http@^1.0.0",
"@std/io": "jsr:@std/io@^0.224.4",
"@std/log": "jsr:@std/log@^0.224.5",
"@std/media-types": "jsr:@std/media-types@^1.0.0-rc.1",
"@std/path": "jsr:@std/path@^0.225.2",
"@std/semver": "jsr:@std/semver@^0.224.3",
"@std/streams": "jsr:@std/streams@^1.0.0",
"@std/testing": "jsr:@std/testing@^1.0.0",
"@cliffy/prompt": "jsr:@cliffy/prompt@^1.0.0-rc.5",
"@core/asyncutil": "jsr:@core/asyncutil@^1.0.2",
"@deco/durable": "jsr:@deco/[email protected]",
"@deco/warp": "jsr:@deco/[email protected]",
"@hono/hono": "jsr:@hono/hono@^4.5.4",
"@std/cli": "jsr:@std/cli@^1.0.3",
"@zaubrik/djwt": "jsr:@zaubrik/djwt@^3.0.2",
"fast-json-patch": "npm:fast-json-patch@^3.1.1",
"simple-git": "npm:simple-git@^3.25.0",
"https://esm.sh/*[email protected]": "npm:[email protected]",
"@deco/dev": "jsr:@deco/[email protected]"
},
"lock": false,
"tasks": {
"check": "deno fmt && deno lint && deno check **/mod.ts",
"release": "deno eval 'import \"deco/scripts/release.ts\"'",
"start": "deno run -A --unstable-http --env https://deco.cx/run -- deno task dev",
"bundle": "deno run -A jsr:@deco/deco/scripts/bundle app-tags",
"link": "deno eval 'import \"deco/scripts/apps/link.ts\"'",
"unlink": "deno eval 'import \"deco/scripts/apps/unlink.ts\"'",
"serve": "deno eval 'import \"deco/scripts/apps/serve.ts\"'",
"watcher": "deno eval 'import \"deco/scripts/apps/watcher.ts\"'",
"update": "deno run -Ar https://deco.cx/update",
"new": "deno run -A ./scripts/new.ts",
"reload": "deno cache -r https://deco.cx/run",
"dev": "deno run -A --env --unstable-kv --unstable-hmr dev.ts"
},
"githooks": {
"pre-commit": "check"
},
"exclude": [
"static",
"README.md",
"**/README.md"
],
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "preact"
},
"version": "0.1.0"
}
37 changes: 37 additions & 0 deletions app-tags/loaders/collections/list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { AppContext } from "../../mod.ts";
import { CollectionList } from "../../utils/types.ts";
import { allowCorsFor } from "@deco/deco";
export interface Props {
term?: string;
}
export default async function loader(
{ term }: Props,
req: Request,
ctx: AppContext,
) {
Object.entries(allowCorsFor(req)).map(([name, value]) => {
ctx.response.headers.set(name, value);
});

const api = ctx.api;

const collectionResponse = term
? await api["GET /api/catalog_system/pvt/collection/search/:searchTerms"]({
searchTerms: term,
page: 1,
pageSize: 15,
})
: await api["GET /api/catalog_system/pvt/collection/search"]({
page: 1,
pageSize: 3000,
orderByAsc: false,
});
const collectionList = await collectionResponse.json();
const stringList = (collectionList as CollectionList)?.items?.map((
collection,
) => ({
value: `${collection.id}`,
label: `${collection.id} - ${collection.name}`,
}));
return stringList;
}
51 changes: 51 additions & 0 deletions app-tags/loaders/getCategoryTree.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { allowCorsFor } from "@deco/deco";
import { AppContext } from "../mod.ts";
import { Category, OrganizedCategory, PropsCategory } from "../utils/types.ts";
/**
* @title Tag Integration
* @description Category List
*/
const loader = async (
_props: PropsCategory,
req: Request,
ctx: AppContext,
): Promise<OrganizedCategory[] | null> => {

Object.entries(allowCorsFor(req)).map(([name, value]) => {
ctx.response.headers.set(name, value);
});

try {
// Fetch categories from VTEX API
const response = await fetch(`https://${ctx.account}.vtexcommercestable.com.br/api/catalog_system/pub/category/tree/1`);

if (!response.ok) {
throw new Error("Network response was not ok");
}
const categories: Category[] = await response.json();
const organizedCategories = organizeCategories(categories);

return organizedCategories;
} catch (error) {
console.error("Error:", error);
return null;
}
};

export default loader;

/**
* This function organizes categories into a flat list with `value` and `label`
*/
function organizeCategories(data: Category[]): OrganizedCategory[] {
const result: OrganizedCategory[] = [];

data.forEach((category) => {
result.push({ value: `${category.id}`, label: `${category.id} - ${category.name}` });
category.children.forEach((child) => {
result.push({ value: `${child.id}`, label: `${child.id} - ${child.name}` });
});
});

return result;
}
26 changes: 26 additions & 0 deletions app-tags/loaders/tags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { AppContext } from "../mod.ts";

/**
* @title This name will appear on the admin
*/
const loader = (
_props: unknown,
_req: Request,
ctx: AppContext,
) => {
const flagDiscountThirdFor = ctx.flagDiscountThirdFor;
const flagCustom = ctx.flagCustom;
const flagSpecial = ctx.flagSpecial;
const discount = ctx.discount;


const result = {
flagDiscountThirdFor: flagDiscountThirdFor,
flagCustom: flagCustom,
flagSpecial: flagSpecial,
discount: discount
};

return result;
};
export default loader;
29 changes: 29 additions & 0 deletions app-tags/manifest.gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// DO NOT EDIT. This file is generated by deco.
// This file SHOULD be checked into source version control.
// This file is automatically updated during development when running `dev.ts`.

import * as $$$$$$$$$0 from "./actions/myAction.ts";
import * as $$$0 from "./loaders/collections/list.ts";
import * as $$$1 from "./loaders/getCategoryTree.ts";
import * as $$$2 from "./loaders/tags.ts";
import * as $$$$$$0 from "./sections/tags.tsx";

const manifest = {
"loaders": {
"app-tags/loaders/collections/list.ts": $$$0,
"app-tags/loaders/getCategoryTree.ts": $$$1,
"app-tags/loaders/tags.ts": $$$2,
},
"sections": {
"app-tags/sections/tags.tsx": $$$$$$0,
},
"actions": {
"app-tags/actions/myAction.ts": $$$$$$$$$0,
},
"name": "app-tags",
"baseUrl": import.meta.url,
};

export type Manifest = typeof manifest;

export default manifest;
108 changes: 108 additions & 0 deletions app-tags/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import type { App, FnContext } from "@deco/deco";
import { fetchSafe } from "apps/utils/fetch.ts";
import { createHttpClient } from "apps/utils/http.ts";
import { PreviewContainer } from "apps/utils/preview.tsx";
import { Secret } from "apps/website/loaders/secret.ts";
import manifest, { Manifest } from "./manifest.gen.ts";
import { OpenAPI as VCS } from "./utils/openapi/vcs.openapi.gen.ts";
import { FlagDiscountThirdForProps, FlagSpecialProps } from "./utils/types.ts";
import { Flags } from "./utils/types.ts";

export type AppContext = FnContext<State, Manifest>;


export interface Props {
/**
* @title Account Name
* @description ex: lojaN1
*/
account: string;

/**
* @title X-VTEX-API-AppKey
* @description Unique identifier of the application key.
* @format string
*/
appKey: Secret;

/**
* @title X-VTEX-API-AppToken
* @description Secret token of the application key.
* @format string
*/

appToken: Secret

/**
* @title Flag Desconto na terceira compra
*/
flagDiscountThirdFor?: FlagDiscountThirdForProps[];

/**@title Flags Personalizada */
flagCustom?: Flags[];

/**@title Flags Especiais */
flagSpecial?: FlagSpecialProps[];

/**@title Desconto */
/** @description Flag de porcetagem de desconto % */
discount?: boolean;

}

// Here we define the state of the app
// You choose what to put in the state
export interface State extends Omit<Props, "token"> {
api: ReturnType<typeof createHttpClient<VCS>>;
}

/**
* @title App Template
* @description This is an template of an app to be used as a reference.
* @category Tools
* @logo https://
*/
export default function App(props: Props): App<Manifest, State> {
const { appKey, appToken, account: _account, flagCustom, flagDiscountThirdFor } = props;

// const stringAppToken = typeof appToken === "string" ? appToken : appToken?.get() ?? "";

// const stringAppKey = typeof appKey === "string" ? appKey : appKey?.get() ?? "";

console.log("chave da api", typeof appKey)

const api = createHttpClient<VCS>({
base: `https://${_account}.vtexcommercestable.com.br`,
fetcher: fetchSafe,
headers: new Headers({
"Accept": "application/json",
"Content-Type": "application/json",
"X-VTEX-API-AppKey": appKey?.get() ?? '',
"X-VTEX-API-AppToken": appToken?.get() ?? '',
}),
});

const tags = { flagCustom, flagDiscountThirdFor };
const state = { ...props, api, tags };

return {
state,
manifest,
};
}

// It is important to use the same name as the default export of the app
export const preview = () => {
return {
Component: PreviewContainer,
props: {
name: "App Tags",
owner: "Agência N1",
description: "This is an template of an app to be used as a reference.",
logo:
"https://ozksgdmyrqcxcwhnbepg.supabase.co/storage/v1/object/public/assets/1/0ac02239-61e6-4289-8a36-e78c0975bcc8",
images: [],
tabs: [],
},
};
};
20 changes: 20 additions & 0 deletions app-tags/sections/tags.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


// notice that using the same types from the loaders
// it will be easier to use the data from the loaders
// on deco.cx admin

interface Props {
title?: string
}

/**
* @title This name will appear on the admin
*/
export default function Section(props: Props) {
return (
<div>
<h1>{props.title}</h1>
</div>
);
}
Loading
Loading