@chargebee/code-sample-generator 0.3.6 → 0.4.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/browser.js CHANGED
@@ -1,5 +1,5 @@
1
- import { s as getOperationIdsForVersion, q as getOperationIds, c as getOperation, g as generateFromSample } from "./generate-from-sample-DX6FoZAo.js";
2
- import { m, A, h, i, j, f, D, n, G, o, k, T, u, l } from "./generate-from-sample-DX6FoZAo.js";
1
+ import { t as getOperationIdsForVersion, r as getOperationIds, c as getOperation, g as generateFromSample } from "./generate-from-sample-DhbfCFUp.js";
2
+ import { n, A, i, j, k, h, D, o, G, q, l, T, u, m } from "./generate-from-sample-DhbfCFUp.js";
3
3
  function validateOperationId(id, version) {
4
4
  if (version) {
5
5
  const ops = getOperationIdsForVersion(version);
@@ -95,21 +95,21 @@ function createCodeGenerator(options) {
95
95
  };
96
96
  }
97
97
  export {
98
- m as AVAILABLE_LANGUAGES,
98
+ n as AVAILABLE_LANGUAGES,
99
99
  A as AVAILABLE_LANGUAGE_IDS,
100
- h as Carousel,
101
- i as CodeBlock,
102
- j as CodeSampleHeader,
103
- f as CodeSamples,
100
+ i as Carousel,
101
+ j as CodeBlock,
102
+ k as CodeSampleHeader,
103
+ h as CodeSamples,
104
104
  D as DEFAULT_LANGUAGE,
105
- n as DEFAULT_THEME,
105
+ o as DEFAULT_THEME,
106
106
  G as GoToApiExplorer,
107
- o as LANGUAGE_DISPLAY_NAMES,
108
- k as LanguageSwitcher,
107
+ q as LANGUAGE_DISPLAY_NAMES,
108
+ l as LanguageSwitcher,
109
109
  T as TryInApiExplorer,
110
110
  createCodeGenerator,
111
111
  u as useLanguageSelection,
112
- l as useSampleLoader,
112
+ m as useSampleLoader,
113
113
  validateOperationId
114
114
  };
115
115
  //# sourceMappingURL=browser.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ir-builder.d.ts","sourceRoot":"","sources":["../../src/core/ir-builder.ts"],"names":[],"mappings":"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D;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,GAAE,iBAAsB,GAC9B,eAAe,EAAE,CAWnB;AAqWD;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CACzB,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,CAAC,EAAE,iBAAiB,GAC1B,IAAI,CAKN;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CACrB,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAET"}
@@ -9633,7 +9633,7 @@ function CodeBlock({
9633
9633
  "div",
9634
9634
  {
9635
9635
  ref: containerRef,
9636
- className: `font-mono text-[13px] leading-relaxed transition-all duration-300 ease-in-out ${className} ${hideImportsProp ? "hide-code-imports" : ""}`,
9636
+ className: `font-mono text-[13px] leading-relaxed transition-all duration-300 ease-in-out ${isDark ? "dark" : ""} ${className} ${hideImportsProp ? "hide-code-imports" : ""}`,
9637
9637
  style: {
9638
9638
  backgroundColor: isDark ? "#24292e" : "#ffffff",
9639
9639
  // Always white background for light mode (matching API Explorer design)
@@ -121389,7 +121389,8 @@ function buildIR(operation, params, options = {}) {
121389
121389
  const apiKey = options.apiKey ?? DEFAULT_API_KEY;
121390
121390
  const apiVersion = options.apiVersion ?? DEFAULT_API_VERSION;
121391
121391
  const domainName = options.domainName ?? "chargebee.com";
121392
- const baseUrl = options.baseUrl ?? `https://${site}.${domainName}/api/${apiVersion}`;
121392
+ const subDomain = operation.subDomain;
121393
+ const baseUrl = options.baseUrl ?? (subDomain ? `https://${site}.${subDomain}.${domainName}/api/${apiVersion}` : `https://${site}.${domainName}/api/${apiVersion}`);
121393
121394
  const { resolvedPath, pathParams } = resolvePathParams(
121394
121395
  operation.http.path,
121395
121396
  params
@@ -121801,6 +121802,267 @@ function formatValue(value, schema) {
121801
121802
  return String(value);
121802
121803
  }
121803
121804
  }
121805
+ class ValidationError extends Error {
121806
+ constructor(operation, issues) {
121807
+ const summary = issues.map((i) => `${i.path}: ${i.message}`).join("; ");
121808
+ super(`Validation failed for ${operation}: ${summary}`);
121809
+ this.operation = operation;
121810
+ this.issues = issues;
121811
+ if (Error.captureStackTrace) {
121812
+ Error.captureStackTrace(this, ValidationError);
121813
+ }
121814
+ }
121815
+ name = "ValidationError";
121816
+ }
121817
+ function validateParams(schema, params, options = {}) {
121818
+ const opts = {
121819
+ allowUnknown: options.allowUnknown ?? true,
121820
+ // LENIENT by default
121821
+ validateEnums: options.validateEnums ?? true,
121822
+ validateTypes: options.validateTypes ?? true,
121823
+ validateRequired: options.validateRequired ?? true
121824
+ };
121825
+ const issues = [];
121826
+ validateObject(schema, params, "", issues, opts);
121827
+ return issues;
121828
+ }
121829
+ function validateObject(schema, obj, basePath, issues, opts) {
121830
+ if (opts.validateRequired) {
121831
+ for (const requiredField of schema.required ?? []) {
121832
+ const value = obj[requiredField];
121833
+ if (value === void 0 || value === null) {
121834
+ const path = joinPath(basePath, requiredField);
121835
+ issues.push({
121836
+ path,
121837
+ message: `Required field "${requiredField}" is missing`,
121838
+ code: "required"
121839
+ });
121840
+ }
121841
+ }
121842
+ }
121843
+ for (const [key2, value] of Object.entries(obj)) {
121844
+ if (value === void 0) continue;
121845
+ const fieldPath = joinPath(basePath, key2);
121846
+ let propSchema = schema.properties?.[key2];
121847
+ if (!propSchema && key2.includes("[")) {
121848
+ const rootKey = key2.slice(0, key2.indexOf("["));
121849
+ propSchema = schema.properties?.[rootKey];
121850
+ if (propSchema) {
121851
+ continue;
121852
+ }
121853
+ }
121854
+ if (!propSchema) {
121855
+ if (!opts.allowUnknown) {
121856
+ issues.push({
121857
+ path: fieldPath,
121858
+ message: `Unknown field "${key2}"`,
121859
+ code: "unknown_field"
121860
+ });
121861
+ }
121862
+ continue;
121863
+ }
121864
+ if (value === null) continue;
121865
+ if (opts.validateTypes) {
121866
+ const typeIssue = validateType(fieldPath, value, propSchema);
121867
+ if (typeIssue) {
121868
+ issues.push(typeIssue);
121869
+ continue;
121870
+ }
121871
+ }
121872
+ if (opts.validateEnums && propSchema.enum) {
121873
+ const stringValue = String(value).toLowerCase();
121874
+ const lowerEnums = propSchema.enum.map((e) => e.toLowerCase());
121875
+ if (!lowerEnums.includes(stringValue)) {
121876
+ issues.push({
121877
+ path: fieldPath,
121878
+ message: `Invalid value "${String(value)}". Valid values: ${propSchema.enum.join(", ")}`,
121879
+ code: "enum"
121880
+ });
121881
+ }
121882
+ }
121883
+ if (propSchema.type === "object" && propSchema.properties && typeof value === "object" && !Array.isArray(value)) {
121884
+ validateObject(
121885
+ propSchema,
121886
+ value,
121887
+ fieldPath,
121888
+ issues,
121889
+ opts
121890
+ );
121891
+ }
121892
+ if (propSchema.type === "array" && Array.isArray(value)) {
121893
+ validateArray(propSchema, value, fieldPath, issues, opts);
121894
+ }
121895
+ if (propSchema.isFilter && typeof value === "object" && !Array.isArray(value)) {
121896
+ validateFilterParam(
121897
+ propSchema,
121898
+ value,
121899
+ fieldPath,
121900
+ issues,
121901
+ opts
121902
+ );
121903
+ }
121904
+ }
121905
+ }
121906
+ function validateArray(schema, arr, basePath, issues, opts) {
121907
+ const itemSchema = schema.items;
121908
+ if (!itemSchema) return;
121909
+ arr.forEach((item, index) => {
121910
+ const itemPath = `${basePath}[${index}]`;
121911
+ if (item === null || item === void 0) return;
121912
+ if (opts.validateTypes) {
121913
+ const typeIssue = validateType(itemPath, item, itemSchema);
121914
+ if (typeIssue) {
121915
+ issues.push(typeIssue);
121916
+ return;
121917
+ }
121918
+ }
121919
+ if (itemSchema.type === "object" && itemSchema.properties && typeof item === "object" && !Array.isArray(item)) {
121920
+ validateObject(
121921
+ itemSchema,
121922
+ item,
121923
+ itemPath,
121924
+ issues,
121925
+ opts
121926
+ );
121927
+ }
121928
+ });
121929
+ }
121930
+ function validateFilterParam(schema, filterValue, basePath, issues, opts) {
121931
+ const validOperators = /* @__PURE__ */ new Set([
121932
+ "is",
121933
+ "is_not",
121934
+ "in",
121935
+ "not_in",
121936
+ "gt",
121937
+ "gte",
121938
+ "lt",
121939
+ "lte",
121940
+ "between",
121941
+ "on",
121942
+ "before",
121943
+ "after",
121944
+ "starts_with",
121945
+ "is_present",
121946
+ "is_not_present"
121947
+ ]);
121948
+ for (const [operator, value] of Object.entries(filterValue)) {
121949
+ if (!validOperators.has(operator) && !opts.allowUnknown) {
121950
+ issues.push({
121951
+ path: `${basePath}[${operator}]`,
121952
+ message: `Unknown filter operator "${operator}"`,
121953
+ code: "unknown_field"
121954
+ });
121955
+ continue;
121956
+ }
121957
+ if (opts.validateEnums && schema.enum && schema.filterType === "enum") {
121958
+ const values = Array.isArray(value) ? value : [value];
121959
+ for (const v of values) {
121960
+ if (!schema.enum.includes(String(v))) {
121961
+ issues.push({
121962
+ path: `${basePath}[${operator}]`,
121963
+ message: `Invalid enum value "${v}". Valid values: ${schema.enum.join(", ")}`,
121964
+ code: "enum"
121965
+ });
121966
+ }
121967
+ }
121968
+ }
121969
+ }
121970
+ }
121971
+ function validateType(path, value, schema) {
121972
+ const actualType = getValueType(value);
121973
+ switch (schema.type) {
121974
+ case "string":
121975
+ if (actualType !== "string") {
121976
+ return {
121977
+ path,
121978
+ message: `Expected string, got ${actualType}`,
121979
+ code: "type"
121980
+ };
121981
+ }
121982
+ break;
121983
+ case "integer":
121984
+ case "number": {
121985
+ const numericValue = actualType === "string" ? Number(value) : value;
121986
+ if (actualType !== "number" && (actualType !== "string" || Number.isNaN(numericValue))) {
121987
+ return {
121988
+ path,
121989
+ message: `Expected number, got ${actualType}`,
121990
+ code: "type"
121991
+ };
121992
+ }
121993
+ if (schema.type === "integer" && !Number.isInteger(numericValue)) {
121994
+ return {
121995
+ path,
121996
+ message: `Expected integer, got decimal number`,
121997
+ code: "type"
121998
+ };
121999
+ }
122000
+ break;
122001
+ }
122002
+ case "boolean":
122003
+ if (actualType !== "boolean") {
122004
+ return {
122005
+ path,
122006
+ message: `Expected boolean, got ${actualType}`,
122007
+ code: "type"
122008
+ };
122009
+ }
122010
+ break;
122011
+ case "array":
122012
+ if (actualType !== "array") {
122013
+ return {
122014
+ path,
122015
+ message: `Expected array, got ${actualType}`,
122016
+ code: "type"
122017
+ };
122018
+ }
122019
+ break;
122020
+ case "object":
122021
+ if (actualType === "string") {
122022
+ try {
122023
+ const parsed = JSON.parse(value);
122024
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
122025
+ return {
122026
+ path,
122027
+ message: `Expected object, got ${actualType} (JSON parsed to non-object)`,
122028
+ code: "type"
122029
+ };
122030
+ }
122031
+ } catch {
122032
+ return {
122033
+ path,
122034
+ message: `Expected object, got ${actualType} (not valid JSON)`,
122035
+ code: "type"
122036
+ };
122037
+ }
122038
+ } else if (actualType !== "object") {
122039
+ return {
122040
+ path,
122041
+ message: `Expected object, got ${actualType}`,
122042
+ code: "type"
122043
+ };
122044
+ }
122045
+ break;
122046
+ }
122047
+ return null;
122048
+ }
122049
+ function getValueType(value) {
122050
+ if (value === null) return "null";
122051
+ if (Array.isArray(value)) return "array";
122052
+ return typeof value;
122053
+ }
122054
+ function joinPath(base, field) {
122055
+ return base ? `${base}.${field}` : field;
122056
+ }
122057
+ function assertValid(operationId, schema, params, options) {
122058
+ const issues = validateParams(schema, params, options);
122059
+ if (issues.length > 0) {
122060
+ throw new ValidationError(operationId, issues);
122061
+ }
122062
+ }
122063
+ function isValid(schema, params, options) {
122064
+ return validateParams(schema, params, options).length === 0;
122065
+ }
121804
122066
  class CodeGenerationError extends Error {
121805
122067
  constructor(operation, language, cause, message) {
121806
122068
  super(
@@ -121847,6 +122109,9 @@ async function generateFromSample(sample, config, language) {
121847
122109
  try {
121848
122110
  return generateWithIR(sample, config, language);
121849
122111
  } catch (error) {
122112
+ if (error instanceof ValidationError) {
122113
+ throw error;
122114
+ }
121850
122115
  if (error instanceof CodeGenerationError) {
121851
122116
  throw error;
121852
122117
  }
@@ -121881,6 +122146,16 @@ function generateWithIR(sample, config, language) {
121881
122146
  const actualParams = params.map ? params.map : params;
121882
122147
  const pathParams = extractPathParamsFromUri(sample.uri, descriptor2.http.path);
121883
122148
  const mergedParams = { ...pathParams, ...actualParams };
122149
+ const shouldValidate = config.validate ?? true;
122150
+ if (shouldValidate) {
122151
+ const validationOpts = typeof shouldValidate === "object" ? shouldValidate : { allowUnknown: false };
122152
+ const bodyParams = stripPathParams(
122153
+ mergedParams,
122154
+ descriptor2.http.path,
122155
+ descriptor2.params
122156
+ );
122157
+ assertValid(operationId, descriptor2.params, bodyParams, validationOpts);
122158
+ }
121884
122159
  const ir = buildIR(descriptor2, mergedParams, {
121885
122160
  site: config.site || "{site}",
121886
122161
  apiKey: config.apiKey || "{site_api_key}",
@@ -121926,6 +122201,27 @@ function getCombinedVersion(apiVersion, pcVersion) {
121926
122201
  }
121927
122202
  return "v2-pcv2";
121928
122203
  }
122204
+ function stripPathParams(params, pathTemplate, bodySchema) {
122205
+ const pathParamKeys = /* @__PURE__ */ new Set();
122206
+ const placeholderRegex = /\{([^}]+)\}/g;
122207
+ let match = placeholderRegex.exec(pathTemplate);
122208
+ while (match !== null) {
122209
+ const name = match[1];
122210
+ pathParamKeys.add(name);
122211
+ pathParamKeys.add(name.replace(/-/g, "_"));
122212
+ if (name.endsWith("-id") || name.endsWith("_id")) {
122213
+ pathParamKeys.add("id");
122214
+ }
122215
+ match = placeholderRegex.exec(pathTemplate);
122216
+ }
122217
+ const result = {};
122218
+ for (const [key2, value] of Object.entries(params)) {
122219
+ if (bodySchema.properties?.[key2] !== void 0 || !pathParamKeys.has(key2)) {
122220
+ result[key2] = value;
122221
+ }
122222
+ }
122223
+ return result;
122224
+ }
121929
122225
  export {
121930
122226
  AVAILABLE_LANGUAGE_IDS as A,
121931
122227
  CodeGenerationError as C,
@@ -121934,28 +122230,32 @@ export {
121934
122230
  LanguageNotSupportedError as L,
121935
122231
  OperationNotFoundError as O,
121936
122232
  TryInApiExplorer as T,
122233
+ ValidationError as V,
121937
122234
  getGenerator as a,
121938
122235
  getSupportedLanguages as b,
121939
122236
  getOperation as c,
121940
- buildIR as d,
122237
+ assertValid as d,
121941
122238
  expandDescriptor as e,
121942
- CodeSamples as f,
122239
+ buildIR as f,
121943
122240
  generateFromSample as g,
121944
- Carousel as h,
121945
- CodeBlock as i,
121946
- CodeSampleHeader as j,
121947
- LanguageSwitcher as k,
121948
- useSampleLoader as l,
121949
- AVAILABLE_LANGUAGES as m,
121950
- DEFAULT_THEME as n,
121951
- LANGUAGE_DISPLAY_NAMES as o,
122241
+ CodeSamples as h,
122242
+ Carousel as i,
122243
+ CodeBlock as j,
122244
+ CodeSampleHeader as k,
122245
+ LanguageSwitcher as l,
122246
+ useSampleLoader as m,
122247
+ AVAILABLE_LANGUAGES as n,
122248
+ DEFAULT_THEME as o,
121952
122249
  pluralize as p,
121953
- getOperationIds as q,
121954
- getOperations as r,
121955
- getOperationIdsForVersion as s,
121956
- hasGenerator as t,
122250
+ LANGUAGE_DISPLAY_NAMES as q,
122251
+ getOperationIds as r,
122252
+ getOperations as s,
122253
+ getOperationIdsForVersion as t,
121957
122254
  useLanguageSelection as u,
121958
- compressDescriptor as v,
121959
- formatValue as w
122255
+ hasGenerator as v,
122256
+ compressDescriptor as w,
122257
+ formatValue as x,
122258
+ isValid as y,
122259
+ validateParams as z
121960
122260
  };
121961
- //# sourceMappingURL=generate-from-sample-DX6FoZAo.js.map
122261
+ //# sourceMappingURL=generate-from-sample-DhbfCFUp.js.map