fern-api 0.39.17 → 0.39.19

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 +137 -64
  2. package/package.json +1 -1
package/bundle.cjs CHANGED
@@ -1192625,7 +1192625,7 @@ var AccessTokenPosthogManager = class {
1192625
1192625
  properties: {
1192626
1192626
  ...event,
1192627
1192627
  ...event.properties,
1192628
- version: "0.39.17",
1192628
+ version: "0.39.19",
1192629
1192629
  usingAccessToken: true
1192630
1192630
  }
1192631
1192631
  });
@@ -1192687,7 +1192687,7 @@ var UserPosthogManager = class {
1192687
1192687
  distinctId: this.userId ?? await this.getPersistedDistinctId(),
1192688
1192688
  event: "CLI",
1192689
1192689
  properties: {
1192690
- version: "0.39.17",
1192690
+ version: "0.39.19",
1192691
1192691
  ...event,
1192692
1192692
  ...event.properties
1192693
1192693
  }
@@ -1197750,10 +1197750,10 @@ var CliContext = class {
1197750
1197750
  return "fern-api";
1197751
1197751
  }
1197752
1197752
  getPackageVersion() {
1197753
- if ("0.39.17" == null) {
1197753
+ if ("0.39.19" == null) {
1197754
1197754
  this.logger.error("CLI_VERSION is not defined");
1197755
1197755
  }
1197756
- return "0.39.17";
1197756
+ return "0.39.19";
1197757
1197757
  }
1197758
1197758
  getCliName() {
1197759
1197759
  if ("fern" == null) {
@@ -1202422,7 +1202422,7 @@ var ExamplePrimitive = {
1202422
1202422
  },
1202423
1202423
  datetime: (value) => {
1202424
1202424
  return {
1202425
- datetime: value,
1202425
+ ...value,
1202426
1202426
  type: "datetime",
1202427
1202427
  _visit: function(visitor) {
1202428
1202428
  return ExamplePrimitive._visit(this, visitor);
@@ -1202477,7 +1202477,7 @@ var ExamplePrimitive = {
1202477
1202477
  case "date":
1202478
1202478
  return visitor.date(value.date);
1202479
1202479
  case "datetime":
1202480
- return visitor.datetime(value.datetime);
1202480
+ return visitor.datetime(value);
1202481
1202481
  case "uuid":
1202482
1202482
  return visitor.uuid(value.uuid);
1202483
1202483
  case "base64":
@@ -1202692,6 +1202692,7 @@ __export(serialization_exports2, {
1202692
1202692
  ExampleCodeSampleLanguage: () => ExampleCodeSampleLanguage,
1202693
1202693
  ExampleCodeSampleSdk: () => ExampleCodeSampleSdk,
1202694
1202694
  ExampleContainer: () => ExampleContainer2,
1202695
+ ExampleDatetime: () => ExampleDatetime,
1202695
1202696
  ExampleEndpointCall: () => ExampleEndpointCall,
1202696
1202697
  ExampleEndpointErrorResponse: () => ExampleEndpointErrorResponse,
1202697
1202698
  ExampleEndpointSuccessResponse: () => ExampleEndpointSuccessResponse2,
@@ -1206055,6 +1206056,7 @@ __export(types_exports2, {
1206055
1206056
  EnumValue: () => EnumValue,
1206056
1206057
  ExampleAliasType: () => ExampleAliasType,
1206057
1206058
  ExampleContainer: () => ExampleContainer2,
1206059
+ ExampleDatetime: () => ExampleDatetime,
1206058
1206060
  ExampleEnumType: () => ExampleEnumType,
1206059
1206061
  ExampleKeyValuePair: () => ExampleKeyValuePair,
1206060
1206062
  ExampleListContainer: () => ExampleListContainer,
@@ -1206324,6 +1206326,12 @@ var ExampleTypeReference = schemas_exports4.objectWithoutOptionalProperties({
1206324
1206326
  shape: schemas_exports4.lazy(() => ExampleTypeReferenceShape2)
1206325
1206327
  }).extend(WithJsonExample);
1206326
1206328
 
1206329
+ // ../../ir-sdk/lib/sdk/serialization/resources/types/types/ExampleDatetime.js
1206330
+ var ExampleDatetime = schemas_exports4.objectWithoutOptionalProperties({
1206331
+ datetime: schemas_exports4.date(),
1206332
+ raw: schemas_exports4.string().optional()
1206333
+ });
1206334
+
1206327
1206335
  // ../../ir-sdk/lib/sdk/serialization/resources/types/types/ExamplePrimitive.js
1206328
1206336
  var ExamplePrimitive2 = schemas_exports4.union("type", {
1206329
1206337
  integer: schemas_exports4.object({
@@ -1206353,9 +1206361,7 @@ var ExamplePrimitive2 = schemas_exports4.union("type", {
1206353
1206361
  date: schemas_exports4.object({
1206354
1206362
  date: schemas_exports4.string()
1206355
1206363
  }),
1206356
- datetime: schemas_exports4.object({
1206357
- datetime: schemas_exports4.date()
1206358
- }),
1206364
+ datetime: ExampleDatetime,
1206359
1206365
  uuid: schemas_exports4.object({
1206360
1206366
  uuid: schemas_exports4.string()
1206361
1206367
  }),
@@ -1206387,7 +1206393,7 @@ var ExamplePrimitive2 = schemas_exports4.union("type", {
1206387
1206393
  case "date":
1206388
1206394
  return ExamplePrimitive.date(value.date);
1206389
1206395
  case "datetime":
1206390
- return ExamplePrimitive.datetime(value.datetime);
1206396
+ return ExamplePrimitive.datetime(value);
1206391
1206397
  case "uuid":
1206392
1206398
  return ExamplePrimitive.uuid(value.uuid);
1206393
1206399
  case "base64":
@@ -1210371,7 +1210377,8 @@ var StatusCode = schemas_exports5.number();
1210371
1210377
  // ../openapi-ir-sdk/lib/sdk/serialization/resources/commons/types/Server.js
1210372
1210378
  var Server = schemas_exports5.objectWithoutOptionalProperties({
1210373
1210379
  name: schemas_exports5.string().optional(),
1210374
- url: schemas_exports5.string()
1210380
+ url: schemas_exports5.string(),
1210381
+ audiences: schemas_exports5.list(schemas_exports5.string()).optional()
1210375
1210382
  }).extend(WithDescription);
1210376
1210383
 
1210377
1210384
  // ../openapi-ir-sdk/lib/sdk/serialization/resources/example/index.js
@@ -1215926,17 +1215933,27 @@ var ExampleTypeFactory = class {
1215926
1215933
  const fullExample = getFullExampleAsObject(example);
1215927
1215934
  const exampleDiscriminant = fullExample == null ? void 0 : fullExample[schema2.value.discriminantProperty];
1215928
1215935
  const exampleUnionVariantSchema = schema2.value.schemas[exampleDiscriminant];
1215929
- const unionVariant = this.getDiscriminatedUnionVariantSchema(schema2.value, fullExample) ?? Object.entries(schema2.value.schemas)[0];
1215930
- if (exampleDiscriminant != null && exampleUnionVariantSchema != null && exampleUnionVariantSchema.type === "object") {
1215931
- allProperties = this.getAllProperties(exampleUnionVariantSchema);
1215932
- requiredProperties = this.getAllRequiredProperties(exampleUnionVariantSchema);
1215933
- result[schema2.value.discriminantProperty] = FullExample.primitive(PrimitiveExample.string(exampleDiscriminant));
1215934
- } else if (unionVariant != null && unionVariant[1].type === "object") {
1215935
- allProperties = this.getAllProperties(unionVariant[1]);
1215936
- requiredProperties = this.getAllRequiredProperties(unionVariant[1]);
1215937
- result[schema2.value.discriminantProperty] = FullExample.primitive(PrimitiveExample.string(unionVariant[0]));
1215938
- } else {
1215939
- return void 0;
1215936
+ const unionVariants = [];
1215937
+ const schemaFromExample = this.getDiscriminatedUnionVariantSchema(schema2.value, fullExample);
1215938
+ if (schemaFromExample != null) {
1215939
+ unionVariants.push(schemaFromExample);
1215940
+ }
1215941
+ unionVariants.push(...Object.entries(schema2.value.schemas));
1215942
+ for (const unionVariant of unionVariants) {
1215943
+ if (exampleDiscriminant != null && exampleUnionVariantSchema != null && exampleUnionVariantSchema.type === "object") {
1215944
+ allProperties = this.getAllProperties(exampleUnionVariantSchema);
1215945
+ requiredProperties = this.getAllRequiredProperties(exampleUnionVariantSchema);
1215946
+ result[schema2.value.discriminantProperty] = FullExample.primitive(PrimitiveExample.string(exampleDiscriminant));
1215947
+ break;
1215948
+ } else {
1215949
+ const objectSchema = this.getObjectSchema(unionVariant[1]);
1215950
+ if (objectSchema == null) {
1215951
+ continue;
1215952
+ }
1215953
+ allProperties = this.getAllProperties(objectSchema);
1215954
+ requiredProperties = this.getAllRequiredProperties(objectSchema);
1215955
+ result[schema2.value.discriminantProperty] = FullExample.primitive(PrimitiveExample.string(unionVariant[0]));
1215956
+ }
1215940
1215957
  }
1215941
1215958
  for (const commonProperty of schema2.value.commonProperties) {
1215942
1215959
  allProperties[commonProperty.key] = commonProperty.schema;
@@ -1216162,6 +1216179,18 @@ var ExampleTypeFactory = class {
1216162
1216179
  assertNever(schema2);
1216163
1216180
  }
1216164
1216181
  }
1216182
+ getObjectSchema(schema2) {
1216183
+ if (schema2.type === "object") {
1216184
+ return schema2;
1216185
+ }
1216186
+ if (schema2.type === "reference") {
1216187
+ const referenceDeclaration = this.schemas[schema2.schema];
1216188
+ if (referenceDeclaration != null) {
1216189
+ return this.getObjectSchema(referenceDeclaration);
1216190
+ }
1216191
+ }
1216192
+ return void 0;
1216193
+ }
1216165
1216194
  getDiscriminatedUnionVariantSchema(schema2, fullExample) {
1216166
1216195
  const discriminantValue = fullExample == null ? void 0 : fullExample[schema2.discriminantProperty];
1216167
1216196
  if (discriminantValue == null || typeof discriminantValue !== "string") {
@@ -1218159,7 +1218188,8 @@ function convertServer(server) {
1218159
1218188
  return {
1218160
1218189
  url: getServerUrl({ url: server.url, variables: server.variables ?? {} }),
1218161
1218190
  description: server.description,
1218162
- name: getServerName(server)
1218191
+ name: getServerName(server),
1218192
+ audiences: getExtension(server, FernOpenAPIExtension.AUDIENCES)
1218163
1218193
  };
1218164
1218194
  }
1218165
1218195
  function getServerUrl({ url, variables }) {
@@ -1220683,69 +1220713,93 @@ function buildChannel({ channel, context, declarationFile }) {
1220683
1220713
  // ../openapi-ir-to-fern/lib/buildEnvironments.js
1220684
1220714
  var PRODUCTION_ENVNIRONMENT_NAME = "Production";
1220685
1220715
  var DEFAULT_ENVIRONMENT_NAME = "Default";
1220716
+ function extractUrlsFromEnvironmentSchema(record4) {
1220717
+ return Object.entries(record4).reduce((acc, [name2, schemaOrUrl]) => {
1220718
+ if (isRawMultipleBaseUrlsEnvironment(schemaOrUrl)) {
1220719
+ Object.entries(schemaOrUrl.urls).forEach(([urlsName, urlsValue]) => {
1220720
+ acc[urlsName] = urlsValue;
1220721
+ });
1220722
+ } else {
1220723
+ acc[name2] = typeof schemaOrUrl === "string" ? schemaOrUrl : schemaOrUrl.url;
1220724
+ }
1220725
+ return acc;
1220726
+ }, {});
1220727
+ }
1220686
1220728
  function buildEnvironments(context) {
1220687
- var _a6;
1220688
- const topLevelServerURLsWithName = {};
1220689
- const topLevelSkippedServerURLs = [];
1220729
+ var _a6, _b4;
1220730
+ const topLevelServersWithName = {};
1220731
+ const topLevelSkippedServers = [];
1220690
1220732
  for (const server of context.ir.servers) {
1220733
+ const environmentSchema = server.audiences ? {
1220734
+ url: server.url,
1220735
+ audiences: server.audiences
1220736
+ } : server.url;
1220691
1220737
  if (server.name == null) {
1220692
- topLevelSkippedServerURLs.push(server.url);
1220738
+ topLevelSkippedServers.push(environmentSchema);
1220693
1220739
  continue;
1220694
1220740
  }
1220695
- topLevelServerURLsWithName[server.name] = server.url;
1220741
+ topLevelServersWithName[server.name] = environmentSchema;
1220696
1220742
  }
1220697
- const endpointLevelServerURLsWithName = {};
1220698
- const endpointLevelSkippedServerURLs = [];
1220743
+ const endpointLevelServersWithName = {};
1220744
+ const endpointLevelSkippedServers = [];
1220699
1220745
  for (const endpoint of context.ir.endpoints) {
1220700
1220746
  for (const server of endpoint.server) {
1220747
+ const environmentSchema = server.audiences ? {
1220748
+ url: server.url,
1220749
+ audiences: server.audiences
1220750
+ } : server.url;
1220701
1220751
  if (server.name == null) {
1220702
- endpointLevelSkippedServerURLs.push(server.url);
1220752
+ endpointLevelSkippedServers.push(environmentSchema);
1220703
1220753
  continue;
1220704
1220754
  }
1220705
- endpointLevelServerURLsWithName[server.name] = server.url;
1220755
+ endpointLevelServersWithName[server.name] = environmentSchema;
1220706
1220756
  }
1220707
1220757
  }
1220708
- const numTopLevelURLs = Object.keys(topLevelServerURLsWithName).length;
1220709
- const numEndpointLevelURLs = Object.keys(endpointLevelServerURLsWithName).length;
1220710
- if (numTopLevelURLs === 0 && numEndpointLevelURLs === 0) {
1220758
+ const numTopLevelServers = Object.keys(topLevelServersWithName).length;
1220759
+ const numEndpointLevelServers = Object.keys(endpointLevelServersWithName).length;
1220760
+ if (numTopLevelServers === 0 && numEndpointLevelServers === 0) {
1220711
1220761
  const singleURL = (_a6 = context.ir.servers[0]) == null ? void 0 : _a6.url;
1220762
+ const singleURLAudiences = (_b4 = context.ir.servers[0]) == null ? void 0 : _b4.audiences;
1220712
1220763
  if (singleURL != null) {
1220713
1220764
  context.builder.addEnvironment({
1220714
1220765
  name: DEFAULT_ENVIRONMENT_NAME,
1220715
- schema: singleURL
1220766
+ schema: singleURLAudiences ? {
1220767
+ url: singleURL,
1220768
+ audiences: singleURLAudiences
1220769
+ } : singleURL
1220716
1220770
  });
1220717
1220771
  context.builder.setDefaultEnvironment(DEFAULT_ENVIRONMENT_NAME);
1220718
1220772
  }
1220719
- } else if (numTopLevelURLs > 0 && numEndpointLevelURLs === 0) {
1220773
+ } else if (numTopLevelServers > 0 && numEndpointLevelServers === 0) {
1220720
1220774
  let count = 0;
1220721
- if (topLevelSkippedServerURLs.length > 0) {
1220722
- context.logger.error(`Skipping servers ${topLevelSkippedServerURLs.join(", ")} because x-fern-server-name was not provided.`);
1220775
+ if (topLevelSkippedServers.length > 0) {
1220776
+ context.logger.error(`Skipping servers ${topLevelSkippedServers.map((server) => typeof server === "string" ? server : server.url).join(", ")} because x-fern-server-name was not provided.`);
1220723
1220777
  }
1220724
- for (const [name2, url] of Object.entries(topLevelServerURLsWithName)) {
1220778
+ for (const [name2, schema2] of Object.entries(topLevelServersWithName)) {
1220725
1220779
  if (count === 0) {
1220726
1220780
  context.builder.setDefaultEnvironment(name2);
1220727
1220781
  }
1220728
1220782
  context.builder.addEnvironment({
1220729
1220783
  name: name2,
1220730
- schema: url
1220784
+ schema: schema2
1220731
1220785
  });
1220732
1220786
  count += 1;
1220733
1220787
  }
1220734
- } else if (numEndpointLevelURLs > 0) {
1220735
- if (topLevelSkippedServerURLs.length > 0 || endpointLevelSkippedServerURLs.length > 0) {
1220736
- context.logger.error(`Skipping servers ${[...topLevelSkippedServerURLs, ...endpointLevelSkippedServerURLs].join(", ")} because x-fern-server-name was not provided.`);
1220788
+ } else if (numEndpointLevelServers > 0) {
1220789
+ if (topLevelSkippedServers.length > 0 || endpointLevelSkippedServers.length > 0) {
1220790
+ context.logger.error(`Skipping servers ${[...topLevelSkippedServers, ...endpointLevelSkippedServers].map((server) => typeof server === "string" ? server : server.url).join(", ")} because x-fern-server-name was not provided.`);
1220737
1220791
  }
1220738
- const toplevelServerURLEntries = Object.entries(topLevelServerURLsWithName)[0];
1220739
- if (toplevelServerURLEntries != null) {
1220740
- const [name2, _4] = toplevelServerURLEntries;
1220792
+ const toplevelServerEntries = Object.entries(topLevelServersWithName)[0];
1220793
+ if (toplevelServerEntries != null) {
1220794
+ const [name2, _4] = toplevelServerEntries;
1220741
1220795
  context.setDefaultServerName(name2);
1220742
1220796
  }
1220743
1220797
  context.builder.addEnvironment({
1220744
1220798
  name: PRODUCTION_ENVNIRONMENT_NAME,
1220745
1220799
  schema: {
1220746
1220800
  urls: {
1220747
- ...topLevelServerURLsWithName,
1220748
- ...endpointLevelServerURLsWithName
1220801
+ ...extractUrlsFromEnvironmentSchema(topLevelServersWithName),
1220802
+ ...extractUrlsFromEnvironmentSchema(endpointLevelServersWithName)
1220749
1220803
  }
1220750
1220804
  }
1220751
1220805
  });
@@ -1239752,7 +1239806,10 @@ function convertPrimitiveExample({ example, typeBeingExemplified }) {
1239752
1239806
  if (typeof example !== "string") {
1239753
1239807
  throw new Error("Example is not a string");
1239754
1239808
  }
1239755
- return ExampleTypeReferenceShape.primitive(ExamplePrimitive.datetime(new Date(example)));
1239809
+ return ExampleTypeReferenceShape.primitive(ExamplePrimitive.datetime({
1239810
+ datetime: new Date(example),
1239811
+ raw: example
1239812
+ }));
1239756
1239813
  },
1239757
1239814
  date: () => {
1239758
1239815
  if (typeof example !== "string") {
@@ -1242833,7 +1242890,10 @@ var ExampleGenerator = class {
1242833
1242890
  const exDateTime = example != null && typeof example === "string" ? example : examples_exports.DATE_TIME;
1242834
1242891
  return {
1242835
1242892
  jsonExample: exDateTime,
1242836
- shape: ExampleTypeReferenceShape.primitive(ExamplePrimitive.datetime(new Date(exDateTime)))
1242893
+ shape: ExampleTypeReferenceShape.primitive(ExamplePrimitive.datetime({
1242894
+ datetime: new Date(exDateTime),
1242895
+ raw: exDateTime
1242896
+ }))
1242837
1242897
  };
1242838
1242898
  }
1242839
1242899
  case "UUID": {
@@ -1249634,7 +1249694,7 @@ async function getPreviewDocsDefinition({ domain: domain2, project, context }) {
1249634
1249694
  throw new Error("No docs workspace found in project");
1249635
1249695
  }
1249636
1249696
  const fernWorkspaces = await Promise.all(apiWorkspaces.map(async (workspace) => await workspace.toFernWorkspace({ context }, { enableUniqueErrorsPerEndpoint: true, detectGlobalHeaders: false })));
1249637
- const apiCollector = new ReferencedAPICollector();
1249697
+ const apiCollector = new ReferencedAPICollector(context);
1249638
1249698
  const filesV2 = {};
1249639
1249699
  const resolver2 = new DocsDefinitionResolver(domain2, docsWorkspace, fernWorkspaces, context, void 0, async (files) => files.map((file) => {
1249640
1249700
  const fileId = v4();
@@ -1249666,20 +1249726,33 @@ async function getPreviewDocsDefinition({ domain: domain2, project, context }) {
1249666
1249726
  };
1249667
1249727
  }
1249668
1249728
  var ReferencedAPICollector = class {
1249729
+ context;
1249669
1249730
  apis = {};
1249731
+ constructor(context) {
1249732
+ this.context = context;
1249733
+ }
1249670
1249734
  addReferencedAPI({ ir, snippetsConfig }) {
1249671
- const id = v4();
1249672
- const apiDefinition = convertIrToFdrApi({ ir, snippetsConfig });
1249673
- const dbApiDefinition = convertAPIDefinitionToDb(apiDefinition, id, new SDKSnippetHolder({
1249674
- snippetsConfigWithSdkId: {},
1249675
- snippetsBySdkId: {},
1249676
- snippetTemplatesByEndpoint: {},
1249677
- snippetTemplatesByEndpointId: {},
1249678
- snippetsBySdkIdAndEndpointId: {}
1249679
- }));
1249680
- const readApiDefinition = convertDbAPIDefinitionToRead(dbApiDefinition);
1249681
- this.apis[id] = readApiDefinition;
1249682
- return id;
1249735
+ try {
1249736
+ const id = v4();
1249737
+ const apiDefinition = convertIrToFdrApi({ ir, snippetsConfig });
1249738
+ const dbApiDefinition = convertAPIDefinitionToDb(apiDefinition, id, new SDKSnippetHolder({
1249739
+ snippetsConfigWithSdkId: {},
1249740
+ snippetsBySdkId: {},
1249741
+ snippetTemplatesByEndpoint: {},
1249742
+ snippetTemplatesByEndpointId: {},
1249743
+ snippetsBySdkIdAndEndpointId: {}
1249744
+ }));
1249745
+ const readApiDefinition = convertDbAPIDefinitionToRead(dbApiDefinition);
1249746
+ this.apis[id] = readApiDefinition;
1249747
+ return id;
1249748
+ } catch (e) {
1249749
+ const err = e;
1249750
+ this.context.logger.error(`Failed to read referenced API: ${err == null ? void 0 : err.message}`);
1249751
+ if (err.stack != null) {
1249752
+ this.context.logger.error(err == null ? void 0 : err.stack);
1249753
+ }
1249754
+ throw e;
1249755
+ }
1249683
1249756
  }
1249684
1249757
  getAPIsForDefinition() {
1249685
1249758
  return this.apis;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fern-api",
3
- "version": "0.39.17",
3
+ "version": "0.39.19",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/fern-api/fern.git",