-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathmod.ts
83 lines (83 loc) · 2.64 KB
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { createHttpClient } from "../utils/http.ts";
import manifest, { Manifest } from "./manifest.gen.ts";
import { API } from "./utils/client.ts";
import { Secret } from "../website/loaders/secret.ts";
import { LayerAPI } from "./utils/layer.ts";
import { Markdown } from "../decohub/components/Markdown.tsx";
import { PreviewContainer } from "../utils/preview.tsx";
import { type App, type AppContext as AC } from "@deco/deco";
export type AppContext = AC<ReturnType<typeof App>>;
/** @title LINX */
export interface State {
/**
* @title LINX Account name
* @default deco
*/
account: string;
/**
* @title Image CDN URL
* @description e.g.: https://{account}.cloudfront.net/
*/
cdn: string;
/**
* @title Linx integration token
* @description user:password of a Linx integration account encoded in base64
*/
integrationToken: Secret;
}
export const color = 0xFF6A3B;
/**
* IMPORTANT: This app needs the DECO_PROXY_DOMAIN=linx.decocache.com
* environment variable to work properly.
*/
/**
* @title Linx
* @description Loaders, actions and workflows for adding Linx Commerce Platform to your website.
* @category Ecommmerce
* @logo https://raw.githubusercontent.com/deco-cx/apps/main/linx/logo.png
*/
export default function App({ account, cdn, integrationToken }: State) {
const token = integrationToken.get();
const headers = new Headers({
"Accept": "application/json",
"User-Agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36",
"Authorization": `Basic ${token}`,
"x-external-service": "deco",
});
const api = createHttpClient<API>({
base: `https://${account}.core.dcg.com.br/`,
headers,
});
const layer = createHttpClient<LayerAPI>({
base: `https://${account}.layer.core.dcg.com.br/`,
headers,
});
const state = { cdn, api, layer, account };
const app: App<Manifest, typeof state> = { manifest, state };
return app;
}
export const preview = async () => {
const markdownContent = await Markdown(
new URL("./README.md", import.meta.url).href,
);
return {
Component: PreviewContainer,
props: {
name: "Linx",
owner: "deco.cx",
description:
"Loaders, actions and workflows for adding Linx Commerce Platform to your website.",
logo: "https://raw.githubusercontent.com/deco-cx/apps/main/linx/logo.png",
images: [
"https://deco-sites-assets.s3.sa-east-1.amazonaws.com/starting/6a71271e-6298-45c9-be8d-f226f7e5a4f5/linx.webp",
],
tabs: [
{
title: "About",
content: markdownContent(),
},
],
},
};
};