@deenruv/upsell-plugin 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.md +42 -0
- package/dist/plugin-server/api/upsell-admin.resolver.d.ts +16 -0
- package/dist/plugin-server/api/upsell-admin.resolver.js +58 -0
- package/dist/plugin-server/api/upsell-product.resolver.d.ts +7 -0
- package/dist/plugin-server/api/upsell-product.resolver.js +36 -0
- package/dist/plugin-server/constants.d.ts +1 -0
- package/dist/plugin-server/constants.js +1 -0
- package/dist/plugin-server/entities/upsell.entity.d.ts +8 -0
- package/dist/plugin-server/entities/upsell.entity.js +38 -0
- package/dist/plugin-server/extensions/upsell.extension.d.ts +3 -0
- package/dist/plugin-server/extensions/upsell.extension.js +26 -0
- package/dist/plugin-server/index.d.ts +8 -0
- package/dist/plugin-server/index.js +43 -0
- package/dist/plugin-server/services/upsell.service.d.ts +11 -0
- package/dist/plugin-server/services/upsell.service.js +76 -0
- package/dist/plugin-server/types.d.ts +1 -0
- package/dist/plugin-server/types.js +1 -0
- package/dist/plugin-server/zeus/const.d.ts +6 -0
- package/dist/plugin-server/zeus/const.js +4039 -0
- package/dist/plugin-server/zeus/index.d.ts +20455 -0
- package/dist/plugin-server/zeus/index.js +443 -0
- package/dist/plugin-ui/components/UpsellSelect.d.ts +2 -0
- package/dist/plugin-ui/components/UpsellSelect.js +99 -0
- package/dist/plugin-ui/graphql/mutations.d.ts +18 -0
- package/dist/plugin-ui/graphql/mutations.js +14 -0
- package/dist/plugin-ui/graphql/queries.d.ts +15 -0
- package/dist/plugin-ui/graphql/queries.js +11 -0
- package/dist/plugin-ui/graphql/scalars.d.ts +13 -0
- package/dist/plugin-ui/graphql/scalars.js +14 -0
- package/dist/plugin-ui/graphql/selectors.d.ts +12 -0
- package/dist/plugin-ui/graphql/selectors.js +8 -0
- package/dist/plugin-ui/index.d.ts +1 -0
- package/dist/plugin-ui/index.js +21 -0
- package/dist/plugin-ui/locales/en/index.d.ts +5 -0
- package/dist/plugin-ui/locales/en/index.js +2 -0
- package/dist/plugin-ui/locales/en/wfirma.json +4 -0
- package/dist/plugin-ui/locales/pl/index.d.ts +5 -0
- package/dist/plugin-ui/locales/pl/index.js +2 -0
- package/dist/plugin-ui/locales/pl/wfirma.json +4 -0
- package/dist/plugin-ui/pages/ExtrasPage.d.ts +2 -0
- package/dist/plugin-ui/pages/ExtrasPage.js +8 -0
- package/dist/plugin-ui/translation-ns.d.ts +1 -0
- package/dist/plugin-ui/translation-ns.js +1 -0
- package/dist/plugin-ui/tsconfig.json +18 -0
- package/dist/plugin-ui/zeus/const.d.ts +6 -0
- package/dist/plugin-ui/zeus/const.js +4039 -0
- package/dist/plugin-ui/zeus/index.d.ts +20455 -0
- package/dist/plugin-ui/zeus/index.js +459 -0
- package/dist/plugin-ui/zeus/typedDocumentNode.d.ts +3 -0
- package/dist/plugin-ui/zeus/typedDocumentNode.js +9 -0
- package/package.json +61 -0
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import { AllTypesProps, ReturnTypes, Ops } from './const.js';
|
|
3
|
+
export const HOST = "http://localhost:3000/admin-api";
|
|
4
|
+
export const HEADERS = {};
|
|
5
|
+
export const apiSubscription = (options) => (query) => {
|
|
6
|
+
try {
|
|
7
|
+
const queryString = options[0] + '?query=' + encodeURIComponent(query);
|
|
8
|
+
const wsString = queryString.replace('http', 'ws');
|
|
9
|
+
const host = (options.length > 1 && options[1]?.websocket?.[0]) || wsString;
|
|
10
|
+
const webSocketOptions = options[1]?.websocket || [host];
|
|
11
|
+
const ws = new WebSocket(...webSocketOptions);
|
|
12
|
+
return {
|
|
13
|
+
ws,
|
|
14
|
+
on: (e) => {
|
|
15
|
+
ws.onmessage = (event) => {
|
|
16
|
+
if (event.data) {
|
|
17
|
+
const parsed = JSON.parse(event.data);
|
|
18
|
+
const data = parsed.data;
|
|
19
|
+
return e(data);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
off: (e) => {
|
|
24
|
+
ws.onclose = e;
|
|
25
|
+
},
|
|
26
|
+
error: (e) => {
|
|
27
|
+
ws.onerror = e;
|
|
28
|
+
},
|
|
29
|
+
open: (e) => {
|
|
30
|
+
ws.onopen = e;
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
throw new Error('No websockets implemented');
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const handleFetchResponse = (response) => {
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
return new Promise((_, reject) => {
|
|
41
|
+
response
|
|
42
|
+
.text()
|
|
43
|
+
.then((text) => {
|
|
44
|
+
try {
|
|
45
|
+
reject(JSON.parse(text));
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
reject(text);
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
.catch(reject);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return response.json();
|
|
55
|
+
};
|
|
56
|
+
export const apiFetch = (options) => (query, variables = {}) => {
|
|
57
|
+
const fetchOptions = options[1] || {};
|
|
58
|
+
if (fetchOptions.method && fetchOptions.method === 'GET') {
|
|
59
|
+
return fetch(`${options[0]}?query=${encodeURIComponent(query)}`, fetchOptions)
|
|
60
|
+
.then(handleFetchResponse)
|
|
61
|
+
.then((response) => {
|
|
62
|
+
if (response.errors) {
|
|
63
|
+
throw new GraphQLError(response);
|
|
64
|
+
}
|
|
65
|
+
return response.data;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return fetch(`${options[0]}`, {
|
|
69
|
+
body: JSON.stringify({ query, variables }),
|
|
70
|
+
method: 'POST',
|
|
71
|
+
headers: {
|
|
72
|
+
'Content-Type': 'application/json',
|
|
73
|
+
},
|
|
74
|
+
...fetchOptions,
|
|
75
|
+
})
|
|
76
|
+
.then(handleFetchResponse)
|
|
77
|
+
.then((response) => {
|
|
78
|
+
if (response.errors) {
|
|
79
|
+
throw new GraphQLError(response);
|
|
80
|
+
}
|
|
81
|
+
return response.data;
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
export const InternalsBuildQuery = ({ ops, props, returns, options, scalars, }) => {
|
|
85
|
+
const ibb = (k, o, p = '', root = true, vars = []) => {
|
|
86
|
+
const keyForPath = purifyGraphQLKey(k);
|
|
87
|
+
const newPath = [p, keyForPath].join(SEPARATOR);
|
|
88
|
+
if (!o) {
|
|
89
|
+
return '';
|
|
90
|
+
}
|
|
91
|
+
if (typeof o === 'boolean' || typeof o === 'number') {
|
|
92
|
+
return k;
|
|
93
|
+
}
|
|
94
|
+
if (typeof o === 'string') {
|
|
95
|
+
return `${k} ${o}`;
|
|
96
|
+
}
|
|
97
|
+
if (Array.isArray(o)) {
|
|
98
|
+
const args = InternalArgsBuilt({
|
|
99
|
+
props,
|
|
100
|
+
returns,
|
|
101
|
+
ops,
|
|
102
|
+
scalars,
|
|
103
|
+
vars,
|
|
104
|
+
})(o[0], newPath);
|
|
105
|
+
return `${ibb(args ? `${k}(${args})` : k, o[1], p, false, vars)}`;
|
|
106
|
+
}
|
|
107
|
+
if (k === '__alias') {
|
|
108
|
+
return Object.entries(o)
|
|
109
|
+
.map(([alias, objectUnderAlias]) => {
|
|
110
|
+
if (typeof objectUnderAlias !== 'object' || Array.isArray(objectUnderAlias)) {
|
|
111
|
+
throw new Error('Invalid alias it should be __alias:{ YOUR_ALIAS_NAME: { OPERATION_NAME: { ...selectors }}}');
|
|
112
|
+
}
|
|
113
|
+
const operationName = Object.keys(objectUnderAlias)[0];
|
|
114
|
+
const operation = objectUnderAlias[operationName];
|
|
115
|
+
return ibb(`${alias}:${operationName}`, operation, p, false, vars);
|
|
116
|
+
})
|
|
117
|
+
.join('\n');
|
|
118
|
+
}
|
|
119
|
+
const hasOperationName = root && options?.operationName ? ' ' + options.operationName : '';
|
|
120
|
+
const keyForDirectives = o.__directives ?? '';
|
|
121
|
+
const query = `{${Object.entries(o)
|
|
122
|
+
.filter(([k]) => k !== '__directives')
|
|
123
|
+
.map((e) => ibb(...e, [p, `field<>${keyForPath}`].join(SEPARATOR), false, vars))
|
|
124
|
+
.join('\n')}}`;
|
|
125
|
+
if (!root) {
|
|
126
|
+
return `${k} ${keyForDirectives}${hasOperationName} ${query}`;
|
|
127
|
+
}
|
|
128
|
+
const varsString = vars.map((v) => `${v.name}: ${v.graphQLType}`).join(', ');
|
|
129
|
+
return `${k} ${keyForDirectives}${hasOperationName}${varsString ? `(${varsString})` : ''} ${query}`;
|
|
130
|
+
};
|
|
131
|
+
return ibb;
|
|
132
|
+
};
|
|
133
|
+
export const Thunder = (fn, thunderGraphQLOptions) => (operation, graphqlOptions) => (o, ops) => {
|
|
134
|
+
const options = {
|
|
135
|
+
...thunderGraphQLOptions,
|
|
136
|
+
...graphqlOptions,
|
|
137
|
+
};
|
|
138
|
+
return fn(Zeus(operation, o, {
|
|
139
|
+
operationOptions: ops,
|
|
140
|
+
scalars: options?.scalars,
|
|
141
|
+
}), ops?.variables).then((data) => {
|
|
142
|
+
if (options?.scalars) {
|
|
143
|
+
return decodeScalarsInResponse({
|
|
144
|
+
response: data,
|
|
145
|
+
initialOp: operation,
|
|
146
|
+
initialZeusQuery: o,
|
|
147
|
+
returns: ReturnTypes,
|
|
148
|
+
scalars: options.scalars,
|
|
149
|
+
ops: Ops,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return data;
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
export const Chain = (...options) => Thunder(apiFetch(options));
|
|
156
|
+
export const SubscriptionThunder = (fn, thunderGraphQLOptions) => (operation, graphqlOptions) => (o, ops) => {
|
|
157
|
+
const options = {
|
|
158
|
+
...thunderGraphQLOptions,
|
|
159
|
+
...graphqlOptions,
|
|
160
|
+
};
|
|
161
|
+
const returnedFunction = fn(Zeus(operation, o, {
|
|
162
|
+
operationOptions: ops,
|
|
163
|
+
scalars: options?.scalars,
|
|
164
|
+
}));
|
|
165
|
+
if (returnedFunction?.on && options?.scalars) {
|
|
166
|
+
const wrapped = returnedFunction.on;
|
|
167
|
+
returnedFunction.on = (fnToCall) => wrapped((data) => {
|
|
168
|
+
if (options?.scalars) {
|
|
169
|
+
return fnToCall(decodeScalarsInResponse({
|
|
170
|
+
response: data,
|
|
171
|
+
initialOp: operation,
|
|
172
|
+
initialZeusQuery: o,
|
|
173
|
+
returns: ReturnTypes,
|
|
174
|
+
scalars: options.scalars,
|
|
175
|
+
ops: Ops,
|
|
176
|
+
}));
|
|
177
|
+
}
|
|
178
|
+
return fnToCall(data);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
return returnedFunction;
|
|
182
|
+
};
|
|
183
|
+
export const Subscription = (...options) => SubscriptionThunder(apiSubscription(options));
|
|
184
|
+
export const Zeus = (operation, o, ops) => InternalsBuildQuery({
|
|
185
|
+
props: AllTypesProps,
|
|
186
|
+
returns: ReturnTypes,
|
|
187
|
+
ops: Ops,
|
|
188
|
+
options: ops?.operationOptions,
|
|
189
|
+
scalars: ops?.scalars,
|
|
190
|
+
})(operation, o);
|
|
191
|
+
export const ZeusSelect = () => ((t) => t);
|
|
192
|
+
export const Selector = (key) => key && ZeusSelect();
|
|
193
|
+
export const TypeFromSelector = (key) => key && ZeusSelect();
|
|
194
|
+
export const Gql = Chain(HOST, {
|
|
195
|
+
headers: {
|
|
196
|
+
'Content-Type': 'application/json',
|
|
197
|
+
...HEADERS,
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
export const ZeusScalars = ZeusSelect();
|
|
201
|
+
export const decodeScalarsInResponse = ({ response, scalars, returns, ops, initialZeusQuery, initialOp, }) => {
|
|
202
|
+
if (!scalars) {
|
|
203
|
+
return response;
|
|
204
|
+
}
|
|
205
|
+
const builder = PrepareScalarPaths({
|
|
206
|
+
ops,
|
|
207
|
+
returns,
|
|
208
|
+
});
|
|
209
|
+
const scalarPaths = builder(initialOp, ops[initialOp], initialZeusQuery);
|
|
210
|
+
if (scalarPaths) {
|
|
211
|
+
const r = traverseResponse({ scalarPaths, resolvers: scalars })(initialOp, response, [ops[initialOp]]);
|
|
212
|
+
return r;
|
|
213
|
+
}
|
|
214
|
+
return response;
|
|
215
|
+
};
|
|
216
|
+
export const traverseResponse = ({ resolvers, scalarPaths, }) => {
|
|
217
|
+
const ibb = (k, o, p = []) => {
|
|
218
|
+
if (Array.isArray(o)) {
|
|
219
|
+
return o.map((eachO) => ibb(k, eachO, p));
|
|
220
|
+
}
|
|
221
|
+
if (o == null) {
|
|
222
|
+
return o;
|
|
223
|
+
}
|
|
224
|
+
const scalarPathString = p.join(SEPARATOR);
|
|
225
|
+
const currentScalarString = scalarPaths[scalarPathString];
|
|
226
|
+
if (currentScalarString) {
|
|
227
|
+
const currentDecoder = resolvers[currentScalarString.split('.')[1]]?.decode;
|
|
228
|
+
if (currentDecoder) {
|
|
229
|
+
return currentDecoder(o);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (typeof o === 'boolean' || typeof o === 'number' || typeof o === 'string' || !o) {
|
|
233
|
+
return o;
|
|
234
|
+
}
|
|
235
|
+
const entries = Object.entries(o).map(([k, v]) => [k, ibb(k, v, [...p, purifyGraphQLKey(k)])]);
|
|
236
|
+
const objectFromEntries = entries.reduce((a, [k, v]) => {
|
|
237
|
+
a[k] = v;
|
|
238
|
+
return a;
|
|
239
|
+
}, {});
|
|
240
|
+
return objectFromEntries;
|
|
241
|
+
};
|
|
242
|
+
return ibb;
|
|
243
|
+
};
|
|
244
|
+
export const SEPARATOR = '|';
|
|
245
|
+
export class GraphQLError extends Error {
|
|
246
|
+
constructor(response) {
|
|
247
|
+
super('');
|
|
248
|
+
this.response = response;
|
|
249
|
+
console.error(response);
|
|
250
|
+
}
|
|
251
|
+
toString() {
|
|
252
|
+
return 'GraphQL Response Error';
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
const ExtractScalar = (mappedParts, returns) => {
|
|
256
|
+
if (mappedParts.length === 0) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const oKey = mappedParts[0];
|
|
260
|
+
const returnP1 = returns[oKey];
|
|
261
|
+
if (typeof returnP1 === 'object') {
|
|
262
|
+
const returnP2 = returnP1[mappedParts[1]];
|
|
263
|
+
if (returnP2) {
|
|
264
|
+
return ExtractScalar([returnP2, ...mappedParts.slice(2)], returns);
|
|
265
|
+
}
|
|
266
|
+
return undefined;
|
|
267
|
+
}
|
|
268
|
+
return returnP1;
|
|
269
|
+
};
|
|
270
|
+
export const PrepareScalarPaths = ({ ops, returns }) => {
|
|
271
|
+
const ibb = (k, originalKey, o, p = [], pOriginals = [], root = true) => {
|
|
272
|
+
if (!o) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
if (typeof o === 'boolean' || typeof o === 'number' || typeof o === 'string') {
|
|
276
|
+
const extractionArray = [...pOriginals, originalKey];
|
|
277
|
+
const isScalar = ExtractScalar(extractionArray, returns);
|
|
278
|
+
if (isScalar?.startsWith('scalar')) {
|
|
279
|
+
const partOfTree = {
|
|
280
|
+
[[...p, k].join(SEPARATOR)]: isScalar,
|
|
281
|
+
};
|
|
282
|
+
return partOfTree;
|
|
283
|
+
}
|
|
284
|
+
return {};
|
|
285
|
+
}
|
|
286
|
+
if (Array.isArray(o)) {
|
|
287
|
+
return ibb(k, k, o[1], p, pOriginals, false);
|
|
288
|
+
}
|
|
289
|
+
if (k === '__alias') {
|
|
290
|
+
return Object.entries(o)
|
|
291
|
+
.map(([alias, objectUnderAlias]) => {
|
|
292
|
+
if (typeof objectUnderAlias !== 'object' || Array.isArray(objectUnderAlias)) {
|
|
293
|
+
throw new Error('Invalid alias it should be __alias:{ YOUR_ALIAS_NAME: { OPERATION_NAME: { ...selectors }}}');
|
|
294
|
+
}
|
|
295
|
+
const operationName = Object.keys(objectUnderAlias)[0];
|
|
296
|
+
const operation = objectUnderAlias[operationName];
|
|
297
|
+
return ibb(alias, operationName, operation, p, pOriginals, false);
|
|
298
|
+
})
|
|
299
|
+
.reduce((a, b) => ({
|
|
300
|
+
...a,
|
|
301
|
+
...b,
|
|
302
|
+
}));
|
|
303
|
+
}
|
|
304
|
+
const keyName = root ? ops[k] : k;
|
|
305
|
+
return Object.entries(o)
|
|
306
|
+
.filter(([k]) => k !== '__directives')
|
|
307
|
+
.map(([k, v]) => {
|
|
308
|
+
// Inline fragments shouldn't be added to the path as they aren't a field
|
|
309
|
+
const isInlineFragment = originalKey.match(/^...\s*on/) != null;
|
|
310
|
+
return ibb(k, k, v, isInlineFragment ? p : [...p, purifyGraphQLKey(keyName || k)], isInlineFragment ? pOriginals : [...pOriginals, purifyGraphQLKey(originalKey)], false);
|
|
311
|
+
})
|
|
312
|
+
.reduce((a, b) => ({
|
|
313
|
+
...a,
|
|
314
|
+
...b,
|
|
315
|
+
}));
|
|
316
|
+
};
|
|
317
|
+
return ibb;
|
|
318
|
+
};
|
|
319
|
+
export const purifyGraphQLKey = (k) => k.replace(/\([^)]*\)/g, '').replace(/^[^:]*\:/g, '');
|
|
320
|
+
const mapPart = (p) => {
|
|
321
|
+
const [isArg, isField] = p.split('<>');
|
|
322
|
+
if (isField) {
|
|
323
|
+
return {
|
|
324
|
+
v: isField,
|
|
325
|
+
__type: 'field',
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
return {
|
|
329
|
+
v: isArg,
|
|
330
|
+
__type: 'arg',
|
|
331
|
+
};
|
|
332
|
+
};
|
|
333
|
+
export const ResolveFromPath = (props, returns, ops) => {
|
|
334
|
+
const ResolvePropsType = (mappedParts) => {
|
|
335
|
+
const oKey = ops[mappedParts[0].v];
|
|
336
|
+
const propsP1 = oKey ? props[oKey] : props[mappedParts[0].v];
|
|
337
|
+
if (propsP1 === 'enum' && mappedParts.length === 1) {
|
|
338
|
+
return 'enum';
|
|
339
|
+
}
|
|
340
|
+
if (typeof propsP1 === 'string' && propsP1.startsWith('scalar.') && mappedParts.length === 1) {
|
|
341
|
+
return propsP1;
|
|
342
|
+
}
|
|
343
|
+
if (typeof propsP1 === 'object') {
|
|
344
|
+
if (mappedParts.length < 2) {
|
|
345
|
+
return 'not';
|
|
346
|
+
}
|
|
347
|
+
const propsP2 = propsP1[mappedParts[1].v];
|
|
348
|
+
if (typeof propsP2 === 'string') {
|
|
349
|
+
return rpp(`${propsP2}${SEPARATOR}${mappedParts
|
|
350
|
+
.slice(2)
|
|
351
|
+
.map((mp) => mp.v)
|
|
352
|
+
.join(SEPARATOR)}`);
|
|
353
|
+
}
|
|
354
|
+
if (typeof propsP2 === 'object') {
|
|
355
|
+
if (mappedParts.length < 3) {
|
|
356
|
+
return 'not';
|
|
357
|
+
}
|
|
358
|
+
const propsP3 = propsP2[mappedParts[2].v];
|
|
359
|
+
if (propsP3 && mappedParts[2].__type === 'arg') {
|
|
360
|
+
return rpp(`${propsP3}${SEPARATOR}${mappedParts
|
|
361
|
+
.slice(3)
|
|
362
|
+
.map((mp) => mp.v)
|
|
363
|
+
.join(SEPARATOR)}`);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
const ResolveReturnType = (mappedParts) => {
|
|
369
|
+
if (mappedParts.length === 0) {
|
|
370
|
+
return 'not';
|
|
371
|
+
}
|
|
372
|
+
const oKey = ops[mappedParts[0].v];
|
|
373
|
+
const returnP1 = oKey ? returns[oKey] : returns[mappedParts[0].v];
|
|
374
|
+
if (typeof returnP1 === 'object') {
|
|
375
|
+
if (mappedParts.length < 2)
|
|
376
|
+
return 'not';
|
|
377
|
+
const returnP2 = returnP1[mappedParts[1].v];
|
|
378
|
+
if (returnP2) {
|
|
379
|
+
return rpp(`${returnP2}${SEPARATOR}${mappedParts
|
|
380
|
+
.slice(2)
|
|
381
|
+
.map((mp) => mp.v)
|
|
382
|
+
.join(SEPARATOR)}`);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
const rpp = (path) => {
|
|
387
|
+
const parts = path.split(SEPARATOR).filter((l) => l.length > 0);
|
|
388
|
+
const mappedParts = parts.map(mapPart);
|
|
389
|
+
const propsP1 = ResolvePropsType(mappedParts);
|
|
390
|
+
if (propsP1) {
|
|
391
|
+
return propsP1;
|
|
392
|
+
}
|
|
393
|
+
const returnP1 = ResolveReturnType(mappedParts);
|
|
394
|
+
if (returnP1) {
|
|
395
|
+
return returnP1;
|
|
396
|
+
}
|
|
397
|
+
return 'not';
|
|
398
|
+
};
|
|
399
|
+
return rpp;
|
|
400
|
+
};
|
|
401
|
+
export const InternalArgsBuilt = ({ props, ops, returns, scalars, vars, }) => {
|
|
402
|
+
const arb = (a, p = '', root = true) => {
|
|
403
|
+
if (typeof a === 'string') {
|
|
404
|
+
if (a.startsWith(START_VAR_NAME)) {
|
|
405
|
+
const [varName, graphQLType] = a.replace(START_VAR_NAME, '$').split(GRAPHQL_TYPE_SEPARATOR);
|
|
406
|
+
const v = vars.find((v) => v.name === varName);
|
|
407
|
+
if (!v) {
|
|
408
|
+
vars.push({
|
|
409
|
+
name: varName,
|
|
410
|
+
graphQLType,
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
if (v.graphQLType !== graphQLType) {
|
|
415
|
+
throw new Error(`Invalid variable exists with two different GraphQL Types, "${v.graphQLType}" and ${graphQLType}`);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return varName;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
const checkType = ResolveFromPath(props, returns, ops)(p);
|
|
422
|
+
if (checkType.startsWith('scalar.')) {
|
|
423
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
424
|
+
const [_, ...splittedScalar] = checkType.split('.');
|
|
425
|
+
const scalarKey = splittedScalar.join('.');
|
|
426
|
+
return scalars?.[scalarKey]?.encode?.(a) || JSON.stringify(a);
|
|
427
|
+
}
|
|
428
|
+
if (Array.isArray(a)) {
|
|
429
|
+
return `[${a.map((arr) => arb(arr, p, false)).join(', ')}]`;
|
|
430
|
+
}
|
|
431
|
+
if (typeof a === 'string') {
|
|
432
|
+
if (checkType === 'enum') {
|
|
433
|
+
return a;
|
|
434
|
+
}
|
|
435
|
+
return `${JSON.stringify(a)}`;
|
|
436
|
+
}
|
|
437
|
+
if (typeof a === 'object') {
|
|
438
|
+
if (a === null) {
|
|
439
|
+
return `null`;
|
|
440
|
+
}
|
|
441
|
+
const returnedObjectString = Object.entries(a)
|
|
442
|
+
.filter(([, v]) => typeof v !== 'undefined')
|
|
443
|
+
.map(([k, v]) => `${k}: ${arb(v, [p, k].join(SEPARATOR), false)}`)
|
|
444
|
+
.join(',\n');
|
|
445
|
+
if (!root) {
|
|
446
|
+
return `{${returnedObjectString}}`;
|
|
447
|
+
}
|
|
448
|
+
return returnedObjectString;
|
|
449
|
+
}
|
|
450
|
+
return `${a}`;
|
|
451
|
+
};
|
|
452
|
+
return arb;
|
|
453
|
+
};
|
|
454
|
+
export const resolverFor = (type, field, fn) => fn;
|
|
455
|
+
export const START_VAR_NAME = `$ZEUS_VAR`;
|
|
456
|
+
export const GRAPHQL_TYPE_SEPARATOR = `__$GRAPHQL__`;
|
|
457
|
+
export const $ = (name, graphqlType) => {
|
|
458
|
+
return (START_VAR_NAME + name + GRAPHQL_TYPE_SEPARATOR + graphqlType);
|
|
459
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
2
|
+
import { ValueTypes, GenericOperation, OperationOptions, GraphQLTypes, InputType, ScalarDefinition, ThunderGraphQLOptions, ExtractVariables } from './index.js';
|
|
3
|
+
export declare const typedGql: <O extends "query" | "mutation", SCLR extends ScalarDefinition, R extends keyof ValueTypes = GenericOperation<O>>(operation: O, graphqlOptions?: ThunderGraphQLOptions<SCLR> | undefined) => <Z extends ValueTypes[R]>(o: Z & { [P in keyof Z]: P extends keyof ValueTypes[R] ? Z[P] : never; }, ops?: OperationOptions) => TypedDocumentNode<InputType<GraphQLTypes[R], Z, SCLR>, ExtractVariables<Z>>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { gql } from 'graphql-tag';
|
|
2
|
+
import { Zeus, } from './index.js';
|
|
3
|
+
export const typedGql = (operation, graphqlOptions) => (o, ops) => {
|
|
4
|
+
const str = Zeus(operation, o, {
|
|
5
|
+
operationOptions: ops,
|
|
6
|
+
scalars: graphqlOptions?.scalars,
|
|
7
|
+
});
|
|
8
|
+
return gql(str);
|
|
9
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@deenruv/upsell-plugin",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/**/*"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
"./plugin-server": "./dist/plugin-server/index.js",
|
|
14
|
+
"./plugin-server/ui": "./dist/plugin-server/ui.js",
|
|
15
|
+
"./plugin-ui": "./dist/plugin-ui/index.js"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@aws-sdk/client-s3": "^3.685.0",
|
|
19
|
+
"@aws-sdk/s3-request-presigner": "^3.726.1",
|
|
20
|
+
"@nestjs/common": "~10.3.10",
|
|
21
|
+
"@nestjs/graphql": "~12.2.0",
|
|
22
|
+
"date-fns": "^4.1.0",
|
|
23
|
+
"graphql": "~16.9.0",
|
|
24
|
+
"graphql-tag": "^2.12.6",
|
|
25
|
+
"graphql-zeus": "^5.4.2",
|
|
26
|
+
"lucide-react": "^0.363.0",
|
|
27
|
+
"react": "^18.2.0",
|
|
28
|
+
"react-dom": "^18.2.0",
|
|
29
|
+
"react-router-dom": "^6.22.1",
|
|
30
|
+
"react-i18next": "^14.0.5",
|
|
31
|
+
"sonner": "^1.4.41",
|
|
32
|
+
"recharts": "^2.12.7",
|
|
33
|
+
"@deenruv/admin-types": "^1.0.0",
|
|
34
|
+
"@deenruv/react-ui-devkit": "^1.0.0",
|
|
35
|
+
"@deenruv/common": "^1.0.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@graphql-typed-document-node/core": "3.2.0",
|
|
39
|
+
"@types/express": "^4.17.21",
|
|
40
|
+
"@types/react": "^18.2.0",
|
|
41
|
+
"@types/react-dom": "^18.2.0",
|
|
42
|
+
"@types/stream-json": "^1.7.8",
|
|
43
|
+
"@types/xml2js": "^0.4.14",
|
|
44
|
+
"rimraf": "^5.0.10",
|
|
45
|
+
"tslib": "^2.6.2",
|
|
46
|
+
"typescript": "5.3.3",
|
|
47
|
+
"@deenruv/core": "^1.0.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"@deenruv/core": "^0.1.0"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "rimraf dist && tsc --build",
|
|
54
|
+
"watch": "concurrently -k -p \"[{name}]\" -n \"SERVER,UI\" -c \"yellow.bold,cyan.bold\" \"tsc --watch --project src/plugin-server/tsconfig.json\" \"tsc --watch --project src/plugin-ui/tsconfig.json\"",
|
|
55
|
+
"watch:ui": "tsc --watch --project src/plugin-ui/tsconfig.json",
|
|
56
|
+
"lint": "eslint ./src/**/*.ts",
|
|
57
|
+
"lint:fix": "eslint --fix ./src/**/*.ts",
|
|
58
|
+
"zeus": "zeus http://localhost:3000/admin-api ./src/plugin-server --es && zeus http://localhost:3000/admin-api ./src/plugin-ui --td --es",
|
|
59
|
+
"codegen": "graphql-codegen --config codegen.ts"
|
|
60
|
+
}
|
|
61
|
+
}
|