@bagelink/sdk 1.4.69 → 1.4.73

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
@@ -126,6 +126,126 @@ function formatVarType({
126
126
  if (defaultStr) optionalStr = "";
127
127
  return `${varName}${optionalStr}: ${type}${defaultStr}`;
128
128
  }
129
+ const RESERVED_KEYWORDS = /* @__PURE__ */ new Set([
130
+ // JavaScript reserved words
131
+ "break",
132
+ "case",
133
+ "catch",
134
+ "class",
135
+ "const",
136
+ "continue",
137
+ "debugger",
138
+ "default",
139
+ "delete",
140
+ "do",
141
+ "else",
142
+ "enum",
143
+ "export",
144
+ "extends",
145
+ "false",
146
+ "finally",
147
+ "for",
148
+ "function",
149
+ "if",
150
+ "import",
151
+ "in",
152
+ "instanceof",
153
+ "new",
154
+ "null",
155
+ "return",
156
+ "super",
157
+ "switch",
158
+ "this",
159
+ "throw",
160
+ "true",
161
+ "try",
162
+ "typeof",
163
+ "var",
164
+ "void",
165
+ "while",
166
+ "with",
167
+ "yield",
168
+ // TypeScript reserved words
169
+ "abstract",
170
+ "any",
171
+ "as",
172
+ "asserts",
173
+ "bigint",
174
+ "boolean",
175
+ "constructor",
176
+ "declare",
177
+ "get",
178
+ "infer",
179
+ "intrinsic",
180
+ "is",
181
+ "keyof",
182
+ "module",
183
+ "namespace",
184
+ "never",
185
+ "number",
186
+ "object",
187
+ "package",
188
+ "private",
189
+ "protected",
190
+ "public",
191
+ "readonly",
192
+ "require",
193
+ "set",
194
+ "static",
195
+ "string",
196
+ "symbol",
197
+ "type",
198
+ "undefined",
199
+ "unique",
200
+ "unknown",
201
+ // Strict mode reserved words
202
+ "implements",
203
+ "interface",
204
+ "let",
205
+ "package",
206
+ "private",
207
+ "protected",
208
+ "public",
209
+ "static",
210
+ // Common global identifiers to avoid
211
+ "arguments",
212
+ "eval",
213
+ "Infinity",
214
+ "NaN",
215
+ "undefined",
216
+ "globalThis",
217
+ "window",
218
+ "document",
219
+ "console",
220
+ "Object",
221
+ "Array",
222
+ "Function",
223
+ "String",
224
+ "Number",
225
+ "Boolean",
226
+ "Date",
227
+ "RegExp",
228
+ "Error",
229
+ "Promise",
230
+ "Map",
231
+ "Set",
232
+ "WeakMap",
233
+ "WeakSet",
234
+ "Symbol",
235
+ "Proxy",
236
+ "Reflect"
237
+ ]);
238
+ function sanitizeVarName(varName) {
239
+ if (!varName) return varName;
240
+ if (RESERVED_KEYWORDS.has(varName.toLowerCase())) {
241
+ return `${varName}_`;
242
+ }
243
+ return varName;
244
+ }
245
+ function toCamelCaseSafe(str) {
246
+ const camelCased = toCamelCase(str);
247
+ return sanitizeVarName(camelCased);
248
+ }
129
249
  function cleanPath(path) {
130
250
  return path.split("/").filter((p) => p && !/\{|\}/.test(p)).join("/");
131
251
  }
@@ -216,7 +336,7 @@ function generateRequestBody(requestBody) {
216
336
  const bodySchema = dereference(jsonContent.schema);
217
337
  const requestBodyType = schemaToType(bodySchema);
218
338
  collectTypeForImportStatement(requestBodyType);
219
- const requestBodyPayload = toCamelCase(bodySchema.title) || toCamelCase(requestBodyType) || "requestBody";
339
+ const requestBodyPayload = toCamelCaseSafe(bodySchema.title) || toCamelCaseSafe(requestBodyType) || "requestBody";
220
340
  const requestBodyParam = formatVarType({
221
341
  varName: requestBodyPayload,
222
342
  schema: bodySchema,
@@ -243,7 +363,7 @@ function generateFunctionParameters(params, isFileUpload = false) {
243
363
  const paramType = schemaToType(pSchema);
244
364
  collectTypeForImportStatement(paramType);
245
365
  const paramName = param.name;
246
- const varName = toCamelCase(param.name);
366
+ const varName = toCamelCaseSafe(param.name);
247
367
  if (param.in === "path" || param.in === "query" || param.in === "header") {
248
368
  functionParams.push(
249
369
  formatVarType({
@@ -394,7 +514,7 @@ function generateFunctions(paths, baseUrl) {
394
514
  for (const [path, operation] of Object.entries(paths)) {
395
515
  const splitPath = path.split("/").filter((p) => p && !/\{|\}/.test(p));
396
516
  splitPath.reduce((acc, key, index, array) => {
397
- const objFuncKey = toCamelCase(key);
517
+ const objFuncKey = toCamelCaseSafe(key);
398
518
  if (!objFuncKey) return acc;
399
519
  const methods = Object.keys(operation);
400
520
  if (index === array.length - 1 && methods.length === 1 && allPathsClean.filter((p) => p === cleanPath(path)).length === 1) {
package/dist/index.mjs CHANGED
@@ -120,6 +120,126 @@ function formatVarType({
120
120
  if (defaultStr) optionalStr = "";
121
121
  return `${varName}${optionalStr}: ${type}${defaultStr}`;
122
122
  }
123
+ const RESERVED_KEYWORDS = /* @__PURE__ */ new Set([
124
+ // JavaScript reserved words
125
+ "break",
126
+ "case",
127
+ "catch",
128
+ "class",
129
+ "const",
130
+ "continue",
131
+ "debugger",
132
+ "default",
133
+ "delete",
134
+ "do",
135
+ "else",
136
+ "enum",
137
+ "export",
138
+ "extends",
139
+ "false",
140
+ "finally",
141
+ "for",
142
+ "function",
143
+ "if",
144
+ "import",
145
+ "in",
146
+ "instanceof",
147
+ "new",
148
+ "null",
149
+ "return",
150
+ "super",
151
+ "switch",
152
+ "this",
153
+ "throw",
154
+ "true",
155
+ "try",
156
+ "typeof",
157
+ "var",
158
+ "void",
159
+ "while",
160
+ "with",
161
+ "yield",
162
+ // TypeScript reserved words
163
+ "abstract",
164
+ "any",
165
+ "as",
166
+ "asserts",
167
+ "bigint",
168
+ "boolean",
169
+ "constructor",
170
+ "declare",
171
+ "get",
172
+ "infer",
173
+ "intrinsic",
174
+ "is",
175
+ "keyof",
176
+ "module",
177
+ "namespace",
178
+ "never",
179
+ "number",
180
+ "object",
181
+ "package",
182
+ "private",
183
+ "protected",
184
+ "public",
185
+ "readonly",
186
+ "require",
187
+ "set",
188
+ "static",
189
+ "string",
190
+ "symbol",
191
+ "type",
192
+ "undefined",
193
+ "unique",
194
+ "unknown",
195
+ // Strict mode reserved words
196
+ "implements",
197
+ "interface",
198
+ "let",
199
+ "package",
200
+ "private",
201
+ "protected",
202
+ "public",
203
+ "static",
204
+ // Common global identifiers to avoid
205
+ "arguments",
206
+ "eval",
207
+ "Infinity",
208
+ "NaN",
209
+ "undefined",
210
+ "globalThis",
211
+ "window",
212
+ "document",
213
+ "console",
214
+ "Object",
215
+ "Array",
216
+ "Function",
217
+ "String",
218
+ "Number",
219
+ "Boolean",
220
+ "Date",
221
+ "RegExp",
222
+ "Error",
223
+ "Promise",
224
+ "Map",
225
+ "Set",
226
+ "WeakMap",
227
+ "WeakSet",
228
+ "Symbol",
229
+ "Proxy",
230
+ "Reflect"
231
+ ]);
232
+ function sanitizeVarName(varName) {
233
+ if (!varName) return varName;
234
+ if (RESERVED_KEYWORDS.has(varName.toLowerCase())) {
235
+ return `${varName}_`;
236
+ }
237
+ return varName;
238
+ }
239
+ function toCamelCaseSafe(str) {
240
+ const camelCased = toCamelCase(str);
241
+ return sanitizeVarName(camelCased);
242
+ }
123
243
  function cleanPath(path) {
124
244
  return path.split("/").filter((p) => p && !/\{|\}/.test(p)).join("/");
125
245
  }
@@ -210,7 +330,7 @@ function generateRequestBody(requestBody) {
210
330
  const bodySchema = dereference(jsonContent.schema);
211
331
  const requestBodyType = schemaToType(bodySchema);
212
332
  collectTypeForImportStatement(requestBodyType);
213
- const requestBodyPayload = toCamelCase(bodySchema.title) || toCamelCase(requestBodyType) || "requestBody";
333
+ const requestBodyPayload = toCamelCaseSafe(bodySchema.title) || toCamelCaseSafe(requestBodyType) || "requestBody";
214
334
  const requestBodyParam = formatVarType({
215
335
  varName: requestBodyPayload,
216
336
  schema: bodySchema,
@@ -237,7 +357,7 @@ function generateFunctionParameters(params, isFileUpload = false) {
237
357
  const paramType = schemaToType(pSchema);
238
358
  collectTypeForImportStatement(paramType);
239
359
  const paramName = param.name;
240
- const varName = toCamelCase(param.name);
360
+ const varName = toCamelCaseSafe(param.name);
241
361
  if (param.in === "path" || param.in === "query" || param.in === "header") {
242
362
  functionParams.push(
243
363
  formatVarType({
@@ -388,7 +508,7 @@ function generateFunctions(paths, baseUrl) {
388
508
  for (const [path, operation] of Object.entries(paths)) {
389
509
  const splitPath = path.split("/").filter((p) => p && !/\{|\}/.test(p));
390
510
  splitPath.reduce((acc, key, index, array) => {
391
- const objFuncKey = toCamelCase(key);
511
+ const objFuncKey = toCamelCaseSafe(key);
392
512
  if (!objFuncKey) return acc;
393
513
  const methods = Object.keys(operation);
394
514
  if (index === array.length - 1 && methods.length === 1 && allPathsClean.filter((p) => p === cleanPath(path)).length === 1) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/sdk",
3
3
  "type": "module",
4
- "version": "1.4.69",
4
+ "version": "1.4.73",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Neveh Allon",
@@ -16,6 +16,7 @@ import {
16
16
  formatVarType,
17
17
  schemaToType,
18
18
  toCamelCase,
19
+ toCamelCaseSafe,
19
20
  toPascalCase,
20
21
  } from './utils'
21
22
 
@@ -194,7 +195,7 @@ function generateRequestBody(requestBody?: OpenAPIOperation['requestBody']): {
194
195
  collectTypeForImportStatement(requestBodyType)
195
196
 
196
197
  const requestBodyPayload = (
197
- toCamelCase(bodySchema.title) || toCamelCase(requestBodyType) || 'requestBody'
198
+ toCamelCaseSafe(bodySchema.title) || toCamelCaseSafe(requestBodyType) || 'requestBody'
198
199
  )
199
200
 
200
201
  const requestBodyParam = formatVarType({
@@ -238,7 +239,7 @@ function generateFunctionParameters(
238
239
  const paramType = schemaToType(pSchema)
239
240
  collectTypeForImportStatement(paramType)
240
241
  const paramName = param.name
241
- const varName = toCamelCase(param.name)
242
+ const varName = toCamelCaseSafe(param.name)
242
243
 
243
244
  if (param.in === 'path' || param.in === 'query' || param.in === 'header') {
244
245
  functionParams.push(
@@ -536,7 +537,7 @@ export function generateFunctions(paths: OpenAPIPaths, baseUrl: string): string
536
537
  const splitPath = path.split('/').filter(p => p && !/\{|\}/.test(p))
537
538
 
538
539
  splitPath.reduce((acc, key: string, index: number, array: string[]) => {
539
- const objFuncKey = toCamelCase(key)
540
+ const objFuncKey = toCamelCaseSafe(key)
540
541
  if (!objFuncKey) return acc
541
542
 
542
543
  const methods = Object.keys(operation) as Array<keyof OpenAPIPath>
@@ -144,6 +144,145 @@ export function formatVarType({
144
144
  return `${varName}${optionalStr}: ${type}${defaultStr}`
145
145
  }
146
146
 
147
+ /**
148
+ * List of JavaScript/TypeScript reserved keywords and common identifiers to avoid
149
+ */
150
+ const RESERVED_KEYWORDS = new Set([
151
+ // JavaScript reserved words
152
+ 'break',
153
+ 'case',
154
+ 'catch',
155
+ 'class',
156
+ 'const',
157
+ 'continue',
158
+ 'debugger',
159
+ 'default',
160
+ 'delete',
161
+ 'do',
162
+ 'else',
163
+ 'enum',
164
+ 'export',
165
+ 'extends',
166
+ 'false',
167
+ 'finally',
168
+ 'for',
169
+ 'function',
170
+ 'if',
171
+ 'import',
172
+ 'in',
173
+ 'instanceof',
174
+ 'new',
175
+ 'null',
176
+ 'return',
177
+ 'super',
178
+ 'switch',
179
+ 'this',
180
+ 'throw',
181
+ 'true',
182
+ 'try',
183
+ 'typeof',
184
+ 'var',
185
+ 'void',
186
+ 'while',
187
+ 'with',
188
+ 'yield',
189
+ // TypeScript reserved words
190
+ 'abstract',
191
+ 'any',
192
+ 'as',
193
+ 'asserts',
194
+ 'bigint',
195
+ 'boolean',
196
+ 'constructor',
197
+ 'declare',
198
+ 'get',
199
+ 'infer',
200
+ 'intrinsic',
201
+ 'is',
202
+ 'keyof',
203
+ 'module',
204
+ 'namespace',
205
+ 'never',
206
+ 'number',
207
+ 'object',
208
+ 'package',
209
+ 'private',
210
+ 'protected',
211
+ 'public',
212
+ 'readonly',
213
+ 'require',
214
+ 'set',
215
+ 'static',
216
+ 'string',
217
+ 'symbol',
218
+ 'type',
219
+ 'undefined',
220
+ 'unique',
221
+ 'unknown',
222
+ // Strict mode reserved words
223
+ 'implements',
224
+ 'interface',
225
+ 'let',
226
+ 'package',
227
+ 'private',
228
+ 'protected',
229
+ 'public',
230
+ 'static',
231
+ // Common global identifiers to avoid
232
+ 'arguments',
233
+ 'eval',
234
+ 'Infinity',
235
+ 'NaN',
236
+ 'undefined',
237
+ 'globalThis',
238
+ 'window',
239
+ 'document',
240
+ 'console',
241
+ 'Object',
242
+ 'Array',
243
+ 'Function',
244
+ 'String',
245
+ 'Number',
246
+ 'Boolean',
247
+ 'Date',
248
+ 'RegExp',
249
+ 'Error',
250
+ 'Promise',
251
+ 'Map',
252
+ 'Set',
253
+ 'WeakMap',
254
+ 'WeakSet',
255
+ 'Symbol',
256
+ 'Proxy',
257
+ 'Reflect'
258
+ ])
259
+
260
+ /**
261
+ * Sanitizes a variable name to ensure it's not a reserved keyword
262
+ * @param varName - The variable name to sanitize
263
+ * @returns A safe variable name
264
+ */
265
+ export function sanitizeVarName(varName: string): string {
266
+ if (!varName) return varName
267
+
268
+ // If it's a reserved keyword, append underscore
269
+ if (RESERVED_KEYWORDS.has(varName.toLowerCase())) {
270
+ return `${varName}_`
271
+ }
272
+
273
+ return varName
274
+ }
275
+
276
+ /**
277
+ * Converts a string to camelCase and ensures it's not a reserved keyword
278
+ * @param str - The string to convert
279
+ * @returns A safe camelCase variable name
280
+ */
281
+ export function toCamelCaseSafe(str?: string): string {
282
+ const camelCased = toCamelCase(str)
283
+ return sanitizeVarName(camelCased)
284
+ }
285
+
147
286
  export function cleanPath(path: string) {
148
287
  return path
149
288
  .split('/')