@dyne/interfacer-client 0.2.8 → 0.3.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/dist/index.cjs CHANGED
@@ -281,6 +281,7 @@ __export(index_exports, {
281
281
  clearInstanceVariablesCache: () => clearInstanceVariablesCache,
282
282
  createConfig: () => createConfig,
283
283
  createMemoryStorage: () => createMemoryStorage,
284
+ deriveEndpointsFromProxy: () => deriveEndpointsFromProxy,
284
285
  derivedProductFilterTags: () => derivedProductFilterTags,
285
286
  extractUserTagValues: () => extractUserTagValues,
286
287
  formatImageSrc: () => formatImageSrc,
@@ -1265,7 +1266,9 @@ var GraphQLClient = class {
1265
1266
  console.warn("[interfacer-client] GraphQL signing failed:", err);
1266
1267
  }
1267
1268
  }
1268
- const res = await fetch(this.config.zenflowsUrl, {
1269
+ const url = this.config.zenflowsUrl;
1270
+ if (!url) throw new Error("zenflowsUrl not configured. Provide zenflowsUrl or proxyUrl in config.");
1271
+ const res = await fetch(url, {
1269
1272
  method: "POST",
1270
1273
  headers,
1271
1274
  body
@@ -1486,8 +1489,8 @@ async function getInstanceVariables(client) {
1486
1489
  if (!d) throw new Error("No instance variables returned.");
1487
1490
  cachedVars = {
1488
1491
  projectDesign: d.specs.specProjectDesign,
1489
- projectProduct: d.specs.specProjectProduct,
1490
- projectService: d.specs.specProjectService,
1492
+ projectProduct: d.specs.specProjectProduct ?? void 0,
1493
+ projectService: d.specs.specProjectService ?? void 0,
1491
1494
  dpp: d.specs.specDpp ?? void 0,
1492
1495
  machine: d.specs.specMachine ?? void 0,
1493
1496
  material: d.specs.specMaterial ?? void 0,
@@ -1521,13 +1524,13 @@ var ResourceClient = class {
1521
1524
  // ─── Helpers ───────────────────────────────────────────────────────
1522
1525
  specIdForType(vars, type) {
1523
1526
  switch (type) {
1524
- case "DESIGN" /* DESIGN */:
1527
+ case "Design" /* DESIGN */:
1525
1528
  return vars.projectDesign.id;
1526
- case "PRODUCT" /* PRODUCT */:
1527
- return vars.projectProduct.id;
1528
- case "SERVICE" /* SERVICE */:
1529
- return vars.projectService.id;
1530
- case "MACHINE" /* MACHINE */:
1529
+ case "Product" /* PRODUCT */:
1530
+ return vars.projectProduct?.id || this.config.specs?.product || "";
1531
+ case "Service" /* SERVICE */:
1532
+ return vars.projectService?.id || this.config.specs?.service || "";
1533
+ case "Machine" /* MACHINE */:
1531
1534
  return vars.machine?.id || this.config.specs?.machine || "";
1532
1535
  case "DPP" /* DPP */:
1533
1536
  return vars.dpp?.id || this.config.specs?.dpp || "";
@@ -1557,9 +1560,10 @@ var ResourceClient = class {
1557
1560
  async createProject(params) {
1558
1561
  const vars = await this.getInstanceVars();
1559
1562
  const specId = this.specIdForType(vars, params.projectType);
1560
- const processId = await this.createProcess(`creation of ${params.name} by owner`);
1561
- let locationId;
1562
- if (params.location) {
1563
+ if (!specId) throw new Error(`${params.projectType} spec ID not found in instance variables or config`);
1564
+ const processId = params.processId || await this.createProcess(`creation of ${params.name} by owner`);
1565
+ let locationId = params.locationId;
1566
+ if (!locationId && params.location) {
1563
1567
  const loc = await this.createLocation(params.location);
1564
1568
  locationId = loc.id;
1565
1569
  }
@@ -2292,8 +2296,39 @@ var InterfacerClient = class {
2292
2296
  init_hashing();
2293
2297
 
2294
2298
  // src/config/config.ts
2299
+ function deriveEndpointsFromProxy(proxyUrl) {
2300
+ const base = proxyUrl.replace(/\/$/, "");
2301
+ return {
2302
+ zenflowsUrl: `${base}/zenflows/api`,
2303
+ zenflowsFileUrl: `${base}/zenflows/api/file`,
2304
+ dppUrl: `${base}/interfacer-dpp`,
2305
+ inbox: {
2306
+ send: `${base}/inbox/send`,
2307
+ read: `${base}/inbox/read`,
2308
+ countUnread: `${base}/inbox/count-unread`,
2309
+ setRead: `${base}/inbox/set-read`
2310
+ },
2311
+ walletUrl: `${base}/wallet/token`,
2312
+ social: {
2313
+ personBase: `${base}/inbox/person`,
2314
+ economicResourceBase: `${base}/inbox/economicresource`
2315
+ },
2316
+ oshUrl: `${base}/osh`
2317
+ };
2318
+ }
2295
2319
  function createConfig(config) {
2296
- return config;
2320
+ if (!config.proxyUrl) return config;
2321
+ const derived = deriveEndpointsFromProxy(config.proxyUrl);
2322
+ return {
2323
+ ...config,
2324
+ zenflowsUrl: config.zenflowsUrl ?? derived.zenflowsUrl,
2325
+ zenflowsFileUrl: config.zenflowsFileUrl ?? derived.zenflowsFileUrl,
2326
+ dppUrl: config.dppUrl ?? derived.dppUrl,
2327
+ inbox: config.inbox ?? derived.inbox,
2328
+ walletUrl: config.walletUrl ?? derived.walletUrl,
2329
+ social: config.social ?? derived.social,
2330
+ oshUrl: config.oshUrl ?? derived.oshUrl
2331
+ };
2297
2332
  }
2298
2333
 
2299
2334
  // src/index.ts
@@ -2327,6 +2362,7 @@ init_sign();
2327
2362
  clearInstanceVariablesCache,
2328
2363
  createConfig,
2329
2364
  createMemoryStorage,
2365
+ deriveEndpointsFromProxy,
2330
2366
  derivedProductFilterTags,
2331
2367
  extractUserTagValues,
2332
2368
  formatImageSrc,