@weclapp/sdk 2.0.0-dev.26 → 2.0.0-dev.28
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/README.md +81 -48
- package/dist/cli.js +19 -5
- package/package.json +2 -4
package/README.md
CHANGED
|
@@ -205,6 +205,7 @@ The generator generates various utilities that can be used to integrate it in a
|
|
|
205
205
|
| `WEntityProperties` | Generalized type of `wEntityProperties`. | |
|
|
206
206
|
|
|
207
207
|
# Services and Raw in depth
|
|
208
|
+
|
|
208
209
|
As already described above, the api endpoints can be requested via services or the raw function. The advantage of wServices over the raw function is that all endpoints of the entities are available as functions and these functions are typed. This makes it easier to work with the data provided via the weclapp API.
|
|
209
210
|
|
|
210
211
|
A service of an entity has in general the following base function:
|
|
@@ -216,6 +217,7 @@ A service of an entity has in general the following base function:
|
|
|
216
217
|
update: // updates a entity
|
|
217
218
|
|
|
218
219
|
In addition there are some custom endpoint functions. The generated PartyService is shown below as an example:
|
|
220
|
+
|
|
219
221
|
```ts
|
|
220
222
|
interface PartyService {
|
|
221
223
|
some: PartyService_Some;
|
|
@@ -232,147 +234,178 @@ interface PartyService {
|
|
|
232
234
|
```
|
|
233
235
|
|
|
234
236
|
## Comparison
|
|
237
|
+
|
|
235
238
|
```ts
|
|
236
|
-
import { PartyType, setGlobalConfig, wServices } from
|
|
239
|
+
import { PartyType, setGlobalConfig, wServices } from "@weclapp/sdk";
|
|
237
240
|
|
|
238
241
|
setGlobalConfig({
|
|
239
|
-
domain:
|
|
240
|
-
secure: true
|
|
242
|
+
domain: "company.weclapp.com",
|
|
243
|
+
secure: true,
|
|
241
244
|
});
|
|
242
245
|
|
|
243
246
|
// to get the count of parties via service
|
|
244
|
-
const serviceN = await wServices[
|
|
247
|
+
const serviceN = await wServices["party"].count();
|
|
245
248
|
|
|
246
249
|
// to get the count of parties via raw
|
|
247
|
-
const rawN = await raw(undefined,
|
|
250
|
+
const rawN = await raw(undefined, "/party/count");
|
|
248
251
|
|
|
249
252
|
// to get all parties via service
|
|
250
|
-
const partiesService = await wServices[
|
|
253
|
+
const partiesService = await wServices["party"].some();
|
|
251
254
|
|
|
252
255
|
// to get all parties via raw
|
|
253
|
-
const partiesRaw = await raw(undefined,
|
|
256
|
+
const partiesRaw = await raw(undefined, "/party");
|
|
254
257
|
|
|
255
258
|
// to create a party via service
|
|
256
|
-
const contact = await wServices[
|
|
259
|
+
const contact = await wServices["party"].create({
|
|
260
|
+
partyType: PartyType.PERSON,
|
|
261
|
+
lastName: "Mueller",
|
|
262
|
+
}); // the returned object is already typed as Party
|
|
257
263
|
|
|
258
264
|
// to create a party via raw
|
|
259
|
-
const contactRaw = await await raw(undefined,
|
|
260
|
-
|
|
261
|
-
|
|
265
|
+
const contactRaw = await await raw(undefined, "/party", {
|
|
266
|
+
// the returned object has the type any.
|
|
267
|
+
method: "POST",
|
|
268
|
+
body: { partyType: PartyType.PERSON, lastName: "Mueller" },
|
|
262
269
|
});
|
|
263
270
|
|
|
264
271
|
// to delete a party via service
|
|
265
|
-
await wServices[
|
|
272
|
+
await wServices["party"].remove(contact.id);
|
|
266
273
|
|
|
267
274
|
// to delete a party via raw
|
|
268
|
-
if (contactRaw && typeof contactRaw.id ===
|
|
275
|
+
if (contactRaw && typeof contactRaw.id === "string") {
|
|
269
276
|
await raw(undefined, `/party/id/${contactRaw.id}`, {
|
|
270
|
-
method:
|
|
277
|
+
method: "DELETE",
|
|
271
278
|
});
|
|
272
279
|
}
|
|
273
280
|
```
|
|
274
281
|
|
|
275
282
|
## Service request arguments
|
|
283
|
+
|
|
276
284
|
### Filtering
|
|
285
|
+
|
|
277
286
|
With the some and count functions you can filter the requested data.
|
|
287
|
+
|
|
278
288
|
```ts
|
|
279
|
-
wServices[
|
|
289
|
+
wServices["article"].some({
|
|
280
290
|
filter: {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
291
|
+
name: { EQ: "toy 1" },
|
|
292
|
+
articleNumber: { EQ: "12345" },
|
|
293
|
+
},
|
|
284
294
|
});
|
|
285
295
|
```
|
|
286
|
-
|
|
296
|
+
|
|
297
|
+
The SDK makes an AND operator between the properties. So this equivalent to the follwing expression:
|
|
287
298
|
|
|
288
299
|
name EQ 'toy 1' AND articleNumber EQ '12345'.
|
|
289
300
|
|
|
290
301
|
If you want an OR operator you have to set an array in the or property:
|
|
302
|
+
|
|
291
303
|
```ts
|
|
292
|
-
wServices[
|
|
304
|
+
wServices["article"].some({
|
|
293
305
|
or: [
|
|
294
306
|
{
|
|
295
|
-
name: { EQ:
|
|
296
|
-
articleNumber: { EQ:
|
|
297
|
-
}
|
|
298
|
-
]
|
|
307
|
+
name: { EQ: "toy 1" },
|
|
308
|
+
articleNumber: { EQ: "12345" },
|
|
309
|
+
},
|
|
310
|
+
],
|
|
299
311
|
});
|
|
300
312
|
```
|
|
313
|
+
|
|
301
314
|
The above example is the equivalent of the expression
|
|
302
315
|
|
|
303
316
|
name EQ 'toy 1' OR articleNumber EQ '12345'.
|
|
304
317
|
|
|
305
318
|
To combine OR and AND clauses, you can also group OR expressions by adding several objects to the array:
|
|
319
|
+
|
|
306
320
|
```ts
|
|
307
|
-
wServices[
|
|
321
|
+
wServices["article"].some({
|
|
308
322
|
or: [
|
|
309
323
|
{
|
|
310
|
-
name: { EQ:
|
|
311
|
-
articleNumber: { EQ:
|
|
324
|
+
name: { EQ: "toy 1" },
|
|
325
|
+
articleNumber: { EQ: "12345" },
|
|
312
326
|
},
|
|
313
327
|
{
|
|
314
|
-
batchNumberRequired: { EQ: true}
|
|
315
|
-
}
|
|
316
|
-
]
|
|
317
|
-
})
|
|
328
|
+
batchNumberRequired: { EQ: true },
|
|
329
|
+
},
|
|
330
|
+
],
|
|
331
|
+
});
|
|
318
332
|
```
|
|
333
|
+
|
|
319
334
|
This is evaluated to:
|
|
320
|
-
|
|
335
|
+
(name EQ 'toy 1' OR articleNumber EQ '12345') AND batchNumberRequired EQ true
|
|
321
336
|
|
|
322
337
|
### Where filter
|
|
338
|
+
|
|
323
339
|
<strong>Warning: This is still a beta feature.</strong>
|
|
324
340
|
|
|
325
341
|
It is also possible to specify complex filter expressions that can combine multiple conditions and express relations between properties:
|
|
342
|
+
|
|
326
343
|
```ts
|
|
327
|
-
wServices[
|
|
344
|
+
wServices["article"].some({
|
|
328
345
|
where: {
|
|
329
346
|
AND: [
|
|
330
|
-
{
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
347
|
+
{
|
|
348
|
+
OR: [
|
|
349
|
+
{ name: { LIKE: "%test%", lower: true } },
|
|
350
|
+
{ articleNumber: { LIKE: "%345%" } },
|
|
351
|
+
],
|
|
352
|
+
},
|
|
353
|
+
{ batchNumberRequired: { EQ: true } },
|
|
354
|
+
],
|
|
355
|
+
},
|
|
334
356
|
});
|
|
335
357
|
```
|
|
358
|
+
|
|
336
359
|
"where" parameters are ANDed with other filter parameters.
|
|
337
360
|
|
|
338
361
|
### Sort
|
|
362
|
+
|
|
339
363
|
You can sort your requested data with an array properties.
|
|
364
|
+
|
|
340
365
|
```ts
|
|
341
|
-
wServices[
|
|
342
|
-
sort: [{ name:
|
|
366
|
+
wServices["article"].some({
|
|
367
|
+
sort: [{ name: "asc" }, { minimumPurchaseQuantity: "desc" }],
|
|
343
368
|
});
|
|
344
369
|
```
|
|
370
|
+
|
|
345
371
|
Sort by name (ascending) and then minimumPurchaseQuantity descending.
|
|
346
372
|
|
|
347
373
|
### Pagination
|
|
374
|
+
|
|
348
375
|
By default the API returns only the first 100 entities. You can increase the size of one response to the maximum of 1000. To get the next 1000 entities you have increase the page number.
|
|
376
|
+
|
|
349
377
|
```ts
|
|
350
|
-
wServices[
|
|
378
|
+
wServices["article"].some({
|
|
351
379
|
pagination: {
|
|
352
380
|
page: 2,
|
|
353
|
-
pageSize: 10
|
|
354
|
-
}
|
|
381
|
+
pageSize: 10,
|
|
382
|
+
},
|
|
355
383
|
});
|
|
356
384
|
```
|
|
385
|
+
|
|
357
386
|
This returns the first 10 articles of the second page.
|
|
358
387
|
|
|
359
388
|
### Select
|
|
389
|
+
|
|
360
390
|
With the select option you can fetch specific subset of properties:
|
|
391
|
+
|
|
361
392
|
```ts
|
|
362
|
-
wServices[
|
|
363
|
-
|
|
364
|
-
|
|
393
|
+
wServices["article"].some({
|
|
394
|
+
select: { articleNumber: true },
|
|
395
|
+
});
|
|
365
396
|
```
|
|
397
|
+
|
|
366
398
|
This only returns the articleNumber property of all articles.
|
|
367
399
|
|
|
368
400
|
# Enums
|
|
369
401
|
|
|
370
402
|
The generated enums are a good posibility to check if an entity is of a specific type. For example, you can get all articles of a certain article type:
|
|
403
|
+
|
|
371
404
|
```ts
|
|
372
|
-
wServices[
|
|
405
|
+
wServices["article"].some({
|
|
373
406
|
filter: {
|
|
374
|
-
|
|
375
|
-
}
|
|
407
|
+
articleType: { EQ: ArticleType.STORABLE },
|
|
408
|
+
},
|
|
376
409
|
});
|
|
377
410
|
```
|
|
378
411
|
|
package/dist/cli.js
CHANGED
|
@@ -65,7 +65,10 @@ const bundle = async (workingDirectory, target) => {
|
|
|
65
65
|
const bundles = {
|
|
66
66
|
[Target.BROWSER_PROMISES]: () => ({
|
|
67
67
|
input: src("index.ts"),
|
|
68
|
-
plugins: [
|
|
68
|
+
plugins: [
|
|
69
|
+
ts({ tsconfig, declarationDir: dist(), filterRoot: src() }),
|
|
70
|
+
terser(),
|
|
71
|
+
],
|
|
69
72
|
output: [
|
|
70
73
|
generateOutput({
|
|
71
74
|
file: dist("index.js"),
|
|
@@ -75,7 +78,10 @@ const bundle = async (workingDirectory, target) => {
|
|
|
75
78
|
}),
|
|
76
79
|
[Target.BROWSER_RX]: () => ({
|
|
77
80
|
input: src("index.ts"),
|
|
78
|
-
plugins: [
|
|
81
|
+
plugins: [
|
|
82
|
+
ts({ tsconfig, declarationDir: dist(), filterRoot: src() }),
|
|
83
|
+
terser(),
|
|
84
|
+
],
|
|
79
85
|
external: ["rxjs"],
|
|
80
86
|
output: [
|
|
81
87
|
generateOutput({
|
|
@@ -87,13 +93,19 @@ const bundle = async (workingDirectory, target) => {
|
|
|
87
93
|
}),
|
|
88
94
|
[Target.NODE_PROMISES]: () => ({
|
|
89
95
|
input: src("index.ts"),
|
|
90
|
-
plugins: [
|
|
96
|
+
plugins: [
|
|
97
|
+
ts({ tsconfig, declarationDir: dist(), filterRoot: src() }),
|
|
98
|
+
terser(),
|
|
99
|
+
],
|
|
91
100
|
external: ["node-fetch", "url"],
|
|
92
101
|
output: generateNodeOutput(),
|
|
93
102
|
}),
|
|
94
103
|
[Target.NODE_RX]: () => ({
|
|
95
104
|
input: src("index.ts"),
|
|
96
|
-
plugins: [
|
|
105
|
+
plugins: [
|
|
106
|
+
ts({ tsconfig, declarationDir: dist(), filterRoot: src() }),
|
|
107
|
+
terser(),
|
|
108
|
+
],
|
|
97
109
|
external: ["node-fetch", "url", "rxjs"],
|
|
98
110
|
output: generateNodeOutput(),
|
|
99
111
|
}),
|
|
@@ -1408,12 +1420,14 @@ void (async () => {
|
|
|
1408
1420
|
// Write swagger.json file
|
|
1409
1421
|
await writeFile(await workingDirPath("openapi.json"), JSON.stringify(doc, null, 2));
|
|
1410
1422
|
logger.infoLn(`Generate sdk (target: ${options.target})`);
|
|
1411
|
-
// Generate and write SDK
|
|
1423
|
+
// Generate and write SDK (index.ts)
|
|
1412
1424
|
const sdk = generate(doc, options);
|
|
1413
1425
|
await writeFile(await workingDirPath("src", "index.ts"), sdk.trim() + "\n");
|
|
1414
1426
|
// Bundle and write SDK
|
|
1415
1427
|
logger.infoLn("Bundle... (this may take some time)");
|
|
1416
1428
|
await bundle(workingDir, options.target);
|
|
1429
|
+
// Remove index.ts (only bundle is required)
|
|
1430
|
+
await rm(await workingDirPath("src"), { recursive: true, force: true });
|
|
1417
1431
|
if (useCache) {
|
|
1418
1432
|
// Copy SDK to cache
|
|
1419
1433
|
logger.successLn(`Caching SDK: (${cachedSdkDir})`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weclapp/sdk",
|
|
3
|
-
"version": "2.0.0-dev.
|
|
3
|
+
"version": "2.0.0-dev.28",
|
|
4
4
|
"description": "SDK generator based on a weclapp api swagger file",
|
|
5
5
|
"author": "weclapp",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -25,14 +25,12 @@
|
|
|
25
25
|
"npm": ">=10"
|
|
26
26
|
},
|
|
27
27
|
"types": "./sdk/dist/index.d.ts",
|
|
28
|
-
"main": "./sdk/dist/index.cjs",
|
|
29
28
|
"module": "./sdk/dist/index.js",
|
|
30
29
|
"type": "module",
|
|
31
30
|
"exports": {
|
|
32
31
|
".": {
|
|
33
32
|
"types": "./sdk/dist/index.d.ts",
|
|
34
|
-
"import": "./sdk/dist/index.js"
|
|
35
|
-
"require": "./sdk/dist/index.cjs"
|
|
33
|
+
"import": "./sdk/dist/index.js"
|
|
36
34
|
}
|
|
37
35
|
},
|
|
38
36
|
"scripts": {
|