@accelbyte/codegen 2.2.1 → 2.3.1

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.
@@ -918,7 +918,7 @@ const templateApiIndex = (serviceName, serviceNameTitle, apiList) => {
918
918
  let imports = "";
919
919
  let returnStatement = "";
920
920
  for (const cl of apiList) {
921
- const dir = cl.toLowerCase().includes("admin") ? "generated-admin" : "generated-public";
921
+ const dir = cl.toLowerCase().includes("admin") && cl !== "AdminApi" ? "generated-admin" : "generated-public";
922
922
  imports += `
923
923
  import { ${cl} } from './${dir}/${cl}.js'`;
924
924
  returnStatement += `
@@ -998,7 +998,8 @@ const Endpoint = z.object({
998
998
  schema: Schema.nullish()
999
999
  })
1000
1000
  }).nullish()
1001
- }).nullish()
1001
+ }).nullish(),
1002
+ "x-security": z.any().nullish()
1002
1003
  });
1003
1004
  const Operation = z.object({
1004
1005
  get: Endpoint.nullish(),
@@ -1148,17 +1149,13 @@ const templateApiMethod = ({
1148
1149
  classGenName,
1149
1150
  methodParams,
1150
1151
  methodParamsNoTypes,
1151
- deprecated
1152
+ deprecated,
1153
+ xSecurity
1152
1154
  }) => {
1153
- let methodSignature = "";
1154
1155
  let newPath = `'${path}'`;
1155
- let snippetSdk = "";
1156
- let snippetShell = "";
1156
+ let snippetMethod = "";
1157
1157
  for (const pathParam of pathParams) {
1158
1158
  const type = ParserUtils.parseType(pathParam);
1159
- if (pathParam.name !== "namespace") {
1160
- methodSignature += pathParam.name + `:${type}, `;
1161
- }
1162
1159
  const pName = pathParam.name === "namespace" ? "this.namespace" : pathParam.name;
1163
1160
  if (path.match(`{${pathParam.name}}`)) {
1164
1161
  if (type === "string") {
@@ -1168,16 +1165,21 @@ const templateApiMethod = ({
1168
1165
  }
1169
1166
  }
1170
1167
  }
1171
- snippetShell = `curl --location --request \\
1172
- ${httpMethod} '__DOMAIN__${path}' \\
1173
- --header 'accept: application/json'`;
1168
+ const snippetShellArgs = ["--location --request", `${httpMethod} '__DOMAIN__${path}'`, "--header 'accept: application/json'"];
1169
+ const snippetApiArgs = [];
1170
+ if (xSecurity !== void 0 || path.includes("/admin")) {
1171
+ snippetShellArgs.push("--header 'Authorization: Bearer {access_token}'");
1172
+ snippetApiArgs.push("{ config: { headers: { Authorization: 'Bearer {access_token}' } }}".trim());
1173
+ }
1174
1174
  if (httpMethod !== "get") {
1175
1175
  const curlParams = bodyParams?.map((ob) => {
1176
1176
  return ` "${ob.name}": ""`;
1177
1177
  });
1178
- snippetShell += ` \\
1179
- --data-raw '{ ${curlParams}}'`;
1178
+ if (curlParams.length > 0) {
1179
+ snippetShellArgs.push(`--data-raw '{ ${curlParams}}'`);
1180
+ }
1180
1181
  }
1182
+ const snippetShell = `curl ${snippetShellArgs.join(" \\\n ")}`;
1181
1183
  const descriptionText = description ? `
1182
1184
  /**${deprecated ? "\n * @deprecated" : ""}
1183
1185
  * ${description.replace(/\n/g, "\n * ")}
@@ -1194,13 +1196,24 @@ const templateApiMethod = ({
1194
1196
  }
1195
1197
  `;
1196
1198
  const snippetPromiseString = responseType !== "unknown" ? `Promise<${responseType}>` : "Promise";
1197
- snippetSdk += `${classMethod}(${methodParams})
1199
+ snippetMethod += `${classMethod}(${methodParams})
1198
1200
  // return ${snippetPromiseString}`;
1199
- return [methodImpl, snippetSdk, snippetShell];
1201
+ return {
1202
+ generatedMethodString: methodImpl,
1203
+ snippetApiArgs,
1204
+ snippetMethod,
1205
+ snippetShell
1206
+ };
1200
1207
  };
1201
1208
 
1202
- const templateSdkSnippet = (serviceNameTitle, apiName, methodSnippet) => {
1203
- const methodArr = methodSnippet.split("//");
1209
+ const templateSdkSnippet = ({
1210
+ serviceNameTitle,
1211
+ apiName,
1212
+ snippetMethod,
1213
+ snippetApiArgs: snippetApiArgsParam
1214
+ }) => {
1215
+ const methodArr = snippetMethod.split("//");
1216
+ const snippetApiArgs = ["sdk", ...snippetApiArgsParam];
1204
1217
  let normMethod = normalizeMethodSnippet(methodArr[0].trim(), "data:");
1205
1218
  normMethod = normalizeMethodSnippet(normMethod, "queryParams:");
1206
1219
  normMethod = normalizeMethodSnippet(normMethod, "queryParams?:");
@@ -1209,14 +1222,16 @@ const templateSdkSnippet = (serviceNameTitle, apiName, methodSnippet) => {
1209
1222
  import { ${serviceNameTitle} } from '@accelbyte/sdk-${serviceNameTitle.toLowerCase()}'
1210
1223
 
1211
1224
  const sdk = Accelbyte.SDK({
1225
+ options: {
1212
1226
  baseURL: 'https://demo.accelbyte.io',
1213
1227
  clientId: '77f88506b6174c3ea4d925f5b4096ce8',
1214
1228
  namespace: 'accelbyte',
1215
1229
  redirectURI: 'http://localhost:3030'
1230
+ }
1216
1231
  })
1217
1232
 
1218
- ${serviceNameTitle}.${apiName}(sdk)
1219
- .${normMethod}`;
1233
+ ${serviceNameTitle}.${apiName}(${snippetApiArgs.join(", ")})
1234
+ .${normMethod}`;
1220
1235
  return sdkSnippet;
1221
1236
  };
1222
1237
  const normalizeMethodSnippet = (methodInput, splitWord) => {
@@ -1355,7 +1370,7 @@ class SwaggerReaderHelpers {
1355
1370
  deprecated
1356
1371
  });
1357
1372
  tagToEndpointClassesRecord[tag] = (tagToEndpointClassesRecord[tag] || "") + methodImpl;
1358
- const [generatedMethodString, snippetMethod, snippetShell] = templateApiMethod({
1373
+ const { generatedMethodString, snippetApiArgs, snippetMethod, snippetShell } = templateApiMethod({
1359
1374
  classMethod,
1360
1375
  description,
1361
1376
  httpMethod,
@@ -1366,14 +1381,15 @@ class SwaggerReaderHelpers {
1366
1381
  classGenName,
1367
1382
  methodParams,
1368
1383
  methodParamsNoTypes,
1369
- deprecated
1384
+ deprecated,
1385
+ xSecurity: endpoint["x-security"]
1370
1386
  });
1371
1387
  tagToSdkClientRecord[tag] = (tagToSdkClientRecord[tag] || "") + generatedMethodString;
1372
1388
  tagToSdkFunctionNamesRecord[tag] = (tagToSdkFunctionNamesRecord[tag] || "") + classMethod + ",";
1373
1389
  tagToSdkImportsRecord[tag] = tagToSdkImportsRecord[tag] ? [.../* @__PURE__ */ new Set([...importStatements, ...tagToSdkImportsRecord[tag]])] : [...new Set(importStatements)];
1374
1390
  const serviceNameTitle = ParserUtils.convertDashesToTitleCase(serviceName);
1375
1391
  const { apiGenName } = ParserUtils.generateApiName(tag, isAdminEndpoint);
1376
- const resultSnippet = templateSdkSnippet(serviceNameTitle, apiGenName, snippetMethod);
1392
+ const resultSnippet = templateSdkSnippet({ serviceNameTitle, apiName: apiGenName, snippetMethod, snippetApiArgs });
1377
1393
  const currentSnippetMap = {};
1378
1394
  snippetMap[pathWithBase][httpMethod] = currentSnippetMap;
1379
1395
  currentSnippetMap.web = resultSnippet;