@eldrajs/sdk 0.2.0 → 0.2.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/CHANGELOG.md CHANGED
@@ -9,6 +9,15 @@ platform repository.
9
9
 
10
10
  ## Unreleased
11
11
 
12
+ - The Vite plugin writes `.eldra/web-studio/` beside the nearest `package.json` instead of Vite's
13
+ root; on Nuxt 4 the root is `app/`, and the folder landed there. A relative `outDir` is resolved
14
+ the same way.
15
+ - A fetch the plugin skips — gateway down, unknown organisation id, wrong URL — is now a build
16
+ warning naming what was skipped and why; it was silent. `generateEldraFiles` returns what it
17
+ wrote and what it skipped.
18
+
19
+ ## 0.2.0 — 2026-09-16
20
+
12
21
  - **Breaking.** The SDK no longer ships response types. The Vite plugin — now `eldra()`, was
13
22
  `eldraCms()` — generates `contract.ts` from your gateway's `/api/public/openapi.json` next to the
14
23
  CMS types, and it augments the SDK's `EldraContract` so every method is typed against the gateway
package/dist/vite.d.ts CHANGED
@@ -20,8 +20,17 @@ export interface EldraVitePluginOptions {
20
20
  fetch?: typeof fetch;
21
21
  skipOnMissingConfig?: boolean;
22
22
  }
23
+ export interface EldraGenerationResult {
24
+ /** Absolute paths of the files written. */
25
+ written: string[];
26
+ /** What was not generated, and why; the previously generated file, if any, is left in place. */
27
+ skipped: Array<{
28
+ what: string;
29
+ reason: string;
30
+ }>;
31
+ }
23
32
  export declare function eldra(options?: EldraVitePluginOptions): Plugin;
