-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathconfig.ts
More file actions
224 lines (208 loc) · 6.98 KB
/
config.ts
File metadata and controls
224 lines (208 loc) · 6.98 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import packageInfo from "../package.json";
import { type SearchVariables } from "./hooks/makeSearch";
import { type ListSettings, ListViews, type Pagination } from "./types";
export const getAppDefaultUri = () => "/";
export const getAppMountUri = () => window?.__SALEOR_CONFIG__?.APP_MOUNT_URI || getAppDefaultUri();
export const getStaticUrl = () => {
const staticUrl = window?.__SALEOR_CONFIG__?.STATIC_URL;
// Treat empty, null, or undefined as unset and fall back to root
if (!staticUrl) {
return "/";
}
// Ensure the returned URL always ends with a trailing slash
return staticUrl.endsWith("/") ? staticUrl : `${staticUrl}/`;
};
/**
* Get the API URL.
* The same API URL is used regardless of schema version (eg 3.22 or 3.23).
* The schema version is controlled by the FF_USE_STAGING_SCHEMA feature flag.
* May be a relative path (e.g., '/graphql/'); use getAbsoluteApiUrl() when a fully qualified URL is required.
*/
export const getApiUrl = () => window.__SALEOR_CONFIG__.API_URL;
/**
* Resolves full API URL.
* If the config provides an absolute URL, it will be used directly.
* If the config is relative (e.g., /graphql/), it will be resolved against the Dashboard origin.
*/
export const getAbsoluteApiUrl = () => new URL(getApiUrl(), window.location.origin).href;
export const SW_INTERVAL = parseInt(process.env.SW_INTERVAL ?? "300", 10);
export const IS_CLOUD_INSTANCE = window.__SALEOR_CONFIG__.IS_CLOUD_INSTANCE === "true";
export const getSaleorCloudAppDomain = (): string | null =>
window?.__SALEOR_CONFIG__?.SALEOR_CLOUD_APP_DOMAIN || null;
export const getExtensionsConfig = () => ({
extensionsApiUri: window.__SALEOR_CONFIG__.EXTENSIONS_API_URL,
});
export const DEFAULT_INITIAL_SEARCH_DATA: SearchVariables = {
after: null,
first: 20,
query: "",
};
export const DEFAULT_INITIAL_PAGINATION_DATA: Pagination = {
after: undefined,
before: undefined,
};
export const PAGINATE_BY = 20;
export const VALUES_PAGINATE_BY = 10;
export type ProductListColumns =
| "name"
| "productType"
| "description"
| "availability"
| "price"
| "date"
| "created"
| "productCategory"
| "productCollections";
export interface AppListViewSettings {
[ListViews.APPS_LIST]: ListSettings;
[ListViews.ATTRIBUTE_VALUE_LIST]: ListSettings;
[ListViews.ATTRIBUTE_LIST]: ListSettings;
[ListViews.CATEGORY_LIST]: ListSettings;
[ListViews.COLLECTION_LIST]: ListSettings;
[ListViews.CUSTOMER_LIST]: ListSettings;
[ListViews.DRAFT_LIST]: ListSettings;
[ListViews.NAVIGATION_LIST]: ListSettings;
[ListViews.ORDER_LIST]: ListSettings;
[ListViews.PAGES_LIST]: ListSettings;
[ListViews.PLUGINS_LIST]: ListSettings;
[ListViews.PRODUCT_LIST]: ListSettings<ProductListColumns>;
[ListViews.SALES_LIST]: ListSettings;
[ListViews.DISCOUNTS_LIST]: ListSettings;
[ListViews.SHIPPING_METHODS_LIST]: ListSettings;
[ListViews.STAFF_MEMBERS_LIST]: ListSettings;
[ListViews.PERMISSION_GROUP_LIST]: ListSettings;
[ListViews.VOUCHER_LIST]: ListSettings;
[ListViews.WAREHOUSE_LIST]: ListSettings;
[ListViews.WEBHOOK_LIST]: ListSettings;
[ListViews.TRANSLATION_ATTRIBUTE_VALUE_LIST]: ListSettings;
[ListViews.GIFT_CARD_LIST]: ListSettings;
[ListViews.ORDER_DETAILS_LIST]: ListSettings;
[ListViews.ORDER_DRAFT_DETAILS_LIST]: ListSettings;
[ListViews.PRODUCT_DETAILS]: ListSettings;
[ListViews.VOUCHER_CODES]: ListSettings;
[ListViews.ORDER_REFUNDS]: ListSettings;
[ListViews.ORDER_TRANSACTION_REFUNDS]: ListSettings;
}
// TODO: replace with
// type AppListViewSettings = Record<ListViews, ListSettings>;
export const defaultListSettings: AppListViewSettings = {
[ListViews.APPS_LIST]: {
rowNumber: 100,
},
[ListViews.ATTRIBUTE_VALUE_LIST]: {
rowNumber: 10,
},
[ListViews.ATTRIBUTE_LIST]: {
rowNumber: 10,
columns: ["slug", "name", "visible", "searchable", "use-in-faceted-search"],
},
[ListViews.CATEGORY_LIST]: {
rowNumber: PAGINATE_BY,
columns: ["name", "products", "subcategories"],
},
[ListViews.COLLECTION_LIST]: {
rowNumber: PAGINATE_BY,
columns: ["name", "productCount", "availability"],
},
[ListViews.CUSTOMER_LIST]: {
rowNumber: PAGINATE_BY,
columns: ["name", "email", "orders"],
},
[ListViews.DRAFT_LIST]: {
rowNumber: PAGINATE_BY,
columns: ["number", "date", "customer", "total", "channel"],
},
[ListViews.NAVIGATION_LIST]: {
rowNumber: PAGINATE_BY,
},
[ListViews.ORDER_LIST]: {
rowNumber: PAGINATE_BY,
columns: ["number", "date", "customer", "payment", "status", "total", "channel"],
},
[ListViews.PAGES_LIST]: {
rowNumber: PAGINATE_BY,
columns: ["title", "slug", "visible", "contentType"],
},
[ListViews.PLUGINS_LIST]: {
rowNumber: PAGINATE_BY,
},
[ListViews.PRODUCT_LIST]: {
columns: ["name", "availability", "description", "price", "productType", "date", "created"],
rowNumber: PAGINATE_BY,
},
[ListViews.SALES_LIST]: {
rowNumber: PAGINATE_BY,
columns: ["name", "startDate", "endDate", "value"],
},
[ListViews.DISCOUNTS_LIST]: {
rowNumber: PAGINATE_BY,
columns: ["name", "status", "type", "startDate", "endDate"],
},
[ListViews.SHIPPING_METHODS_LIST]: {
columns: ["name", "countries"],
rowNumber: PAGINATE_BY,
},
[ListViews.STAFF_MEMBERS_LIST]: {
rowNumber: PAGINATE_BY,
columns: ["name", "email", "status"],
},
[ListViews.PERMISSION_GROUP_LIST]: {
rowNumber: PAGINATE_BY,
columns: ["name", "members"],
},
[ListViews.VOUCHER_LIST]: {
rowNumber: PAGINATE_BY,
columns: ["code", "min-spent", "start-date", "end-date", "value", "limit"],
},
[ListViews.WAREHOUSE_LIST]: {
rowNumber: PAGINATE_BY,
},
[ListViews.WEBHOOK_LIST]: {
rowNumber: PAGINATE_BY,
},
[ListViews.TRANSLATION_ATTRIBUTE_VALUE_LIST]: {
rowNumber: 10,
},
[ListViews.GIFT_CARD_LIST]: {
rowNumber: PAGINATE_BY,
columns: ["giftCardCode", "status", "tag", "product", "usedBy", "balance"],
},
[ListViews.ORDER_DETAILS_LIST]: {
rowNumber: PAGINATE_BY,
columns: ["product", "sku", "variantName", "quantity", "price", "total", "isGift", "metadata"],
},
[ListViews.ORDER_DRAFT_DETAILS_LIST]: {
rowNumber: PAGINATE_BY,
columns: [
"product",
"status",
"sku",
"variantName",
"quantity",
"price",
"total",
"isGift",
"metadata",
],
},
[ListViews.PRODUCT_DETAILS]: {
rowNumber: PAGINATE_BY,
columns: ["name", "sku"],
},
[ListViews.VOUCHER_CODES]: {
rowNumber: PAGINATE_BY,
},
[ListViews.ORDER_REFUNDS]: {
rowNumber: PAGINATE_BY,
columns: ["status", "amount", "reason", "date", "account"],
},
[ListViews.ORDER_TRANSACTION_REFUNDS]: {
rowNumber: PAGINATE_BY,
columns: ["product", "unitPrice", "qtyOrdered", "maxQty", "qtyToRefund", "reason"],
},
};
export const APP_VERSION = process.env.CUSTOM_VERSION || `v${packageInfo.version}`;
export const GTM_ID = process.env.GTM_ID;
export const DEFAULT_NOTIFICATION_SHOW_TIME = 3000;
export const ENABLED_SERVICE_NAME_HEADER =
(process.env.ENABLED_SERVICE_NAME_HEADER as string) === "true";