fern-api 0.41.1 → 0.41.3

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.
Files changed (2) hide show
  1. package/bundle.cjs +284 -256
  2. package/package.json +1 -1
package/bundle.cjs CHANGED
@@ -445660,88 +445660,6 @@ var require_xml2js = __commonJS({
445660
445660
  }
445661
445661
  });
445662
445662
 
445663
- // ../../../node_modules/.pnpm/supports-hyperlinks@2.3.0/node_modules/supports-hyperlinks/index.js
445664
- var require_supports_hyperlinks = __commonJS({
445665
- "../../../node_modules/.pnpm/supports-hyperlinks@2.3.0/node_modules/supports-hyperlinks/index.js"(exports2, module2) {
445666
- "use strict";
445667
- var supportsColor2 = require_supports_color();
445668
- var hasFlag2 = require_has_flag();
445669
- function parseVersion2(versionString) {
445670
- if (/^\d{3,4}$/.test(versionString)) {
445671
- const m = /(\d{1,2})(\d{2})/.exec(versionString);
445672
- return {
445673
- major: 0,
445674
- minor: parseInt(m[1], 10),
445675
- patch: parseInt(m[2], 10)
445676
- };
445677
- }
445678
- const versions = (versionString || "").split(".").map((n2) => parseInt(n2, 10));
445679
- return {
445680
- major: versions[0],
445681
- minor: versions[1],
445682
- patch: versions[2]
445683
- };
445684
- }
445685
- function supportsHyperlink(stream) {
445686
- const { env: env4 } = process;
445687
- if ("FORCE_HYPERLINK" in env4) {
445688
- return !(env4.FORCE_HYPERLINK.length > 0 && parseInt(env4.FORCE_HYPERLINK, 10) === 0);
445689
- }
445690
- if (hasFlag2("no-hyperlink") || hasFlag2("no-hyperlinks") || hasFlag2("hyperlink=false") || hasFlag2("hyperlink=never")) {
445691
- return false;
445692
- }
445693
- if (hasFlag2("hyperlink=true") || hasFlag2("hyperlink=always")) {
445694
- return true;
445695
- }
445696
- if ("NETLIFY" in env4) {
445697
- return true;
445698
- }
445699
- if (!supportsColor2.supportsColor(stream)) {
445700
- return false;
445701
- }
445702
- if (stream && !stream.isTTY) {
445703
- return false;
445704
- }
445705
- if (process.platform === "win32") {
445706
- return false;
445707
- }
445708
- if ("CI" in env4) {
445709
- return false;
445710
- }
445711
- if ("TEAMCITY_VERSION" in env4) {
445712
- return false;
445713
- }
445714
- if ("TERM_PROGRAM" in env4) {
445715
- const version3 = parseVersion2(env4.TERM_PROGRAM_VERSION);
445716
- switch (env4.TERM_PROGRAM) {
445717
- case "iTerm.app":
445718
- if (version3.major === 3) {
445719
- return version3.minor >= 1;
445720
- }
445721
- return version3.major > 3;
445722
- case "WezTerm":
445723
- return version3.major >= 20200620;
445724
- case "vscode":
445725
- return version3.major > 1 || version3.major === 1 && version3.minor >= 72;
445726
- }
445727
- }
445728
- if ("VTE_VERSION" in env4) {
445729
- if (env4.VTE_VERSION === "0.50.0") {
445730
- return false;
445731
- }
445732
- const version3 = parseVersion2(env4.VTE_VERSION);
445733
- return version3.major > 0 || version3.minor >= 50;
445734
- }
445735
- return false;
445736
- }
445737
- module2.exports = {
445738
- supportsHyperlink,
445739
- stdout: supportsHyperlink(process.stdout),
445740
- stderr: supportsHyperlink(process.stderr)
445741
- };
445742
- }
445743
- });
445744
-
445745
445663
  // ../../../node_modules/.pnpm/validate-npm-package-name@5.0.1/node_modules/validate-npm-package-name/lib/index.js