24
- export declare function generateEldraFiles(root: string, options: EldraVitePluginOptions, mode?: string): Promise<void>;
33
+ export declare function generateEldraFiles(root: string, options: EldraVitePluginOptions, mode?: string): Promise<EldraGenerationResult>;
25
34
  export declare function createContractSource(document: unknown, options?: {
26
35
  sdkImport?: string;
27
36
  source?: URL | string;
package/dist/vite.js CHANGED
@@ -37,21 +37,30 @@ function eldra(options = {}) {
37
37
  async buildStart() {
38
38
  if (generated) return;
39
39
  generated = true;
40
- await generateEldraFiles(config?.root ?? process.cwd(), options, config?.mode);
40
+ const result = await generateEldraFiles(config?.root ?? process.cwd(), options, config?.mode);
41
+ for (const skip of result.skipped) this.warn(`${skip.what} not generated: ${skip.reason}`);
41
42
  }
42
43
  };
43
44
  }
44
45
  async function generateEldraFiles(root, options, mode = process.env.NODE_ENV ?? "development") {
45
- const env = resolvePluginEnv(root, mode, options);
46
+ const projectRoot = await findProjectRoot(root);
47
+ const env = resolvePluginEnv(projectRoot, mode, options);
46
48
  const apiBaseUrl = resolveRuntimeValue(options.apiBaseUrl) ?? readFirstEnvValue(env, apiBaseUrlEnvKeys) ?? "https://web.eldra.app/api";
47
49
  const orgId = resolveRuntimeValue(options.orgId) ?? readFirstEnvValue(env, orgIdEnvKeys);
48
50
  if (!orgId) {
49
- if (options.skipOnMissingConfig) return;
50
- throw new Error("Missing Eldra generation config. Set orgId or ELDRA_ORG_ID. Set apiBaseUrl only for staging, local, or test gateways.");
51
+ const reason = "no organisation id. Set orgId or ELDRA_ORG_ID; set apiBaseUrl only for staging, local, or test gateways.";
52
+ if (options.skipOnMissingConfig) return {
53
+ written: [],
54
+ skipped: [{
55
+ what: "Eldra types",
56
+ reason
57
+ }]
58
+ };
59
+ throw new Error(`Missing Eldra generation config: ${reason}`);
51
60
  }
52
61
  const moduleName = options.moduleName ?? defaultModuleName;
53
62
  const sdkImport = options.sdkImport ?? defaultSdkImport;
54
- const outDir = resolve(root, options.outDir ?? defaultOutDir);
63
+ const outDir = resolve(projectRoot, options.outDir ?? defaultOutDir);
55
64
  const typesFileName = options.typesFileName ?? defaultTypesFileName;
56
65
  const contractFileName = options.contractFileName ?? defaultContractFileName;
57
66
  const clientFileName = options.clientFileName ?? defaultClientFileName;
@@ -60,30 +69,40 @@ async function generateEldraFiles(root, options, mode = process.env.NODE_ENV ??
60
69
  fetch: options.fetch,
61
70
  headers: resolveRuntimeValue(options.headers)
62
71
  };
63
- const typesSource = await orSkip(() => fetchCmsTypes(apiBaseUrl, orgId, {
72
+ const result = {
73
+ written: [],
74
+ skipped: []
75
+ };
76
+ const typesSource = await attempt("CMS types", result, () => fetchCmsTypes(apiBaseUrl, orgId, {
64
77
  ...fetchOptions,
65
78
  maxDepth: options.maxDepth,
66
79
  moduleName,
67
80
  schemas: options.schemas
68
81
  }));
69
- const contractSource = options.contract === false ? void 0 : await orSkip(() => fetchContract(apiBaseUrl, orgId, {
82
+ const contractSource = options.contract === false ? void 0 : await attempt("Gateway contract", result, () => fetchContract(apiBaseUrl, orgId, {
70
83
  ...fetchOptions,
71
84
  sdkImport
72
85
  }));
73
- if (!typesSource && !contractSource) return;
86
+ if (!typesSource && !contractSource) return result;
74
87
  await mkdir(outDir, { recursive: true });
88
+ const write = async (fileName, source) => {
89
+ const path = resolve(outDir, fileName);
90
+ await writeGeneratedFile(path, source);
91
+ result.written.push(path);
92
+ };
75
93
  if (typesSource) {
76
- await writeGeneratedFile(resolve(outDir, typesFileName), typesSource);
77
- await writeGeneratedFile(resolve(outDir, clientFileName), createGeneratedClientSource({
94
+ await write(typesFileName, typesSource);
95
+ await write(clientFileName, createGeneratedClientSource({
78
96
  moduleName,
79
97
  sdkImport,
80
98
  typesImport: `./${stripTSExtension(typesFileName)}`
81
99
  }));
82
100
  }
83
- if (contractSource) await writeGeneratedFile(resolve(outDir, contractFileName), contractSource);
101
+ if (contractSource) await write(contractFileName, contractSource);
84
102
  const hasClient = typesSource !== void 0 || await exists(resolve(outDir, clientFileName));
85
103
  const hasContract = contractSource !== void 0 || await exists(resolve(outDir, contractFileName));
86
- await writeGeneratedFile(resolve(outDir, indexFileName), [hasClient ? `export * from './${stripTSExtension(clientFileName)}';` : void 0, hasContract ? `export * from './${stripTSExtension(contractFileName)}';` : void 0].filter(Boolean).join("\n") + "\n");
104
+ await write(indexFileName, [hasClient ? `export * from './${stripTSExtension(clientFileName)}';` : void 0, hasContract ? `export * from './${stripTSExtension(contractFileName)}';` : void 0].filter(Boolean).join("\n") + "\n");
105
+ return result;
87
106
  }
88
107
  async function fetchCmsTypes(apiBaseUrl, orgId, options) {
89
108
  const url = new URL(`${trimSlash(apiBaseUrl)}/cms/v1/typescript-definitions`);
@@ -132,13 +151,26 @@ async function fetchText(url, orgId, options) {
132
151
  if (!response.ok) throw new Error(`Failed to fetch ${url}: ${response.status} ${response.statusText}\n${body}`);
133
152
  return body;
134
153
  }
135
- async function orSkip(run) {
154
+ async function attempt(what, result, run) {
136
155
  try {
137
156
  return await run();
138
- } catch {
157
+ } catch (error) {
158
+ result.skipped.push({
159
+ what,
160
+ reason: error instanceof Error ? error.message : String(error)
161
+ });
139
162
  return;
140
163
  }
141
164
  }
165
+ async function findProjectRoot(start) {
166
+ let dir = resolve(start);
167
+ while (true) {
168
+ if (await exists(resolve(dir, "package.json"))) return dir;
169
+ const parent = dirname(dir);
170
+ if (parent === dir) return resolve(start);
171
+ dir = parent;
172
+ }
173
+ }
142
174
  function createGeneratedClientSource(options) {
143
175
  const prefix = pascalTypeName(options.moduleName) || defaultModuleName;
144
176
  return `import {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eldrajs/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Framework-free client for the Eldra Web Studio public storefront API: CMS, catalog, cart, checkout handoff, orders, inventory. Types generated from your gateway's OpenAPI document and CMS schemas at build time.",
5
5
  "keywords": [
6
6
  "cms",