@ductape/sdk 0.1.120 → 0.1.123

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.
@@ -117,7 +117,16 @@ class ProductsBuilderService {
117
117
  return this.product.workspace_id;
118
118
  }
119
119
  fetchProductId() {
120
- return this.product._id;
120
+ return this.requireProductId('fetchProductId');
121
+ }
122
+ requireProductId(operation) {
123
+ var _a;
124
+ const productId = String(this.product_id || ((_a = this.product) === null || _a === void 0 ? void 0 : _a._id) || '').trim();
125
+ if (!productId) {
126
+ throw new Error(`Product must be initialized before ${operation}; no product_id is available`);
127
+ }
128
+ this.product_id = productId;
129
+ return productId;
121
130
  }
122
131
  async createHealthcheck(data) {
123
132
  try {
@@ -540,7 +549,11 @@ class ProductsBuilderService {
540
549
  async initializeProductByTag(tag) {
541
550
  try {
542
551
  if (this.product && this.product.tag === tag) {
543
- return;
552
+ const cachedId = String(this.product_id || this.product._id || '').trim();
553
+ if (cachedId) {
554
+ this.product_id = cachedId;
555
+ return;
556
+ }
544
557
  }
545
558
  this.brokerCache.clear();
546
559
  this.envCache.clear();
@@ -548,7 +561,8 @@ class ProductsBuilderService {
548
561
  if (!this.product) {
549
562
  throw new Error(`Product with tag "${tag}" not found or failed to fetch`);
550
563
  }
551
- this.product_id = this.product._id;
564
+ this.product_id = String(this.product._id || '').trim();
565
+ this.requireProductId(`initializeProductByTag("${tag}")`);
552
566
  }
553
567
  catch (e) {
554
568
  throw e;
@@ -5105,6 +5119,7 @@ class ProductsBuilderService {
5105
5119
  // ==================== WORKFLOW CRUD METHODS ====================
5106
5120
  async createFeature(data, throwErrorIfExists = false) {
5107
5121
  try {
5122
+ const productId = this.requireProductId(`createFeature("${data.tag || ''}")`);
5108
5123
  const existing = await this.fetchFeature(data.tag);
5109
5124
  if (!existing) {
5110
5125
  // Validate required fields
@@ -5121,7 +5136,7 @@ class ProductsBuilderService {
5121
5136
  }
5122
5137
  }
5123
5138
  try {
5124
- await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.FEATURE, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
5139
+ await this.productApi.updateProduct(productId, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.FEATURE, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
5125
5140
  }
5126
5141
  catch (createErr) {
5127
5142
  // The by-tag existence check above (fetchFeature) is known to false-negative
@@ -5199,7 +5214,8 @@ class ProductsBuilderService {
5199
5214
  }
5200
5215
  }
5201
5216
  async fetchFeatures() {
5202
- const components = await this.productApi.fetchProductComponents(this.product_id, 'feature', this.getUserAccess());
5217
+ const productId = this.requireProductId('fetchFeatures');
5218
+ const components = await this.productApi.fetchProductComponents(productId, 'feature', this.getUserAccess());
5203
5219
  if (Array.isArray(components) && components.length > 0) {
5204
5220
  return components;
5205
5221
  }
@@ -5208,7 +5224,7 @@ class ProductsBuilderService {
5208
5224
  // while older /components/:id/feature handlers can incorrectly return an
5209
5225
  // empty list. Always perform a fresh product read before concluding that a
5210
5226
  // product has no features.
5211
- const product = await this.productApi.fetchProduct(this.product_id, this.getUserAccess());
5227
+ const product = await this.productApi.fetchProduct(productId, this.getUserAccess());
5212
5228
  const rawProduct = product;
5213
5229
  const byTag = new Map();
5214
5230
  for (const feature of [
@@ -5222,7 +5238,8 @@ class ProductsBuilderService {
5222
5238
  return Array.from(byTag.values());
5223
5239
  }
5224
5240
  async fetchFeature(tag) {
5225
- const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'feature', tag, this.getUserAccess());
5241
+ const productId = this.requireProductId(`fetchFeature("${tag}")`);
5242
+ const component = await this.productApi.fetchProductComponentByTag(productId, 'feature', tag, this.getUserAccess());
5226
5243
  if (component)
5227
5244
  return component;
5228
5245
  // Keep tag lookup consistent with fetchFeatures()/Workbench when an older