445746
445664
  var require_lib22 = __commonJS({
445747
445665
  "../../../node_modules/.pnpm/validate-npm-package-name@5.0.1/node_modules/validate-npm-package-name/lib/index.js"(exports2, module2) {
@@ -1187522,6 +1187440,88 @@ var require_docker = __commonJS({
1187522
1187440
  }
1187523
1187441
  });
1187524
1187442
 
1187443
+ // ../../../node_modules/.pnpm/supports-hyperlinks@2.3.0/node_modules/supports-hyperlinks/index.js
1187444
+ var require_supports_hyperlinks = __commonJS({
1187445
+ "../../../node_modules/.pnpm/supports-hyperlinks@2.3.0/node_modules/supports-hyperlinks/index.js"(exports2, module2) {
1187446
+ "use strict";
1187447
+ var supportsColor2 = require_supports_color();
1187448
+ var hasFlag2 = require_has_flag();
1187449
+ function parseVersion2(versionString) {
1187450
+ if (/^\d{3,4}$/.test(versionString)) {
1187451
+ const m = /(\d{1,2})(\d{2})/.exec(versionString);
1187452
+ return {
1187453
+ major: 0,
1187454
+ minor: parseInt(m[1], 10),
1187455
+ patch: parseInt(m[2], 10)
1187456
+ };
1187457
+ }
1187458
+ const versions = (versionString || "").split(".").map((n2) => parseInt(n2, 10));
1187459
+ return {
1187460
+ major: versions[0],
1187461
+ minor: versions[1],
1187462
+ patch: versions[2]
1187463
+ };
1187464
+ }
1187465
+ function supportsHyperlink(stream) {
1187466
+ const { env: env4 } = process;
1187467
+ if ("FORCE_HYPERLINK" in env4) {
1187468
+ return !(env4.FORCE_HYPERLINK.length > 0 && parseInt(env4.FORCE_HYPERLINK, 10) === 0);
1187469
+ }
1187470
+ if (hasFlag2("no-hyperlink") || hasFlag2("no-hyperlinks") || hasFlag2("hyperlink=false") || hasFlag2("hyperlink=never")) {
1187471
+ return false;
1187472
+ }
1187473
+ if (hasFlag2("hyperlink=true") || hasFlag2("hyperlink=always")) {
1187474
+ return true;
1187475
+ }
1187476
+ if ("NETLIFY" in env4) {
1187477
+ return true;
1187478
+ }
1187479
+ if (!supportsColor2.supportsColor(stream)) {
1187480
+ return false;
1187481
+ }
1187482
+ if (stream && !stream.isTTY) {
1187483
+ return false;
1187484
+ }
1187485
+ if (process.platform === "win32") {
1187486
+ return false;
1187487
+ }
1187488
+ if ("CI" in env4) {
1187489
+ return false;
1187490
+ }
1187491
+ if ("TEAMCITY_VERSION" in env4) {
1187492
+ return false;
1187493
+ }
1187494
+ if ("TERM_PROGRAM" in env4) {
1187495
+ const version3 = parseVersion2(env4.TERM_PROGRAM_VERSION);
1187496
+ switch (env4.TERM_PROGRAM) {
1187497
+ case "iTerm.app":
1187498
+ if (version3.major === 3) {
1187499
+ return version3.minor >= 1;
1187500
+ }
1187501
+ return version3.major > 3;
1187502
+ case "WezTerm":
1187503
+ return version3.major >= 20200620;
1187504
+ case "vscode":
1187505
+ return version3.major > 1 || version3.major === 1 && version3.minor >= 72;
1187506
+ }
1187507
+ }
1187508
+ if ("VTE_VERSION" in env4) {
1187509
+ if (env4.VTE_VERSION === "0.50.0") {
1187510
+ return false;
1187511
+ }
1187512
+ const version3 = parseVersion2(env4.VTE_VERSION);
1187513
+ return version3.major > 0 || version3.minor >= 50;
1187514
+ }
1187515
+ return false;
1187516
+ }
1187517
+ module2.exports = {
1187518
+ supportsHyperlink,
1187519
+ stdout: supportsHyperlink(process.stdout),
1187520
+ stderr: supportsHyperlink(process.stderr)
1187521
+ };
1187522
+ }
1187523
+ });
1187524
+
1187525
1187525
  // ../../../node_modules/.pnpm/queue@6.0.2/node_modules/queue/index.js
1187526
1187526
  var require_queue2 = __commonJS({
1187527
1187527
  "../../../node_modules/.pnpm/queue@6.0.2/node_modules/queue/index.js"(exports2, module2) {
@@ -1205054,11 +1205054,6 @@ async function convertFilepathOrUrl(value, absoluteFilepathToDocsConfig) {
1205054
1205054
  return { type: "url", value };
1205055
1205055
  }
1205056
1205056
 
1205057
- // ../configuration/lib/DocsLinks.js
1205058
- var DocsLinks = {
1205059
- oauth: "https://buildwithfern.com/learn/api-definition/fern/api-yml-reference#authentication"
1205060
- };
1205061
-
1205062
1205057
  // ../configuration/lib/fern-config-json/index.js
1205063
1205058
  var fern_config_json_exports = {};
1205064
1205059
  __export(fern_config_json_exports, {
@@ -1205586,6 +1205581,7 @@ __export(schemas_exports3, {
1205586
1205581
  WebhookPayloadSchema: () => WebhookPayloadSchema,
1205587
1205582
  WebhookReferencedPayloadSchema: () => WebhookReferencedPayloadSchema,
1205588
1205583
  WebhookSchema: () => WebhookSchema,
1205584
+ WithAuthSchema: () => WithAuthSchema,
1205589
1205585
  WithDocsSchema: () => WithDocsSchema,
1205590
1205586
  WithEnvironmentsSchema: () => WithEnvironmentsSchema,
1205591
1205587
  WithNameAndDocsSchema: () => WithNameAndDocsSchema,
@@ -1206104,8 +1206100,9 @@ var PaginationSchema = z.union([CursorPaginationSchema, OffsetPaginationSchema])
1206104
1206100
  var ResponseErrorsSchema = z.array(z.union([z.string(), ErrorReferenceSchema]));
1206105
1206101
 
1206106
1206102
  // ../fern-definition/schema/lib/schemas/HttpEndpointSchema.js
1206103
+ var HttpMethodSchema = z.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]);
1206107
1206104
  var HttpEndpointSchema = DeclarationSchema.extend({
1206108
- method: z.optional(z.enum(["GET", "POST", "PUT", "PATCH", "DELETE"])),
1206105
+ method: z.optional(HttpMethodSchema),
1206109
1206106
  "display-name": z.optional(z.string()),
1206110
1206107
  path: z.string(),
1206111
1206108
  url: z.optional(z.string()),
@@ -1206120,7 +1206117,6 @@ var HttpEndpointSchema = DeclarationSchema.extend({
1206120
1206117
  examples: z.optional(z.array(ExampleEndpointCallSchema)),
1206121
1206118
  pagination: z.optional(z.union([PaginationSchema, z.boolean()]))
1206122
1206119
  });
1206123
- var HttpMethodSchema = z.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]);
1206124
1206120
 
1206125
1206121
  // ../fern-definition/schema/lib/schemas/GrpcSchema.js
1206126
1206122
  var GrpcSchema = z.strictObject({
@@ -1206306,12 +1206302,14 @@ var WithEnvironmentsSchema = z.strictObject({
1206306
1206302
  "default-environment": z.optional(z.string().or(z.null())),
1206307
1206303
  environments: z.optional(z.record(z.string(), EnvironmentSchema))
1206308
1206304
  });
1206309
- var RootApiFileSchema = WithEnvironmentsSchema.extend({
1206305
+ var WithAuthSchema = z.strictObject({
1206306
+ auth: z.optional(ApiAuthSchema),
1206307
+ "auth-schemes": z.optional(z.record(AuthSchemeDeclarationSchema))
1206308
+ });
1206309
+ var RootApiFileSchema = z.strictObject({
1206310
1206310
  name: z.string(),
1206311
1206311
  "display-name": z.optional(z.string()),
1206312
1206312
  imports: z.optional(z.record(z.string())),
1206313
- auth: z.optional(ApiAuthSchema),
1206314
- "auth-schemes": z.optional(z.record(AuthSchemeDeclarationSchema)),
1206315
1206313
  headers: z.optional(z.record(z.string(), HttpHeaderSchema)),
1206316
1206314
  "error-discrimination": z.optional(ErrorDiscriminationSchema),
1206317
1206315
  audiences: z.optional(z.array(z.string())),
@@ -1206323,7 +1206321,7 @@ var RootApiFileSchema = WithEnvironmentsSchema.extend({
1206323
1206321
  variables: z.optional(z.record(VariableDeclarationSchema)),
1206324
1206322
  pagination: z.optional(PaginationSchema),
1206325
1206323
  version: z.optional(VersionDeclarationSchema)
1206326
- });
1206324
+ }).extend(WithEnvironmentsSchema.shape).extend(WithAuthSchema.shape);
1206327
1206325
 
1206328
1206326
  // ../fern-definition/schema/lib/utils/RawContainerType.js
1206329
1206327
  var RawContainerType = {
@@ -1206352,6 +1206350,11 @@ function isGeneric(name2) {
1206352
1206350
  return parseGeneric(name2) != null;
1206353
1206351
  }
1206354
1206352
 
1206353
+ // ../fern-definition/schema/lib/utils/auth/isOauthScheme.js
1206354
+ function isOAuthScheme(rawOAuthSchemeSchema) {
1206355
+ return rawOAuthSchemeSchema.scheme === "oauth";
1206356
+ }
1206357
+
1206355
1206358
  // ../fern-definition/schema/lib/utils/getRequestBody.js
1206356
1206359
  function getRequestBody(endpoint) {
1206357
1206360
  if (endpoint.request == null) {
@@ -1213472,6 +1213475,32 @@ function isRawEnumDefinition(rawTypeDeclaration) {
1213472
1213475
  return rawTypeDeclaration.enum != null;
1213473
1213476
  }
1213474
1213477
 
1213478
+ // ../fern-definition/schema/lib/utils/HttpEndpointReferenceParser.js
1213479
+ var HttpEndpointReferenceParser = class {
1213480
+ REFERENCE_REGEX = /^(GET|POST|PUT|DELETE|PATCH)\s(\/[a-zA-Z0-9\/]*)$/;
1213481
+ validate(reference) {
1213482
+ const validFormat = this.REFERENCE_REGEX.test(reference);
1213483
+ if (!validFormat) {
1213484
+ return { type: "invalid" };
1213485
+ }
1213486
+ return { type: "valid" };
1213487
+ }
1213488
+ tryParse(reference) {
1213489
+ const validationResponse = this.validate(reference);
1213490
+ if (validationResponse.type === "invalid") {
1213491
+ return void 0;
1213492
+ }
1213493
+ const match = reference.match(this.REFERENCE_REGEX);
1213494
+ if (match == null || match[1] == null || match[2] == null) {
1213495
+ return void 0;
1213496
+ }
1213497
+ return {
1213498
+ method: match[1],
1213499
+ path: match[2]
1213500
+ };
1213501
+ }
1213502
+ };
1213503
+
1213475
1213504
  // ../configuration/lib/generators-yml/schemas/APIConfigurationV2Schema.js
1213476
1213505
  var OpenAPISpecSchema = z.strictObject({
1213477
1213506
  openapi: z.string(),
@@ -1213485,6 +1213514,7 @@ var AsyncAPISchema = z.strictObject({
1213485
1213514
  });
1213486
1213515
  var SpecSchema = z.union([OpenAPISpecSchema, AsyncAPISchema]);
1213487
1213516
  var APIConfigurationV2Schema = schemas_exports3.WithEnvironmentsSchema.extend({
1213517
+ auth: z.optional(schemas_exports3.ApiAuthSchema),
1213488
1213518
  specs: z.array(SpecSchema)
1213489
1213519
  });
1213490
1213520
 
@@ -1213759,6 +1213789,7 @@ var API_ORIGIN_LOCATION_KEY = "spec-origin";
1213759
1213789
  var ASYNC_API_LOCATION_KEY = "async-api";
1213760
1213790
  var API_SETTINGS_KEY = "api-settings";
1213761
1213791
  var GeneratorsConfigurationSchema = z.strictObject({
1213792
+ "auth-schemes": z.optional(z.record(schemas_exports3.AuthSchemeDeclarationSchema)),
1213762
1213793
  api: z.optional(APIConfigurationSchema),
1213763
1213794
  whitelabel: z.optional(WhitelabelConfigurationSchema),
1213764
1213795
  metadata: z.optional(OutputMetadataSchema),
@@ -1213961,6 +1213992,19 @@ async function parseAPIConfiguration(rawGeneratorsConfiguration) {
1213961
1213992
  if (apiConfiguration != null && isApiConfigurationV2Schema(apiConfiguration)) {
1213962
1213993
  return {
1213963
1213994
  type: "singleNamespace",
1213995
+ "auth-schemes": apiConfiguration.auth != null ? Object.fromEntries(Object.entries(rawGeneratorsConfiguration["auth-schemes"] ?? {}).filter(([name2, _4]) => {
1213996
+ if (apiConfiguration.auth == null) {
1213997
+ return false;
1213998
+ }
1213999
+ return visitRawApiAuth(apiConfiguration.auth, {
1214000
+ any: (any4) => {
1214001
+ return any4.any.includes(name2);
1214002
+ },
1214003
+ single: (single) => {
1214004
+ return single === name2;
1214005
+ }
1214006
+ });
1214007
+ })) : void 0,
1213964
1214008
  ...apiConfiguration,
1213965
1214009
  definitions: apiConfiguration.specs.map((spec) => {
1213966
1214010
  if (isOpenAPISchema(spec)) {
@@ -1216775,7 +1216819,7 @@ var AccessTokenPosthogManager = class {
1216775
1216819
  properties: {
1216776
1216820
  ...event,
1216777
1216821
  ...event.properties,
1216778
- version: "0.41.1",
1216822
+ version: "0.41.3",
1216779
1216823
  usingAccessToken: true
1216780
1216824
  }
1216781
1216825
  });
@@ -1216837,7 +1216881,7 @@ var UserPosthogManager = class {
1216837
1216881
  distinctId: this.userId ?? await this.getPersistedDistinctId(),
1216838
1216882
  event: "CLI",
1216839
1216883
  properties: {
1216840
- version: "0.41.1",
1216884
+ version: "0.41.3",
1216841
1216885
  ...event,
1216842
1216886
  ...event.properties
1216843
1216887
  }
@@ -1221927,10 +1221971,10 @@ var CliContext = class {
1221927
1221971
  return "fern-api";
1221928
1221972
  }
1221929
1221973
  getPackageVersion() {
1221930
- if ("0.41.1" == null) {
1221974
+ if ("0.41.3" == null) {
1221931
1221975
  this.logger.error("CLI_VERSION is not defined");
1221932
1221976
  }
1221933
- return "0.41.1";
1221977
+ return "0.41.3";
1221934
1221978
  }
1221935
1221979
  getCliName() {
1221936
1221980
  if ("fern" == null) {
@@ -1228059,6 +1228103,18 @@ function getHeaderName(headerWireKey) {
1228059
1228103
  var BASIC_AUTH_SCHEME = "BasicAuthScheme";
1228060
1228104
  var BEARER_AUTH_SCHEME = "BearerAuthScheme";
1228061
1228105
  function buildAuthSchemes(context) {
1228106
+ if (context.authOverrides != null) {
1228107
+ for (const [name2, declaration] of Object.entries(context.authOverrides["auth-schemes"] ?? {})) {
1228108
+ context.builder.addAuthScheme({
1228109
+ name: name2,
1228110
+ schema: declaration
1228111
+ });
1228112
+ }
1228113
+ if (context.authOverrides.auth != null) {
1228114
+ context.builder.setAuth(context.authOverrides.auth);
1228115
+ }
1228116
+ return;
1228117
+ }
1228062
1228118
  let setAuth = false;
1228063
1228119
  for (const [id, securityScheme] of Object.entries(context.ir.securitySchemes)) {
1228064
1228120
  if (securityScheme.type === "basic") {
@@ -1237325,8 +1237381,8 @@ var FernDefinitionBuilderImpl = class {
1237325
1237381
  }
1237326
1237382
  this.rootApiFile.audiences.push(name2);
1237327
1237383
  }
1237328
- setAuth(name2) {
1237329
- this.rootApiFile.auth = name2;
1237384
+ setAuth(auth) {
1237385
+ this.rootApiFile.auth = auth;
1237330
1237386
  }
1237331
1237387
  addAuthScheme({ name: name2, schema: schema2 }) {
1237332
1237388
  if (this.rootApiFile["auth-schemes"] == null) {
@@ -1237698,15 +1237754,17 @@ var OpenApiIrConverterContext = class {
1237698
1237754
  ir;
1237699
1237755
  builder;
1237700
1237756
  environmentOverrides;
1237757
+ authOverrides;
1237701
1237758
  detectGlobalHeaders;
1237702
1237759
  defaultServerName = void 0;
1237703
- constructor({ taskContext, ir, enableUniqueErrorsPerEndpoint, detectGlobalHeaders, environmentOverrides }) {
1237760
+ constructor({ taskContext, ir, enableUniqueErrorsPerEndpoint, detectGlobalHeaders, environmentOverrides, authOverrides }) {
1237704
1237761
  this.logger = taskContext.logger;
1237705
1237762
  this.taskContext = taskContext;
1237706
1237763
  this.ir = ir;
1237707
1237764
  this.builder = new FernDefinitionBuilderImpl(ir, false, enableUniqueErrorsPerEndpoint);
1237708
1237765
  this.detectGlobalHeaders = detectGlobalHeaders;
1237709
1237766
  this.environmentOverrides = environmentOverrides;
1237767
+ this.authOverrides = authOverrides;
1237710
1237768
  }
1237711
1237769
  getSchema(id) {
1237712
1237770
  const schema2 = this.ir.schemas[id];
@@ -1237874,7 +1237932,7 @@ var OSSWorkspace = class extends AbstractAPIWorkspace {
1237874
1237932
  this.sources = this.convertSpecsToIdentifiableSources(specs);
1237875
1237933
  }
1237876
1237934
  async getDefinition({ context, relativePathToDependency }, settings) {
1237877
- var _a6;
1237935
+ var _a6, _b4, _c4, _d2, _e, _f;
1237878
1237936
  const openApiSpecs = await getAllOpenAPISpecs({ context, specs: this.specs, relativePathToDependency });
1237879
1237937
  const openApiIr = await parse3({
1237880
1237938
  absoluteFilePathToWorkspace: this.absoluteFilepath,
@@ -1237883,9 +1237941,8 @@ var OSSWorkspace = class extends AbstractAPIWorkspace {
1237883
1237941
  optionOverrides: getOptionsOverridesFromSettings(settings)
1237884
1237942
  });
1237885
1237943
  const definition3 = convert({
1237886
- environmentOverrides: {
1237887
- ...(_a6 = this.generatorsConfiguration) == null ? void 0 : _a6.api
1237888
- },
1237944
+ authOverrides: ((_b4 = (_a6 = this.generatorsConfiguration) == null ? void 0 : _a6.api) == null ? void 0 : _b4.auth) != null ? { ...(_c4 = this.generatorsConfiguration) == null ? void 0 : _c4.api } : void 0,
1237945
+ environmentOverrides: ((_e = (_d2 = this.generatorsConfiguration) == null ? void 0 : _d2.api) == null ? void 0 : _e.environments) != null ? { ...(_f = this.generatorsConfiguration) == null ? void 0 : _f.api } : void 0,
1237889
1237946
  taskContext: context,
1237890
1237947
  ir: openApiIr,
1237891
1237948
  enableUniqueErrorsPerEndpoint: (settings == null ? void 0 : settings.enableUniqueErrorsPerEndpoint) ?? false,
@@ -1256359,7 +1256416,7 @@ function isRootFernFilepath({ fernFilePath }) {
1256359
1256416
 
1256360
1256417
  // ../generation/ir-generator/lib/converters/convertOAuthRefreshEndpoint.js
1256361
1256418
  async function convertOAuthRefreshEndpoint({ endpointResolver, propertyResolver, file, refreshTokenEndpoint }) {
1256362
- const resolvedEndpoint = endpointResolver.resolveEndpointOrThrow({
1256419
+ const resolvedEndpoint = await endpointResolver.resolveEndpointOrThrow({
1256363
1256420
  endpoint: refreshTokenEndpoint.endpoint,
1256364
1256421
  file
1256365
1256422
  });
@@ -1256398,7 +1256455,7 @@ async function convertOAuthRefreshEndpoint({ endpointResolver, propertyResolver,
1256398
1256455
 
1256399
1256456
  // ../generation/ir-generator/lib/converters/convertOAuthTokenEndpoint.js
1256400
1256457
  async function convertOAuthTokenEndpoint({ endpointResolver, propertyResolver, file, tokenEndpoint }) {
1256401
- const resolvedEndpoint = endpointResolver.resolveEndpointOrThrow({
1256458
+ const resolvedEndpoint = await endpointResolver.resolveEndpointOrThrow({
1256402
1256459
  endpoint: tokenEndpoint.endpoint,
1256403
1256460
  file
1256404
1256461
  });
@@ -1259601,15 +1259658,61 @@ var EndpointResolverImpl = class {
1259601
1259658
  constructor(workspace) {
1259602
1259659
  this.workspace = workspace;
1259603
1259660
  }
1259604
- resolveEndpointOrThrow({ endpoint, file }) {
1259605
- const resolvedEndpoint = this.resolveEndpoint({ endpoint, file });
1259661
+ async resolveEndpointOrThrow({ endpoint, file }) {
1259662
+ const resolvedEndpoint = await this.resolveEndpoint({ endpoint, file });
1259606
1259663
  if (resolvedEndpoint == null) {
1259607
1259664
  throw new Error("Cannot resolve endpoint: " + endpoint + " in file " + file.relativeFilepath);
1259608
1259665
  }
1259609
1259666
  return resolvedEndpoint;
1259610
1259667
  }
1259611
- resolveEndpoint({ endpoint, file }) {
1259668
+ async resolveEndpointByMethodAndPath({ method, path: path45 }) {
1259669
+ let result = void 0;
1259670
+ await visitAllDefinitionFiles(this.workspace, async (relativeFilepath, file, metadata) => {
1259671
+ var _a6;
1259672
+ const context = constructFernFileContext({
1259673
+ relativeFilepath,
1259674
+ definitionFile: file,
1259675
+ casingsGenerator: CASINGS_GENERATOR,
1259676
+ rootApiFile: this.workspace.definition.rootApiFile.contents,
1259677
+ defaultUrl: metadata.defaultUrl
1259678
+ });
1259679
+ for (const [endpointId, endpointDeclaration] of Object.entries(((_a6 = file.service) == null ? void 0 : _a6.endpoints) ?? {})) {
1259680
+ if (endpointDeclaration.method === method && endpointDeclaration.path === path45) {
1259681
+ result = {
1259682
+ endpointId,
1259683
+ endpoint: endpointDeclaration,
1259684
+ file: context
1259685
+ };
1259686
+ }
1259687
+ }
1259688
+ });
1259689
+ await visitAllPackageMarkers(this.workspace, async (relativeFilepath, packageMarker) => {
1259690
+ var _a6;
1259691
+ const context = constructFernFileContext({
1259692
+ relativeFilepath,
1259693
+ definitionFile: packageMarker,
1259694
+ casingsGenerator: CASINGS_GENERATOR,
1259695
+ rootApiFile: this.workspace.definition.rootApiFile.contents
1259696
+ });
1259697
+ for (const [endpointId, endpointDeclaration] of Object.entries(((_a6 = packageMarker.service) == null ? void 0 : _a6.endpoints) ?? {})) {
1259698
+ if (endpointDeclaration.method === method && endpointDeclaration.path === path45) {
1259699
+ result = {
1259700
+ endpointId,
1259701
+ endpoint: endpointDeclaration,
1259702
+ file: context
1259703
+ };
1259704
+ }
1259705
+ }
1259706
+ });
1259707
+ return result;
1259708
+ }
1259709
+ async resolveEndpoint({ endpoint, file }) {
1259612
1259710
  var _a6, _b4;
1259711
+ const referenceParser = new HttpEndpointReferenceParser();
1259712
+ const parsedEndpointReference = referenceParser.tryParse(endpoint);
1259713
+ if (parsedEndpointReference != null) {
1259714
+ return await this.resolveEndpointByMethodAndPath(parsedEndpointReference);
1259715
+ }
1259613
1259716
  const maybeDeclaration = this.getDeclarationOfEndpoint({
1259614
1259717
  referenceToEndpoint: endpoint,
1259615
1259718
  file
@@ -1259828,7 +1259931,7 @@ var PropertyResolverImpl = class {
1259828
1259931
  return resolvedRequestProperty;
1259829
1259932
  }
1259830
1259933
  async resolveRequestProperty({ file, endpoint, propertyComponents }) {
1259831
- const resolvedEndpoint = this.endpointResolver.resolveEndpointOrThrow({
1259934
+ const resolvedEndpoint = await this.endpointResolver.resolveEndpointOrThrow({
1259832
1259935
  endpoint,
1259833
1259936
  file
1259834
1259937
  });
@@ -1259868,7 +1259971,7 @@ var PropertyResolverImpl = class {
1259868
1259971
  }
1259869
1259972
  async resolveResponseProperty({ file, endpoint, propertyComponents }) {
1259870
1259973
  var _a6;
1259871
- const resolvedEndpoint = this.endpointResolver.resolveEndpointOrThrow({
1259974
+ const resolvedEndpoint = await this.endpointResolver.resolveEndpointOrThrow({
1259872
1259975
  endpoint,
1259873
1259976
  file
1259874
1259977
  });
@@ -1266340,7 +1266443,17 @@ async function visitRootApiFileYamlAst(contents, visitor) {
1266340
1266443
  imports: noop,
1266341
1266444
  auth: noop,
1266342
1266445
  "idempotency-headers": noop,
1266343
- "auth-schemes": noop,
1266446
+ "auth-schemes": async (authSchemes) => {
1266447
+ await Promise.all(Object.entries(authSchemes ?? {}).map(async ([authScheme, authSchemeDeclaration]) => {
1266448
+ var _a7;
1266449
+ if (isOAuthScheme(authSchemeDeclaration)) {
1266450
+ await ((_a7 = visitor.oauth) == null ? void 0 : _a7.call(visitor, { name: authScheme, oauth: authSchemeDeclaration }, [
1266451
+ "auth-scheme",
1266452
+ authScheme
1266453
+ ]));
1266454
+ }
1266455
+ }));
1266456
+ },
1266344
1266457
  pagination: noop,
1266345
1266458
  "default-environment": async (defaultEnvironment) => {
1266346
1266459
  var _a7;
@@ -1266494,6 +1266607,7 @@ function createRootApiFileAstVisitorForRules({ relativeFilepath, contents, allRu
1266494
1266607
  }
1266495
1266608
  return {
1266496
1266609
  ...createAstNodeVisitor("file"),
1266610
+ ...createAstNodeVisitor("oauth"),
1266497
1266611
  ...createAstNodeVisitor("defaultEnvironment"),
1266498
1266612
  ...createAstNodeVisitor("environment"),
1266499
1266613
  ...createAstNodeVisitor("errorDiscrimination"),
@@ -1269103,21 +1269217,6 @@ var ValidNavigationRule = {
1269103
1269217
  }
1269104
1269218
  };
1269105
1269219
 
1269106
- // ../../../node_modules/.pnpm/terminal-link@3.0.0/node_modules/terminal-link/index.js
1269107
- var import_supports_hyperlinks = __toESM(require_supports_hyperlinks(), 1);
1269108
- function terminalLink(text8, url, { target = "stdout", ...options2 } = {}) {
1269109
- if (!import_supports_hyperlinks.default[target]) {
1269110
- if (options2.fallback === false) {
1269111
- return text8;
1269112
- }
1269113
- return typeof options2.fallback === "function" ? options2.fallback(text8, url) : `${text8} (\u200B${url}\u200B)`;
1269114
- }
1269115
- return ansi_escapes_default.link(text8, url);
1269116
- }
1269117
- terminalLink.isSupported = import_supports_hyperlinks.default.stdout;
1269118
- terminalLink.stderr = (text8, url, options2 = {}) => terminalLink(text8, url, { target: "stderr", ...options2 });
1269119
- terminalLink.stderr.isSupported = import_supports_hyperlinks.default.stderr;
1269120
-
1269121
1269220
  // ../fern-definition/validator/lib/utils/propertyValidatorUtils.js
1269122
1269221
  var REQUEST_PREFIX2 = "$request.";
1269123
1269222
  var RESPONSE_PREFIX = "$response.";
@@ -1269730,155 +1269829,67 @@ function validateTokenEndpoint({ endpointId, endpoint, typeResolver, file, token
1269730
1269829
  return violations;
1269731
1269830
  }
1269732
1269831
 
1269733
- // ../fern-definition/validator/lib/rules/valid-oauth/validateClientCredentials.js
1269734
- function validateClientCredentials({ endpointId, endpoint, typeResolver, file, resolvedTokenEndpoint, resolvedRefreshEndpoint, clientCredentials: oauthScheme }) {
1269735
- const violations = [];
1269736
- if (endpointId === resolvedTokenEndpoint.endpointId) {
1269737
- violations.push(...validateTokenEndpoint({
1269738
- endpointId,
1269739
- endpoint,
1269740
- typeResolver,
1269741
- file,
1269742
- tokenEndpoint: oauthScheme["get-token"]
1269743
- }));
1269744
- }
1269745
- if (oauthScheme["refresh-token"] != null && endpointId === (resolvedRefreshEndpoint == null ? void 0 : resolvedRefreshEndpoint.endpointId)) {
1269746
- violations.push(...validateRefreshTokenEndpoint({
1269747
- endpointId,
1269748
- endpoint,
1269749
- typeResolver,
1269750
- file,
1269751
- refreshEndpoint: oauthScheme["refresh-token"]
1269752
- }));
1269753
- }
1269754
- return violations;
1269755
- }
1269756
-
1269757
1269832
  // ../fern-definition/validator/lib/rules/valid-oauth/valid-oauth.js
1269758
- var DOCS_LINK_MESSAGE = `For details, see the ${terminalLink("docs", DocsLinks.oauth, {
1269759
- fallback: (text8, url) => `${text8}: ${url}`
1269760
- })}.`;
1269761
1269833
  var ValidOauthRule = {
1269762
1269834
  name: "valid-oauth",
1269763
1269835
  create: ({ workspace }) => {
1269764
- const oauthScheme = maybeGetOAuthScheme({ workspace });
1269765
- if (oauthScheme == null) {
1269766
- return {};
1269767
- }
1269768
- const oauthSchema = oauthScheme.schema;
1269769
1269836
  const typeResolver = new TypeResolverImpl(workspace);
1269770
1269837
  const endpointResolver = new EndpointResolverImpl(workspace);
1269771
- const imports = workspace.definition.rootApiFile.contents.imports;
1269772
- if (imports == null) {
1269773
- return {
1269774
- rootApiFile: {
1269775
- file: (_4) => {
1269776
- return [
1269777
- {
1269778
- severity: "error",
1269779
- message: `File declares oauth scheme '${oauthScheme.name}', but no imports are declared to reference the required token endpoint(s). ${DOCS_LINK_MESSAGE}`
1269780
- }
1269781
- ];
1269782
- }
1269783
- }
1269784
- };
1269785
- }
1269786
1269838
  const apiFile = constructRootApiFileContext({
1269787
1269839
  casingsGenerator: CASINGS_GENERATOR2,
1269788
1269840
  rootApiFile: workspace.definition.rootApiFile.contents
1269789
1269841
  });
1269790
- const resolvedTokenEndpoint = endpointResolver.resolveEndpoint({
1269791
- endpoint: oauthSchema["get-token"].endpoint,
1269792
- file: apiFile
1269793
- });
1269794
- if (resolvedTokenEndpoint == null) {
1269795
- return {
1269796
- rootApiFile: {
1269797
- file: (_4) => {
1269798
- return [
1269799
- {
1269800
- severity: "error",
1269801
- message: `File declares oauth scheme '${oauthScheme.name}', but the OAuth 'get-token' endpoint could not be resolved. ${DOCS_LINK_MESSAGE}`
1269802
- }
1269803
- ];
1269804
- }
1269805
- }
1269806
- };
1269807
- }
1269808
- const resolvedRefreshEndpoint = oauthSchema["refresh-token"] != null ? endpointResolver.resolveEndpoint({
1269809
- endpoint: oauthSchema["refresh-token"].endpoint,
1269810
- file: apiFile
1269811
- }) : void 0;
1269812
- if (oauthSchema["refresh-token"] != null && resolvedRefreshEndpoint == null) {
1269813
- return {
1269814
- rootApiFile: {
1269815
- file: (_4) => {
1269816
- return [
1269817
- {
1269818
- severity: "error",
1269819
- message: `File declares oauth scheme '${oauthScheme.name}', but the OAuth 'refresh-token' endpoint could not be resolved. ${DOCS_LINK_MESSAGE}`
1269820
- }
1269821
- ];
1269822
- }
1269823
- }
1269824
- };
1269825
- }
1269826
1269842
  return {
1269827
- definitionFile: {
1269828
- httpEndpoint: ({ endpointId, endpoint }, { relativeFilepath, contents: definitionFile }) => {
1269829
- if (endpointId !== resolvedTokenEndpoint.endpointId && endpointId !== (resolvedRefreshEndpoint == null ? void 0 : resolvedRefreshEndpoint.endpointId)) {
1269830
- return [];
1269831
- }
1269832
- const file = constructFernFileContext({
1269833
- relativeFilepath,
1269834
- definitionFile,
1269835
- casingsGenerator: CASINGS_GENERATOR2,
1269836
- rootApiFile: workspace.definition.rootApiFile.contents
1269843
+ rootApiFile: {
1269844
+ oauth: async ({ name: name2, oauth }, { relativeFilepath }) => {
1269845
+ var _a6;
1269846
+ const violations = [];
1269847
+ const tokenEndpointReference = oauth["get-token"].endpoint;
1269848
+ const resolvedTokenEndpoint = await endpointResolver.resolveEndpoint({
1269849
+ endpoint: tokenEndpointReference,
1269850
+ file: apiFile
1269837
1269851
  });
1269838
- switch (oauthSchema.type) {
1269839
- case "client-credentials": {
1269840
- const violations = validateClientCredentials({
1269841
- endpointId,
1269842
- endpoint,
1269843
- typeResolver,
1269844
- file,
1269845
- resolvedTokenEndpoint,
1269846
- resolvedRefreshEndpoint,
1269847
- clientCredentials: oauthSchema
1269852
+ if (resolvedTokenEndpoint == null) {
1269853
+ violations.push({
1269854
+ severity: "error",
1269855
+ message: `Failed to resolve endpoint ${tokenEndpointReference}`
1269856
+ });
1269857
+ } else {
1269858
+ violations.push(...validateTokenEndpoint({
1269859
+ endpointId: resolvedTokenEndpoint.endpointId,
1269860
+ endpoint: resolvedTokenEndpoint.endpoint,
1269861
+ typeResolver,
1269862
+ file: resolvedTokenEndpoint.file,
1269863
+ tokenEndpoint: oauth["get-token"]
1269864
+ }));
1269865
+ }
1269866
+ const refreshEndpointReference = (_a6 = oauth["refresh-token"]) == null ? void 0 : _a6.endpoint;
1269867
+ if (oauth["refresh-token"] != null && refreshEndpointReference != null) {
1269868
+ const resolvedRefreshEndpoint = await endpointResolver.resolveEndpoint({
1269869
+ endpoint: refreshEndpointReference,
1269870
+ file: apiFile
1269871
+ });
1269872
+ if (resolvedRefreshEndpoint == null) {
1269873
+ violations.push({
1269874
+ severity: "error",
1269875
+ message: `Failed to resolve endpoint ${tokenEndpointReference}`
1269848
1269876
  });
1269849
- if (violations.length > 0) {
1269850
- return violations.map((violation) => ({
1269851
- severity: violation.severity,
1269852
- message: violation.message + ` ${DOCS_LINK_MESSAGE}`
1269853
- }));
1269854
- }
1269855
- return [];
1269877
+ } else {
1269878
+ violations.push(...validateRefreshTokenEndpoint({
1269879
+ endpointId: resolvedRefreshEndpoint.endpointId,
1269880
+ endpoint: resolvedRefreshEndpoint.endpoint,
1269881
+ typeResolver,
1269882
+ file: resolvedRefreshEndpoint.file,
1269883
+ refreshEndpoint: oauth["refresh-token"]
1269884
+ }));
1269856
1269885
  }
1269857
- default:
1269858
- assertNever(oauthSchema.type);
1269859
1269886
  }
1269887
+ return violations;
1269860
1269888
  }
1269861
1269889
  }
1269862
1269890
  };
1269863
1269891
  }
1269864
1269892
  };
1269865
- function maybeGetOAuthScheme({ workspace }) {
1269866
- const authSchemes = workspace.definition.rootApiFile.contents["auth-schemes"];
1269867
- if (authSchemes == null) {
1269868
- return void 0;
1269869
- }
1269870
- const oauthSchemePair = Object.entries(authSchemes).find(([_4, value]) => isRawOAuthSchemeSchema(value));
1269871
- if (oauthSchemePair == null) {
1269872
- return void 0;
1269873
- }
1269874
- return {
1269875
- name: oauthSchemePair[0],
1269876
- schema: oauthSchemePair[1]
1269877
- };
1269878
- }
1269879
- function isRawOAuthSchemeSchema(rawOAuthSchemeSchema) {
1269880
- return rawOAuthSchemeSchema.scheme === "oauth" && rawOAuthSchemeSchema.type != null && rawOAuthSchemeSchema["get-token"] != null;
1269881
- }
1269882
1269893
 
1269883
1269894
  // ../fern-definition/validator/lib/rules/valid-pagination/validateUtils.js
1269884
1269895
  function validateResultsProperty({ endpointId, typeResolver, file, resolvedResponseType, resultsProperty }) {
@@ -1323699,6 +1323710,23 @@ var import_fs9 = require("fs");
1323699
1323710
  var import_promises50 = require("fs/promises");
1323700
1323711
  var import_path41 = __toESM(require("path"), 1);
1323701
1323712
  var import_promises51 = require("stream/promises");
1323713
+
1323714
+ // ../../../node_modules/.pnpm/terminal-link@3.0.0/node_modules/terminal-link/index.js
1323715
+ var import_supports_hyperlinks = __toESM(require_supports_hyperlinks(), 1);
1323716
+ function terminalLink(text8, url, { target = "stdout", ...options2 } = {}) {
1323717
+ if (!import_supports_hyperlinks.default[target]) {
1323718
+ if (options2.fallback === false) {
1323719
+ return text8;
1323720
+ }
1323721
+ return typeof options2.fallback === "function" ? options2.fallback(text8, url) : `${text8} (\u200B${url}\u200B)`;
1323722
+ }
1323723
+ return ansi_escapes_default.link(text8, url);
1323724
+ }
1323725
+ terminalLink.isSupported = import_supports_hyperlinks.default.stdout;
1323726
+ terminalLink.stderr = (text8, url, options2 = {}) => terminalLink(text8, url, { target: "stderr", ...options2 });
1323727
+ terminalLink.stderr.isSupported = import_supports_hyperlinks.default.stderr;
1323728
+
1323729
+ // ../generation/remote-generation/remote-workspace-runner/lib/RemoteTaskHandler.js
1323702
1323730
  var import_tmp_promise11 = __toESM(require_tmp_promise(), 1);
1323703
1323731
  var _isFinished, _createdSnippets, _snippetsS3PreSignedReadUrl;
1323704
1323732
  var RemoteTaskHandler = class {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fern-api",
3
- "version": "0.41.1",
3
+ "version": "0.41.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/fern-api/fern.git",