Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 9x 9x 1x 1x 1x 2x 2x 1x 1x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 7x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 7x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 7x 1x 1x 1x 7x 7x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 10x 10x 1x 1x 1x 2x 2x 1x 1x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 12x 12x 12x 1x 1x 1x 2x 2x 1x 1x 2x | import * as v from 'valibot';
const ambeedProductListResponseSchema = v.object({
source: v.number(),
code: v.number(),
lang: v.string(),
value: v.record(v.string(), v.unknown()),
time: v.string(),
});
/**
* Type guard to validate if a response matches the Ambeed product list API response structure.
* Checks for the presence and correct types of source, code, lang, value, and time fields.
*
* @category Typeguards
* @param data - The response data to validate
* @returns Type predicate indicating if the data is a valid AmbeedProductListResponse
* @example
* ```typescript
* const response = await fetch("https://www.ambeed.com/api/search");
* const data = await response.json();
* if (isAmbeedProductListResponse(data)) {
* console.log("Valid response, language:", data.lang);
* console.log("Response code:", data.code);
* }
* ```
* @source
*/
export function isAmbeedProductListResponse(data: unknown): data is AmbeedProductListResponse {
return v.safeParse(ambeedProductListResponseSchema, data).success;
}
/**
* Type assertion to ensure the given data is a valid AmbeedProductListResponse.
* Throws an error if the data does not match the expected structure.
*
* @category Typeguards
* @param data - The response data to assert
* @throws Error if the data is not a valid AmbeedProductListResponse
* @example
* ```typescript
* try {
* assertIsAmbeedProductListResponse(data);
* // data is now typed as AmbeedProductListResponse
* console.log(data.value);
* } catch (error) {
* console.error("Invalid Ambeed response:", error.message);
* }
* ```
* @source
*/
export function assertIsAmbeedProductListResponse(
data: unknown,
): asserts data is AmbeedProductListResponse {
if (!isAmbeedProductListResponse(data)) {
throw new Error('assertIsAmbeedProductListResponse failed');
}
}
const ambeedProductListResponseValueSchema = v.object({
total: v.number(),
pagenum: v.number(),
pageindex: v.number(),
pagesize: v.number(),
result: v.custom<object>((val) => typeof val === 'object' && val !== null),
menu_res: v.custom<object>((val) => typeof val === 'object' && val !== null),
});
/**
* Type guard to validate if data matches the Ambeed product list response value structure.
* Checks for pagination fields (total, pagenum, pageindex, pagesize) and result/menu data.
*
* @category Typeguards
* @param data - The value object to validate
* @returns Type predicate indicating if the data is a valid AmbeedProductListResponseValue
* @example
* ```typescript
* if (isAmbeedProductListResponseValue(response.value)) {
* console.log("Total results:", response.value.total);
* console.log("Page:", response.value.pageindex, "of", response.value.pagenum);
* }
* ```
* @source
*/
export function isAmbeedProductListResponseValue(
data: unknown,
): data is AmbeedProductListResponseValue {
return v.safeParse(ambeedProductListResponseValueSchema, data).success;
}
const ambeedProductListResponseResultItemSchema = v.object({
p_id: v.string(),
priceList: v.custom<object>((val) => typeof val === 'object' && val !== null),
p_proper_name3: v.string(),
p_am: v.string(),
s_url: v.string(),
p_name_en: v.string(),
p_cas: v.string(),
});
/**
* Type guard to validate if data matches the Ambeed product result item structure.
* Checks for required product fields including product ID, price list, name, molecular formula,
* URL, English name, and CAS number.
*
* @category Typeguards
* @param data - The result item to validate
* @returns Type predicate indicating if the data is a valid AmbeedProductListResponseResultItem
* @example
* ```typescript
* const item = resultList[0];
* if (isAmbeedProductListResponseResultItem(item)) {
* console.log("Product:", item.p_name_en);
* console.log("CAS:", item.p_cas);
* console.log("URL:", item.s_url);
* }
* ```
* @source
*/
export function isAmbeedProductListResponseResultItem(
data: unknown,
): data is AmbeedProductListResponseResultItem {
return v.safeParse(ambeedProductListResponseResultItemSchema, data).success;
}
const ambeedProductListResponsePriceListSchema = v.object({
pr_am: v.string(),
pr_usd: v.string(),
pr_id: v.number(),
discount_usd: v.string(),
pr_size: v.string(),
vip_usd: v.string(),
pr_rate: v.number(),
});
/**
* Type guard to validate if data matches the Ambeed price list item structure.
* Checks for required pricing fields including amount, USD price, discount, size,
* VIP price, and rate.
*
* @category Typeguards
* @param data - The price list item to validate
* @returns Type predicate indicating if the data is a valid AmbeedProductListResponsePriceList
* @example
* ```typescript
* const priceItem = product.priceList[0];
* if (isAmbeedProductListResponsePriceList(priceItem)) {
* console.log("Price (USD):", priceItem.pr_usd);
* console.log("Size:", priceItem.pr_size);
* console.log("Discount:", priceItem.discount_usd);
* }
* ```
* @source
*/
export function isAmbeedProductListResponsePriceList(
data: unknown,
): data is AmbeedProductListResponsePriceList {
return v.safeParse(ambeedProductListResponsePriceListSchema, data).success;
}
/**
* Type guard to validate if data matches the Ambeed search response product structure.
* Uses the same schema as the product list response for validation.
*
* @category Typeguards
* @param data - The search response product to validate
* @returns Type predicate indicating if the data is a valid AmbeedSearchResponseProduct
* @example
* ```typescript
* const product = searchResults[0];
* if (isAmbeedSearchResponseProduct(product)) {
* console.log("Source:", product.source);
* console.log("Code:", product.code);
* }
* ```
* @source
*/
export function isAmbeedSearchResponseProduct(data: unknown): data is AmbeedSearchResponseProduct {
return v.safeParse(ambeedProductListResponseSchema, data).success;
}
const ambeedProductPriceResponseSchema = v.object({
source: v.number(),
code: v.number(),
lang: v.string(),
time: v.string(),
value: v.object({
proInfo: v.custom<object>((val) => typeof val === 'object' && val !== null),
}),
});
/**
* Type guard to validate if data matches the Ambeed product price API response structure.
* Checks the `AmbeedResponseBase` fields plus a `value.proInfo` object, which carries the
* shared product info every priced variant in the response is keyed against.
* @category Typeguards
* @param data - The response data to validate
* @returns Type predicate indicating if the data is a valid AmbeedProductPriceResponse
* @example
* ```typescript
* const response = await this.httpPostJson({ path: "/webapi/v1/product_price" });
* if (isAmbeedProductPriceResponse(response)) {
* console.log("Product:", response.value.proInfo.p_name_en);
* console.log("Lead time:", response.value.proInfo.p_leadtime);
* }
* ```
* @source
*/
export function isAmbeedProductPriceResponse(data: unknown): data is AmbeedProductPriceResponse {
return v.safeParse(ambeedProductPriceResponseSchema, data).success;
}
/**
* Type assertion to ensure the given data is a valid AmbeedProductPriceResponse.
* Throws an error if the data does not match the expected structure.
* @category Typeguards
* @param data - The response data to assert
* @throws Error if the data is not a valid AmbeedProductPriceResponse
* @example
* ```typescript
* assertIsAmbeedProductPriceResponse(response);
* // response is now typed as AmbeedProductPriceResponse
* console.log(response.value.proInfo.p_am);
* ```
* @source
*/
export function assertIsAmbeedProductPriceResponse(
data: unknown,
): asserts data is AmbeedProductPriceResponse {
if (!isAmbeedProductPriceResponse(data)) {
throw new Error('assertIsAmbeedProductPriceResponse failed');
}
}
const ambeedGetSearchProductAndRecommendedProductsByCASResponseSchema = v.object({
source: v.number(),
code: v.number(),
lang: v.string(),
time: v.string(),
value: v.object({
search_pro_dict: v.custom<object>((val) => typeof val === 'object' && val !== null),
r_pro_list: v.array(v.unknown()),
}),
});
/**
* Type guard to validate if data matches the Ambeed "get search product and recommended
* products by CAS" API response structure. Checks the `AmbeedResponseBase` fields plus a
* `value` object containing the CAS-matched `search_pro_dict` and the `r_pro_list` array
* of recommendations.
* @category Typeguards
* @param data - The response data to validate
* @returns Type predicate indicating if the data is a valid
* AmbeedGetSearchProductAndRecommendedProductsByCASResponse
* @example
* ```typescript
* if (isAmbeedGetSearchProductAndRecommendedProductsByCASResponse(response)) {
* console.log("Matched product:", response.value.search_pro_dict.p_name_en);
* console.log("Recommendations:", response.value.r_pro_list.length);
* }
* ```
* @source
*/
export function isAmbeedGetSearchProductAndRecommendedProductsByCASResponse(
data: unknown,
): data is AmbeedGetSearchProductAndRecommendedProductsByCASResponse {
return v.safeParse(ambeedGetSearchProductAndRecommendedProductsByCASResponseSchema, data).success;
}
/**
* Type assertion to ensure the given data is a valid
* AmbeedGetSearchProductAndRecommendedProductsByCASResponse. Throws an error if the data
* does not match the expected structure.
* @category Typeguards
* @param data - The response data to assert
* @throws Error if the data is not a valid
* AmbeedGetSearchProductAndRecommendedProductsByCASResponse
* @example
* ```typescript
* assertIsAmbeedGetSearchProductAndRecommendedProductsByCASResponse(response);
* // response is now typed as AmbeedGetSearchProductAndRecommendedProductsByCASResponse
* console.log(response.value.search_pro_dict.p_cas);
* ```
* @source
*/
export function assertIsAmbeedGetSearchProductAndRecommendedProductsByCASResponse(
data: unknown,
): asserts data is AmbeedGetSearchProductAndRecommendedProductsByCASResponse {
if (!isAmbeedGetSearchProductAndRecommendedProductsByCASResponse(data)) {
throw new Error('assertIsAmbeedGetSearchProductAndRecommendedProductsByCASResponse failed');
}
}
const ambeedProductStockResponseSchema = v.object({
source: v.number(),
code: v.number(),
lang: v.string(),
time: v.string(),
value: v.array(v.looseObject({ size: v.string() })),
});
/**
* Type guard to validate the `webapi/v1/product_stock` response shape — the
* `value` array of per-size stock rows (each with a `size`, plus per-warehouse
* quantities and an optional aggregate `has_stock` flag). An empty `value`
* array is valid (no stock data available).
*
* @category Typeguards
* @param data - The response data to validate
* @returns Type predicate indicating if the data is a valid AmbeedProductStockResponse
* @example
* ```typescript
* if (isAmbeedProductStockResponse(data)) {
* console.log(data.value[0].size, data.value[0].has_stock);
* }
* ```
* @source
*/
export function isAmbeedProductStockResponse(data: unknown): data is AmbeedProductStockResponse {
return v.safeParse(ambeedProductStockResponseSchema, data).success;
}
/**
* Type assertion that the given data is a valid AmbeedProductStockResponse.
* Throws if the data does not match the expected structure.
*
* @category Typeguards
* @param data - The response data to assert
* @throws Error if the data is not a valid AmbeedProductStockResponse
* @example
* ```typescript
* assertIsAmbeedProductStockResponse(response);
* console.log(response.value);
* ```
* @source
*/
export function assertIsAmbeedProductStockResponse(
data: unknown,
): asserts data is AmbeedProductStockResponse {
if (!isAmbeedProductStockResponse(data)) {
throw new Error('assertIsAmbeedProductStockResponse failed');
}
}
const ambeedGetPmsSdsByAmsResponseSchema = v.object({
value: v.object({
isokk: v.boolean(),
errmsg: v.string(),
// sds_list[<p_am>][<sdsType>] = { status, url }
sds_list: v.record(
v.string(),
v.record(v.string(), v.object({ status: v.boolean(), url: v.string() })),
),
}),
});
/**
* Type guard to validate the `webapi/v1/getPmsSdsByAms` response shape — the
* `value.sds_list` map of per-product (AM id) SDS documents keyed by SDS type.
*
* @category Typeguards
* @param data - The response data to validate
* @returns Type predicate indicating if the data is a valid AmbeedGetPmsSdsByAmsResponse
* @example
* ```typescript
* if (isAmbeedGetPmsSdsByAmsResponse(data)) {
* console.log(data.value.sds_list["A491321"]["am"].url);
* }
* ```
* @source
*/
export function isAmbeedGetPmsSdsByAmsResponse(
data: unknown,
): data is AmbeedGetPmsSdsByAmsResponse {
return v.safeParse(ambeedGetPmsSdsByAmsResponseSchema, data).success;
}
/**
* Type assertion that the given data is a valid AmbeedGetPmsSdsByAmsResponse.
* Throws if the data does not match the expected structure.
*
* @category Typeguards
* @param data - The response data to assert
* @throws Error if the data is not a valid AmbeedGetPmsSdsByAmsResponse
* @example
* ```typescript
* assertIsAmbeedGetPmsSdsByAmsResponse(response);
* console.log(response.value.sds_list);
* ```
* @source
*/
export function assertIsAmbeedGetPmsSdsByAmsResponse(
data: unknown,
): asserts data is AmbeedGetPmsSdsByAmsResponse {
if (!isAmbeedGetPmsSdsByAmsResponse(data)) {
throw new Error('assertIsAmbeedGetPmsSdsByAmsResponse failed');
}
}
|