@lessly/sdk-app 0.3.0 → 0.3.1

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 CHANGED
@@ -4,6 +4,8 @@ The Lessly SDK for App is a TypeScript SDK that provides runtime bindings and ty
4
4
 
5
5
  **Note:** The `src/gen` directory contains generated SDK code and should not be edited by hand. Generated files are produced by running `npm run generate` with an API catalog.
6
6
 
7
+ The committed `src/gen` is a **convenience snapshot** — it lets the repo type-check, test, and build offline. It is **not** the source of truth: canonical generation happens **at publish time**, when Cloud Build regenerates `src/gen` from the live catalog before publishing. The catalog is **mid-migration**, so the committed snapshot's namespaces (currently `organization` and `playground`) will **grow as platform extensions migrate to `@lessly/tools`** — a namespace only appears once its tools carry a REST binding (tools without one are excluded until migrated). Regenerate the snapshot with `npx tsx scripts/generate.ts <catalog.json> src/gen && npm run sync-exports` against the live catalog (`https://api.lessly.dev/catalog/tools`).
8
+
7
9
  ## Usage
8
10
 
9
11
  Create a client with `createLesslyApp`, then call operations through the Proxy namespace tree:
@@ -17,10 +19,13 @@ const sdk = createLesslyApp({
17
19
  // getCsrfToken defaults to reading the `lessly_csrf` cookie; override for SSR/tests.
18
20
  });
19
21
 
20
- const { domains } = await sdk.tracking.domains.list({ page: 1 });
21
- await sdk.tracking.domains.create({ host: 'links.example.com' });
22
+ const connectors = await sdk.organization.connectors.list({ productId: 'prod_123' });
23
+ await sdk.organization.product.create({ name: 'Acme' });
22
24
  ```
23
25
 
26
+ The available namespaces track the live catalog and grow as platform extensions migrate; check
27
+ `package.json` `exports` (or `src/gen/manifest.gen.ts`) for what a given version exposes.
28
+
24
29
  Errors are surfaced as a typed `LesslyApiError` (`status`, `code`, `body`).
25
30
 
26
31
  ### TanStack Query
@@ -34,14 +39,14 @@ explicitly:
34
39
  // React example — works the same with any @tanstack/*-query adapter.
35
40
  import { useQuery, useMutation } from '@tanstack/react-query';
36
41
  import {
37
- trackingDomainsListQueryOptions,
38
- trackingDomainsCreateMutationOptions,
39
- } from '@lessly/sdk-app/tracking';
40
-
41
- function Domains() {
42
- const { data } = useQuery(trackingDomainsListQueryOptions(sdk, { page: 1 }));
43
- const create = useMutation(trackingDomainsCreateMutationOptions(sdk));
44
- // create.mutate({ host: 'links.example.com' })
42
+ organizationConnectorsListQueryOptions,
43
+ organizationProductCreateMutationOptions,
44
+ } from '@lessly/sdk-app/organization';
45
+
46
+ function Connectors() {
47
+ const { data } = useQuery(organizationConnectorsListQueryOptions(sdk, { productId: 'prod_123' }));
48
+ const create = useMutation(organizationProductCreateMutationOptions(sdk));
49
+ // create.mutate({ name: 'Acme' })
45
50
  }
46
51
  ```
47
52
 
@@ -116,10 +121,15 @@ MUST publish with an explicit override:
116
121
  npm publish --registry https://registry.npmjs.org/
117
122
  ```
118
123
 
119
- Base-version resolution (the `npm view <pkg>@<channel> dist-tags` lookup inside the pipeline
120
- CLI) follows the same rule: it reads the registry from `package.json`'s `publishConfig.registry`
121
- first, falling back to the `.npmrc` `@lessly:registry` value if `publishConfig.registry` is
122
- absent. This requires no change to the CLI's `--channel`/`--catalog-url`/`--baseline` contract.
124
+ Base-version resolution (the `npm view` lookups inside the pipeline CLI — both the per-channel
125
+ version and the package-wide max-version probe) follows the same rule, and in **two** steps:
126
+ it reads the registry from `package.json`'s `publishConfig.registry` first (falling back to the
127
+ `.npmrc` `@lessly:registry` value if absent), **and** passes that registry as an explicit CLI
128
+ scope override (`--@lessly:registry=<registry>`) on every `npm view`. The `--registry` flag alone
129
+ is not enough: because the package is scoped `@lessly`, the `.npmrc` `@lessly:registry=<GAR>` entry
130
+ would otherwise outrank it and silently resolve the lookup against GAR — which is exactly how an
131
+ early run read GAR's `0.1.x` line instead of the empty npmjs registry and skipped the `0.2.0`
132
+ floor. This requires no change to the CLI's `--channel`/`--catalog-url`/`--baseline` contract.
123
133
 
124
134
  ### Snapshot shape
125
135
 
@@ -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 { domains } = await sdk.tracking.domains.list({ page: 1 });
22
- await sdk.tracking.domains.create({ host: 'links.example.com' });
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.tracking.domains.create({ host: 'links.example.com' });
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
- trackingDomainsListQueryOptions,
61
- trackingDomainsCreateMutationOptions,
62
- } from '@lessly/sdk-app/tracking';
63
-
64
- function Domains() {
65
- const { data } = useQuery(trackingDomainsListQueryOptions(sdk, { page: 1 }));
66
- const create = useMutation(trackingDomainsCreateMutationOptions(sdk));
67
- // create.mutate({ host: 'links.example.com' })
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(trackingDomainsListQueryOptions(sdk, { page: 1 }));
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 (`tracking`, `mail`, `playground`, ...). Call
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.0",
3
+ "version": "0.3.1",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "engines": {
@@ -49,5 +49,6 @@
49
49
  "import": "./dist/playground/index.js",
50
50
  "require": "./dist/playground/index.cjs"
51
51
  }
52
- }
52
+ },
53
+ "sdkContentHash": "sha256:c6888491b9e25a037a38993fa524e1a5b646053465b66a88c5f7dfe3ba69ce70"
53
54
  }