@lessly/sdk-app 0.3.0 → 0.4.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/README.md +24 -14
- package/dist/client.gen-DH0z4Tfa.d.cts +1711 -0
- package/dist/client.gen-DH0z4Tfa.d.ts +1711 -0
- package/dist/deployment/index.cjs +531 -0
- package/dist/deployment/index.cjs.map +1 -0
- package/dist/deployment/index.d.cts +425 -0
- package/dist/deployment/index.d.ts +425 -0
- package/dist/deployment/index.js +425 -0
- package/dist/deployment/index.js.map +1 -0
- package/dist/index.cjs +1649 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1649 -0
- package/dist/index.js.map +1 -1
- package/dist/organization/index.d.cts +1 -1
- package/dist/organization/index.d.ts +1 -1
- package/dist/playground/index.d.cts +1 -1
- package/dist/playground/index.d.ts +1 -1
- package/docs/recipes/sdk-usage.md +24 -14
- package/package.json +8 -2
- package/src/gen/bindings.gen.ts +1649 -0
- package/src/gen/client.gen.ts +391 -0
- package/src/gen/deployment/index.ts +3 -0
- package/src/gen/deployment/queryOptions.gen.ts +681 -0
- package/src/gen/manifest.gen.ts +1 -1
- package/src/gen/types.gen.ts +838 -0
- package/dist/client.gen-DtgaSZYB.d.cts +0 -909
- package/dist/client.gen-DtgaSZYB.d.ts +0 -909
|
@@ -18,10 +18,14 @@ const sdk = createLesslyApp({
|
|
|
18
18
|
// getCsrfToken defaults to reading the `lessly_csrf` cookie; override for SSR/tests.
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
const
|
|
22
|
-
await sdk.
|
|
21
|
+
const connectors = await sdk.organization.connectors.list({ productId: 'prod_123' });
|
|
22
|
+
await sdk.organization.product.create({ name: 'Acme' });
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
+
> The exact namespaces you see depend on the live catalog — see
|
|
26
|
+
> [Namespaces and subpath imports](#namespaces-and-subpath-imports). The calls
|
|
27
|
+
> above use `organization`; substitute the namespace/resource you need.
|
|
28
|
+
|
|
25
29
|
`productId` is the active product — read it from your `./App` props or the
|
|
26
30
|
`X-Product-Id` header (see APP-005), never decoded from a token.
|
|
27
31
|
|
|
@@ -35,7 +39,7 @@ distinguish platform-defined failure reasons:
|
|
|
35
39
|
import { LesslyApiError } from '@lessly/sdk-app';
|
|
36
40
|
|
|
37
41
|
try {
|
|
38
|
-
await sdk.
|
|
42
|
+
await sdk.organization.product.create({ name: 'Acme' });
|
|
39
43
|
} catch (err) {
|
|
40
44
|
if (err instanceof LesslyApiError) {
|
|
41
45
|
if (err.status === 409) {
|
|
@@ -57,14 +61,14 @@ instance explicitly:
|
|
|
57
61
|
// React example — works the same with any @tanstack/*-query adapter.
|
|
58
62
|
import { useQuery, useMutation } from '@tanstack/react-query';
|
|
59
63
|
import {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
} from '@lessly/sdk-app/
|
|
63
|
-
|
|
64
|
-
function
|
|
65
|
-
const { data } = useQuery(
|
|
66
|
-
const create = useMutation(
|
|
67
|
-
// create.mutate({
|
|
64
|
+
organizationConnectorsListQueryOptions,
|
|
65
|
+
organizationProductCreateMutationOptions,
|
|
66
|
+
} from '@lessly/sdk-app/organization';
|
|
67
|
+
|
|
68
|
+
function Connectors() {
|
|
69
|
+
const { data } = useQuery(organizationConnectorsListQueryOptions(sdk, { productId: 'prod_123' }));
|
|
70
|
+
const create = useMutation(organizationProductCreateMutationOptions(sdk));
|
|
71
|
+
// create.mutate({ name: 'Acme' })
|
|
68
72
|
}
|
|
69
73
|
```
|
|
70
74
|
|
|
@@ -73,7 +77,7 @@ so they also work directly with `queryClient.ensureQueryData(...)` and friends
|
|
|
73
77
|
— useful for prefetching outside a component, e.g. in a route loader:
|
|
74
78
|
|
|
75
79
|
```ts
|
|
76
|
-
await queryClient.ensureQueryData(
|
|
80
|
+
await queryClient.ensureQueryData(organizationConnectorsListQueryOptions(sdk, { productId: 'prod_123' }));
|
|
77
81
|
```
|
|
78
82
|
|
|
79
83
|
Prefer these factories over hand-rolling calls against `sdk.<namespace>...`
|
|
@@ -83,12 +87,18 @@ it automatically when you run `npm i @lessly/sdk-app@latest`.
|
|
|
83
87
|
|
|
84
88
|
## Namespaces and subpath imports
|
|
85
89
|
|
|
86
|
-
The SDK is organized by namespace (
|
|
87
|
-
operations off `sdk.<namespace>.<resource>.<action>(...)`, and import that
|
|
90
|
+
The SDK is organized by namespace (currently `organization` and `playground`).
|
|
91
|
+
Call operations off `sdk.<namespace>.<resource>.<action>(...)`, and import that
|
|
88
92
|
namespace's option factories from the matching subpath,
|
|
89
93
|
`@lessly/sdk-app/<namespace>` — not the package root. This keeps each App's
|
|
90
94
|
bundle limited to the namespaces it actually uses.
|
|
91
95
|
|
|
96
|
+
The available namespaces track the live catalog and **grow as platform
|
|
97
|
+
extensions migrate to `@lessly/tools`** — a namespace appears here only once its
|
|
98
|
+
tools carry a REST binding. Run `npm i @lessly/sdk-app@latest` to pick up newly
|
|
99
|
+
migrated namespaces. To see exactly what a given version exposes, check its
|
|
100
|
+
subpaths in `package.json` `exports`, or the `manifest.gen.ts` namespace list.
|
|
101
|
+
|
|
92
102
|
## What not to do
|
|
93
103
|
|
|
94
104
|
- Don't `fetch` a platform host directly, and don't use any other HTTP client
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lessly/sdk-app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"engines": {
|
|
@@ -39,6 +39,11 @@
|
|
|
39
39
|
"import": "./dist/index.js",
|
|
40
40
|
"require": "./dist/index.cjs"
|
|
41
41
|
},
|
|
42
|
+
"./deployment": {
|
|
43
|
+
"types": "./dist/deployment/index.d.ts",
|
|
44
|
+
"import": "./dist/deployment/index.js",
|
|
45
|
+
"require": "./dist/deployment/index.cjs"
|
|
46
|
+
},
|
|
42
47
|
"./organization": {
|
|
43
48
|
"types": "./dist/organization/index.d.ts",
|
|
44
49
|
"import": "./dist/organization/index.js",
|
|
@@ -49,5 +54,6 @@
|
|
|
49
54
|
"import": "./dist/playground/index.js",
|
|
50
55
|
"require": "./dist/playground/index.cjs"
|
|
51
56
|
}
|
|
52
|
-
}
|
|
57
|
+
},
|
|
58
|
+
"sdkContentHash": "sha256:11f8d92935d26f553961ebfbafc4c032fbab2060ab5ad9c22b353899cff359a5"
|
|
53
59
|
}
|