@fern-api/fern-api-dev 5.26.5 → 5.27.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.
Files changed (2) hide show
  1. package/cli.cjs +429 -64
  2. package/package.json +1 -1
package/cli.cjs CHANGED
@@ -44559,6 +44559,7 @@ function createMockTaskContext({ logger: logger4 = CONSOLE_LOGGER } = {}) {
44559
44559
  context3.failAndThrow(message, error50);
44560
44560
  },
44561
44561
  captureException: () => {
44562
+ return void 0;
44562
44563
  },
44563
44564
  getResult: () => TaskResult.Success,
44564
44565
  getLastFailureMessage: () => void 0,
@@ -667930,13 +667931,20 @@ var AccessTokenPosthogManager = class {
667930
667931
  properties: {
667931
667932
  ...event,
667932
667933
  ...event.properties,
667933
- version: "5.26.5",
667934
+ version: "5.27.0",
667934
667935
  usingAccessToken: true,
667935
667936
  ...getRunIdProperties()
667936
667937
  }
667937
667938
  });
667938
667939
  }
667939
667940
  }
667941
+ sendAutomationEvent(event) {
667942
+ this.posthog.capture({
667943
+ distinctId: event.distinctId,
667944
+ event: event.event,
667945
+ properties: event.properties
667946
+ });
667947
+ }
667940
667948
  async flush() {
667941
667949
  try {
667942
667950
  await Promise.race([this.posthog.flush(), new Promise((resolve15) => setTimeout(resolve15, 3e3))]);
@@ -667949,6 +667957,8 @@ var AccessTokenPosthogManager = class {
667949
667957
  var NoopPosthogManager = class {
667950
667958
  async sendEvent() {
667951
667959
  }
667960
+ async sendAutomationEvent() {
667961
+ }
667952
667962
  async identify() {
667953
667963
  }
667954
667964
  async flush() {
@@ -667985,7 +667995,7 @@ var UserPosthogManager = class {
667985
667995
  distinctId: this.userId ?? await this.getPersistedDistinctId(),
667986
667996
  event: "CLI",
667987
667997
  properties: {
667988
- version: "5.26.5",
667998
+ version: "5.27.0",
667989
667999
  ...event,
667990
668000
  ...event.properties,
667991
668001
  usingAccessToken: false,
@@ -667994,6 +668004,13 @@ var UserPosthogManager = class {
667994
668004
  }
667995
668005
  });
667996
668006
  }
668007
+ sendAutomationEvent(event) {
668008
+ this.posthog.capture({
668009
+ distinctId: event.distinctId,
668010
+ event: event.event,
668011
+ properties: event.properties
668012
+ });
668013
+ }
667997
668014
  async flush() {
667998
668015
  try {
667999
668016
  await Promise.race([this.posthog.flush(), new Promise((resolve15) => setTimeout(resolve15, 3e3))]);
@@ -671960,18 +671977,26 @@ var TelemetryClient = class _TelemetryClient {
671960
671977
  * The caller is responsible for deciding which errors are worth reporting
671961
671978
  * (see `shouldReportToSentry` in withContext.ts).
671962
671979
  */
671963
- captureException(error50, { errorCode }) {
671980
+ captureException(error50, options2) {
671964
671981
  if (this.sentry === void 0) {
671965
- return;
671982
+ return void 0;
671966
671983
  }
671967
671984
  try {
671968
- this.sentry.captureException(error50, {
671969
- captureContext: {
671970
- user: { id: this.distinctId },
671971
- tags: { ...this.baseTags, ...this.accumulatedTags, "error.code": errorCode }
671985
+ const tags = { ...this.baseTags, ...this.accumulatedTags, ...options2?.tags };
671986
+ const context3 = options2?.context;
671987
+ return withScope2((scope) => {
671988
+ scope.setTags(tags);
671989
+ if (context3 != null) {
671990
+ for (const [key2, value2] of Object.entries(context3)) {
671991
+ if (value2 != null) {
671992
+ scope.setContext(key2, value2);
671993
+ }
671994
+ }
671972
671995
  }
671996
+ return this.sentry?.captureException(error50, void 0, scope);
671973
671997
  });
671974
671998
  } catch {
671999
+ return void 0;
671975
672000
  }
671976
672001
  }
671977
672002
  async flush() {
@@ -673459,7 +673484,9 @@ function reportError(context3, error50, options2) {
673459
673484
  const capturable = error50 ?? new CliError({ message: options2?.message ?? "", code: code5 });
673460
673485
  if (shouldReportToSentry(code5)) {
673461
673486
  context3.telemetry.captureException(capturable, {
673462
- errorCode: code5
673487
+ tags: {
673488
+ "error.code": code5
673489
+ }
673463
673490
  });
673464
673491
  }
673465
673492
  context3.telemetry.sendLifecycleEvent({
@@ -673658,9 +673685,8 @@ var TaskContextAdapter = class {
673658
673685
  getLastFailureMessage() {
673659
673686
  return this.lastFailureMessage;
673660
673687
  }
673661
- captureException(error50, code5) {
673662
- const errorCode = resolveErrorCode(error50, code5);
673663
- this.context.telemetry.captureException(error50, { errorCode });
673688
+ captureException(error50, options2) {
673689
+ return this.context.telemetry.captureException(error50, options2);
673664
673690
  }
673665
673691
  getFullErrorMessage(message, error50) {
673666
673692
  const errorDetails = this.formatError(error50);
@@ -859541,7 +859567,7 @@ var LOCAL_STORAGE_FOLDER4 = ".fern-dev";
859541
859567
  var LOGS_FOLDER_NAME = "logs";
859542
859568
  var MAX_LOGS_DIR_SIZE_BYTES = 100 * 1024 * 1024;
859543
859569
  function getCliSource() {
859544
- const version7 = "5.26.5";
859570
+ const version7 = "5.27.0";
859545
859571
  return `cli@${version7}`;
859546
859572
  }
859547
859573
  var DebugLogger = class {
@@ -873514,7 +873540,7 @@ var LegacyDocsPublisher = class {
873514
873540
  previewId,
873515
873541
  disableTemplates: void 0,
873516
873542
  skipUpload,
873517
- cliVersion: "5.26.5",
873543
+ cliVersion: "5.27.0",
873518
873544
  loginCommand: "fern auth login"
873519
873545
  });
873520
873546
  if (taskContext.getResult() === TaskResult.Failure) {
@@ -878121,23 +878147,16 @@ var AbstractDynamicSnippetsGeneratorContext = class {
878121
878147
  }
878122
878148
  associateByWireValue({ parameters: parameters2, values: values2, ignoreMissingParameters }) {
878123
878149
  const instances2 = [];
878124
- for (const [key2, value2] of Object.entries(values2)) {
878150
+ const matchedWireValues = /* @__PURE__ */ new Set();
878151
+ for (const parameter6 of parameters2) {
878152
+ const wireValue = parameter6.name.wireValue;
878153
+ const value2 = values2[wireValue];
878125
878154
  if (value2 === void 0) {
878126
878155
  continue;
878127
878156
  }
878128
- this.errors.scope(key2);
878157
+ matchedWireValues.add(wireValue);
878158
+ this.errors.scope(wireValue);
878129
878159
  try {
878130
- const parameter6 = parameters2.find((param) => param.name.wireValue === key2);
878131
- if (parameter6 == null) {
878132
- if (ignoreMissingParameters) {
878133
- continue;
878134
- }
878135
- this.errors.add({
878136
- severity: Severity.Critical,
878137
- message: this.newParameterNotRecognizedError(key2).message
878138
- });
878139
- continue;
878140
- }
878141
878160
  instances2.push({
878142
878161
  name: parameter6.name,
878143
878162
  typeReference: parameter6.typeReference,
@@ -878147,6 +878166,22 @@ var AbstractDynamicSnippetsGeneratorContext = class {
878147
878166
  this.errors.unscope();
878148
878167
  }
878149
878168
  }
878169
+ if (!ignoreMissingParameters) {
878170
+ for (const [key2, value2] of Object.entries(values2)) {
878171
+ if (value2 === void 0 || matchedWireValues.has(key2)) {
878172
+ continue;
878173
+ }
878174
+ this.errors.scope(key2);
878175
+ try {
878176
+ this.errors.add({
878177
+ severity: Severity.Critical,
878178
+ message: this.newParameterNotRecognizedError(key2).message
878179
+ });
878180
+ } finally {
878181
+ this.errors.unscope();
878182
+ }
878183
+ }
878184
+ }
878150
878185
  return instances2;
878151
878186
  }
878152
878187
  /**
@@ -902637,7 +902672,8 @@ var EndpointSnippetGenerator4 = class {
902637
902672
  const args = [];
902638
902673
  const pathParameters = this.context.associateByWireValue({
902639
902674
  parameters: namedParameters,
902640
- values: snippet2.pathParameters ?? {}
902675
+ values: snippet2.pathParameters ?? {},
902676
+ ignoreMissingParameters: true
902641
902677
  });
902642
902678
  for (const parameter6 of pathParameters) {
902643
902679
  args.push({
@@ -908821,11 +908857,6 @@ var EndpointSnippetGenerator6 = class {
908821
908857
  });
908822
908858
  }
908823
908859
  }
908824
- this.context.errors.scope(Scope4.PathParameters);
908825
- if (this.context.ir.pathParameters != null) {
908826
- fields.push(...this.getPathParameters({ namedParameters: this.context.ir.pathParameters, snippet: snippet2 }));
908827
- }
908828
- this.context.errors.unscope();
908829
908860
  this.context.errors.scope(Scope4.Headers);
908830
908861
  if (this.context.ir.headers != null && snippet2.headers != null) {
908831
908862
  fields.push(...this.getConstructorHeaderArgs({ headers: this.context.ir.headers, values: snippet2.headers }));
@@ -909309,9 +909340,10 @@ var EndpointSnippetGenerator6 = class {
909309
909340
  const args = [];
909310
909341
  const inlinePathParameters = this.context.shouldInlinePathParameters();
909311
909342
  this.context.errors.scope(Scope4.PathParameters);
909343
+ const pathParameters = [...this.context.ir.pathParameters ?? [], ...request7.pathParameters ?? []];
909312
909344
  const pathParameterFields = [];
909313
- if (request7.pathParameters != null) {
909314
- pathParameterFields.push(...this.getPathParameters({ namedParameters: request7.pathParameters, snippet: snippet2 }));
909345
+ if (pathParameters.length > 0) {
909346
+ pathParameterFields.push(...this.getPathParameters({ namedParameters: pathParameters, snippet: snippet2 }));
909315
909347
  }
909316
909348
  this.context.errors.unscope();
909317
909349
  this.context.errors.scope(Scope4.RequestBody);
@@ -912089,9 +912121,10 @@ var EndpointSnippetGenerator7 = class {
912089
912121
  }
912090
912122
  getMethodArgsForInlinedRequest({ request: request7, snippet: snippet2 }) {
912091
912123
  const args = [];
912124
+ const pathParameters = [...this.context.ir.pathParameters ?? [], ...request7.pathParameters ?? []];
912092
912125
  args.push(...this.getNamedParameterArgs({
912093
912126
  kind: "PathParameters",
912094
- namedParameters: request7.pathParameters,
912127
+ namedParameters: pathParameters,
912095
912128
  values: snippet2.pathParameters
912096
912129
  }));
912097
912130
  args.push(...this.getNamedParameterArgs({
@@ -912199,9 +912232,10 @@ var EndpointSnippetGenerator7 = class {
912199
912232
  }
912200
912233
  getMethodArgsForBodyRequest({ request: request7, snippet: snippet2 }) {
912201
912234
  const args = [];
912235
+ const pathParameters = [...this.context.ir.pathParameters ?? [], ...request7.pathParameters ?? []];
912202
912236
  args.push(...this.getNamedParameterArgs({
912203
912237
  kind: "PathParameters",
912204
- namedParameters: request7.pathParameters,
912238
+ namedParameters: pathParameters,
912205
912239
  values: snippet2.pathParameters
912206
912240
  }));
912207
912241
  if (request7.body != null && snippet2.requestBody != null) {
@@ -922028,10 +922062,11 @@ var EndpointSnippetGenerator9 = class {
922028
922062
  getEndpointMethodArgsForInlinedRequest({ request: request7, snippet: snippet2 }) {
922029
922063
  const args = [];
922030
922064
  this.context.errors.scope(Scope4.PathParameters);
922065
+ const pathParameters = [...this.context.ir.pathParameters ?? [], ...request7.pathParameters ?? []];
922031
922066
  const pathParameterFields = [];
922032
- if (request7.pathParameters != null) {
922067
+ if (pathParameters.length > 0) {
922033
922068
  pathParameterFields.push(...this.getEndpointMethodPathParameters({
922034
- namedParameters: request7.pathParameters,
922069
+ namedParameters: pathParameters,
922035
922070
  snippet: snippet2
922036
922071
  }));
922037
922072
  }
@@ -922070,21 +922105,33 @@ var EndpointSnippetGenerator9 = class {
922070
922105
  return args;
922071
922106
  }
922072
922107
  getEndpointMethodPathParameters({ namedParameters, snippet: snippet2 }) {
922073
- const moduleSymbol = this.context.nameRegistry.getRegisteredSourceModuleSymbolOrThrow();
922074
922108
  return this.context.getExampleObjectProperties({
922075
922109
  parameters: namedParameters,
922076
922110
  snippetObject: snippet2.pathParameters ?? {}
922077
922111
  }).map((parameter6) => {
922078
922112
  return swift_exports.functionArgument({
922079
922113
  label: parameter6.name.name.camelCase.unsafeName,
922080
- value: this.context.dynamicTypeLiteralMapper.convert({
922081
- fromSymbol: moduleSymbol,
922082
- typeReference: parameter6.typeReference,
922083
- value: parameter6.value
922084
- })
922114
+ // Generated Swift SDKs declare every path parameter as `String` in
922115
+ // the endpoint method signature (the value is interpolated into the
922116
+ // URL string), so render non-string primitive literals as their
922117
+ // String representation here to keep the rendered snippet's
922118
+ // argument type compatible with the SDK signature.
922119
+ value: this.renderPathParameterValueAsSwiftString({ value: parameter6.value })
922085
922120
  });
922086
922121
  });
922087
922122
  }
922123
+ renderPathParameterValueAsSwiftString({ value: value2 }) {
922124
+ if (typeof value2 === "string") {
922125
+ return swift_exports.Expression.escapedStringLiteral(value2);
922126
+ }
922127
+ if (typeof value2 === "number" || typeof value2 === "boolean" || typeof value2 === "bigint") {
922128
+ return swift_exports.Expression.escapedStringLiteral(String(value2));
922129
+ }
922130
+ if (value2 == null) {
922131
+ return swift_exports.Expression.nop();
922132
+ }
922133
+ return swift_exports.Expression.escapedStringLiteral(JSON.stringify(value2));
922134
+ }
922088
922135
  getEndpointMethodQueryParameters({ namedParameters, snippet: snippet2 }) {
922089
922136
  const moduleSymbol = this.context.nameRegistry.getRegisteredSourceModuleSymbolOrThrow();
922090
922137
  return this.context.getExampleObjectProperties({
@@ -922191,7 +922238,6 @@ var EndpointSnippetGenerator9 = class {
922191
922238
  }
922192
922239
  getEndpointMethodArgsForBodyRequest({ request: request7, snippet: snippet2 }) {
922193
922240
  const args = [];
922194
- const moduleSymbol = this.context.nameRegistry.getRegisteredSourceModuleSymbolOrThrow();
922195
922241
  this.context.errors.scope(Scope4.PathParameters);
922196
922242
  const pathParameters = [...this.context.ir.pathParameters ?? [], ...request7.pathParameters ?? []];
922197
922243
  if (pathParameters.length > 0) {
@@ -947708,6 +947754,260 @@ var esm_default16 = createPrompt((config5, done) => {
947708
947754
  // src/cli-context/CliContext.ts
947709
947755
  init_lodash();
947710
947756
 
947757
+ // src/telemetry/automationTelemetryEvent.ts
947758
+ var AUTOMATION_EVENT_NAMES = {
947759
+ GENERATION_STARTED: "generation_started",
947760
+ GENERATION_COMPLETED: "generation_completed",
947761
+ GENERATION_FAILED: "generation_failed",
947762
+ VERIFICATION_FAILED: "verification_failed",
947763
+ SDK_PR_CREATED: "sdk_pr_created",
947764
+ UPGRADE_APPLIED: "upgrade_applied",
947765
+ MAJOR_VERSION_BUMP: "major_version_bump"
947766
+ };
947767
+ var AUTOMATION_EVENT_FAILURE = {
947768
+ [AUTOMATION_EVENT_NAMES.GENERATION_STARTED]: false,
947769
+ [AUTOMATION_EVENT_NAMES.GENERATION_COMPLETED]: false,
947770
+ [AUTOMATION_EVENT_NAMES.GENERATION_FAILED]: true,
947771
+ [AUTOMATION_EVENT_NAMES.VERIFICATION_FAILED]: true,
947772
+ [AUTOMATION_EVENT_NAMES.SDK_PR_CREATED]: false,
947773
+ [AUTOMATION_EVENT_NAMES.UPGRADE_APPLIED]: false,
947774
+ [AUTOMATION_EVENT_NAMES.MAJOR_VERSION_BUMP]: false
947775
+ };
947776
+ function isFailureAutomationEventName(event) {
947777
+ return AUTOMATION_EVENT_FAILURE[event];
947778
+ }
947779
+ function toPosthogProperties(event, context3) {
947780
+ return {
947781
+ automation_mode: true,
947782
+ surface: "cli",
947783
+ action: context3.action,
947784
+ run_id: context3.run_id,
947785
+ github_run_id: context3.github_run_id,
947786
+ github_run_url: context3.github_run_url,
947787
+ org: context3.org,
947788
+ config_repo: context3.config_repo,
947789
+ config_commit_sha: context3.config_commit_sha,
947790
+ config_branch: context3.config_branch,
947791
+ config_pr_number: context3.config_pr_number,
947792
+ trigger: context3.trigger,
947793
+ cli_version: context3.cli_version,
947794
+ ...event.errorCode !== void 0 ? { error_code: event.errorCode } : {},
947795
+ ...event.attributes ?? {}
947796
+ };
947797
+ }
947798
+ function toSentryTags(event, context3) {
947799
+ function appendStringIfPresent(target, key2, value2) {
947800
+ if (value2 != null) {
947801
+ target[key2] = value2;
947802
+ }
947803
+ }
947804
+ const tags = {
947805
+ surface: "cli",
947806
+ automation_mode: "true"
947807
+ };
947808
+ appendStringIfPresent(tags, "event", event.event);
947809
+ appendStringIfPresent(tags, "action", context3.action);
947810
+ appendStringIfPresent(tags, "run_id", context3.run_id);
947811
+ appendStringIfPresent(tags, "org", context3.org);
947812
+ appendStringIfPresent(tags, "config_repo", context3.config_repo);
947813
+ appendStringIfPresent(tags, "trigger", context3.trigger);
947814
+ appendStringIfPresent(tags, "error_code", event.errorCode ?? "none");
947815
+ return tags;
947816
+ }
947817
+ function toSentryContext(event, context3) {
947818
+ return {
947819
+ github_run_id: context3.github_run_id,
947820
+ github_run_url: context3.github_run_url,
947821
+ config_commit_sha: context3.config_commit_sha,
947822
+ config_branch: context3.config_branch,
947823
+ config_pr_number: context3.config_pr_number,
947824
+ cli_version: context3.cli_version,
947825
+ ...event.attributes ?? {}
947826
+ };
947827
+ }
947828
+ function toAutomationEventApiBody(event, context3) {
947829
+ return {
947830
+ event: event.event,
947831
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
947832
+ surface: "cli",
947833
+ action: context3.action,
947834
+ run_id: context3.run_id,
947835
+ github_run_id: context3.github_run_id,
947836
+ github_run_url: context3.github_run_url,
947837
+ org: context3.org,
947838
+ config_repo: context3.config_repo,
947839
+ config_commit_sha: context3.config_commit_sha,
947840
+ config_branch: context3.config_branch,
947841
+ config_pr_number: context3.config_pr_number,
947842
+ trigger: context3.trigger,
947843
+ cli_version: context3.cli_version,
947844
+ ...event.errorCode !== void 0 ? { error_code: event.errorCode } : {},
947845
+ ...event.attributes ?? {}
947846
+ };
947847
+ }
947848
+ function failureEventNameForCommand(argv) {
947849
+ const joined = argv.join(" ");
947850
+ if (/\bautomations\s+generate\b/.test(joined)) {
947851
+ return AUTOMATION_EVENT_NAMES.GENERATION_FAILED;
947852
+ }
947853
+ if (/\bautomations\s+preview\b/.test(joined)) {
947854
+ return AUTOMATION_EVENT_NAMES.VERIFICATION_FAILED;
947855
+ }
947856
+ return AUTOMATION_EVENT_NAMES.GENERATION_FAILED;
947857
+ }
947858
+
947859
+ // src/telemetry/AutomationEventApiClient.ts
947860
+ var DEFAULT_AUTOMATION_EVENTS_ORIGIN = "";
947861
+ var AUTOMATION_EVENTS_ORIGIN_ENV_VAR = "FERN_AUTOMATION_EVENTS_ORIGIN";
947862
+ var POST_TIMEOUT_MS = 3e3;
947863
+ var AutomationEventApiClient = class _AutomationEventApiClient {
947864
+ static instance;
947865
+ origin;
947866
+ inflight = [];
947867
+ static getInstance() {
947868
+ if (_AutomationEventApiClient.instance == null) {
947869
+ _AutomationEventApiClient.instance = new _AutomationEventApiClient(
947870
+ process.env[AUTOMATION_EVENTS_ORIGIN_ENV_VAR] ?? DEFAULT_AUTOMATION_EVENTS_ORIGIN
947871
+ );
947872
+ }
947873
+ return _AutomationEventApiClient.instance;
947874
+ }
947875
+ constructor(origin2) {
947876
+ this.origin = origin2;
947877
+ }
947878
+ /**
947879
+ * Resolves the automation event API endpoint from the baked origin.
947880
+ * Returns undefined when no origin is configured - callers silently skip
947881
+ * the POST in that case.
947882
+ */
947883
+ resolveEndpoint() {
947884
+ if (this.origin.length === 0) {
947885
+ return void 0;
947886
+ }
947887
+ return `${this.origin.replace(/\/$/, "")}/v1/automation/events`;
947888
+ }
947889
+ /**
947890
+ * Enqueues an automation event POST to the automation event API.
947891
+ *
947892
+ * Best-effort: on any failure (timeout, DNS, non-2xx, missing endpoint),
947893
+ * the request settles without throwing. Sentry + PostHog already captured
947894
+ * the incident.
947895
+ */
947896
+ post(event, context3) {
947897
+ this.inflight.push(this.send(event, context3));
947898
+ }
947899
+ async shutdown() {
947900
+ const pending = this.inflight;
947901
+ this.inflight = [];
947902
+ if (pending.length > 0) {
947903
+ await Promise.allSettled(pending);
947904
+ }
947905
+ }
947906
+ async send(event, context3) {
947907
+ const endpoint3 = this.resolveEndpoint();
947908
+ if (endpoint3 == null) {
947909
+ return;
947910
+ }
947911
+ const controller = new AbortController();
947912
+ const timer2 = setTimeout(() => controller.abort(), POST_TIMEOUT_MS);
947913
+ try {
947914
+ const headers2 = { "content-type": "application/json" };
947915
+ const token = await getAccessToken();
947916
+ if (token != null && token.value.length > 0) {
947917
+ headers2.Authorization = `Bearer ${token.value}`;
947918
+ }
947919
+ const response = await fetch(endpoint3, {
947920
+ method: "POST",
947921
+ headers: headers2,
947922
+ body: JSON.stringify(toAutomationEventApiBody(event, context3)),
947923
+ signal: controller.signal
947924
+ });
947925
+ void response;
947926
+ } catch {
947927
+ return;
947928
+ } finally {
947929
+ clearTimeout(timer2);
947930
+ }
947931
+ }
947932
+ };
947933
+
947934
+ // src/telemetry/automationTelemetryContext.ts
947935
+ function getAutomationContextFromEnv() {
947936
+ const { fern_run_id, github_run_id } = getRunIdProperties();
947937
+ return {
947938
+ action: process.env.FERN_ACTION,
947939
+ run_id: fern_run_id,
947940
+ github_run_id,
947941
+ github_run_url: process.env.FERN_GITHUB_RUN_URL,
947942
+ org: void 0,
947943
+ config_repo: process.env.FERN_CONFIG_REPO,
947944
+ config_commit_sha: process.env.FERN_CONFIG_COMMIT_SHA,
947945
+ config_branch: process.env.FERN_CONFIG_BRANCH,
947946
+ config_pr_number: process.env.FERN_CONFIG_PR_NUMBER,
947947
+ trigger: process.env.GITHUB_EVENT_NAME,
947948
+ cli_version: "5.27.0"
947949
+ };
947950
+ }
947951
+ function isAutomationMode() {
947952
+ return process.env.FERN_AUTOMATION === "true";
947953
+ }
947954
+
947955
+ // src/telemetry/AutomationTelemetryManager.ts
947956
+ var AutomationTelemetryManager = class {
947957
+ constructor(reporter, automationEventApiClient = AutomationEventApiClient.getInstance()) {
947958
+ this.reporter = reporter;
947959
+ this.automationEventApiClient = automationEventApiClient;
947960
+ this.context = getAutomationContextFromEnv();
947961
+ }
947962
+ reporter;
947963
+ automationEventApiClient;
947964
+ context;
947965
+ setOrganization(organization) {
947966
+ this.context = { ...this.context, org: organization };
947967
+ }
947968
+ emit(event, options2) {
947969
+ const sentryEventId = this.captureSentryForFailure({
947970
+ event,
947971
+ context: this.context,
947972
+ error: options2?.error
947973
+ });
947974
+ const eventWithSentry = sentryEventId == null ? event : { ...event, attributes: { ...event.attributes ?? {}, sentry_event_id: sentryEventId } };
947975
+ this.capturePostHogEvent({ event: eventWithSentry, context: this.context });
947976
+ this.captureAutomationEventApiEvent(eventWithSentry, this.context);
947977
+ }
947978
+ async flush() {
947979
+ await this.automationEventApiClient.shutdown();
947980
+ }
947981
+ capturePostHogEvent({
947982
+ event,
947983
+ context: context3
947984
+ }) {
947985
+ this.reporter.instrumentPostHogAutomationEvent({
947986
+ distinctId: context3.run_id ?? void 0,
947987
+ event: event.event,
947988
+ properties: toPosthogProperties(event, context3)
947989
+ });
947990
+ }
947991
+ captureSentryForFailure({
947992
+ event,
947993
+ context: context3,
947994
+ error: error50
947995
+ }) {
947996
+ if (!isFailureAutomationEventName(event.event) || event.errorCode == null) {
947997
+ return void 0;
947998
+ }
947999
+ return this.reporter.captureException(error50, {
948000
+ tags: toSentryTags(event, context3),
948001
+ context: {
948002
+ automation: toSentryContext(event, context3)
948003
+ }
948004
+ });
948005
+ }
948006
+ captureAutomationEventApiEvent(event, context3) {
948007
+ this.automationEventApiClient.post(event, context3);
948008
+ }
948009
+ };
948010
+
947711
948011
  // src/telemetry/reportError.ts
947712
948012
  init_lib6();
947713
948013
  function reportError2(reporter, error50, options2) {
@@ -947715,17 +948015,47 @@ function reportError2(reporter, error50, options2) {
947715
948015
  return;
947716
948016
  }
947717
948017
  const code5 = resolveErrorCode(error50, options2?.code);
948018
+ const argv = options2?.argv ?? process.argv;
948019
+ const command3 = argv.join(" ");
948020
+ const errorMessage = options2?.message ?? (error50 instanceof Error ? error50.message : void 0) ?? "";
948021
+ const reportedError = error50 ?? new CliError({ message: errorMessage, code: code5 });
948022
+ if (isAutomationMode()) {
948023
+ reportErrorForAutomationMode(argv, reporter, code5, errorMessage, reportedError);
948024
+ } else {
948025
+ reportErrorForNormalMode(reporter, command3, code5, reportedError);
948026
+ }
948027
+ }
948028
+ function reportErrorForNormalMode(reporter, command3, code5, reportedError) {
947718
948029
  reporter.instrumentPostHogEvent({
947719
- command: process.argv.join(" "),
948030
+ command: command3,
947720
948031
  properties: {
947721
948032
  failed: true,
947722
948033
  errorCode: code5
947723
948034
  }
947724
948035
  });
947725
948036
  if (shouldReportToSentry(code5)) {
947726
- reporter.captureException(error50 ?? new CliError({ message: options2?.message ?? "", code: code5 }), code5);
948037
+ reporter.captureException(reportedError, {
948038
+ tags: {
948039
+ "error.code": code5
948040
+ }
948041
+ });
947727
948042
  }
947728
948043
  }
948044
+ function reportErrorForAutomationMode(argv, reporter, code5, errorMessage, reportedError) {
948045
+ const failureEventName = failureEventNameForCommand(argv);
948046
+ reporter.emitAutomationTelemetryEvent(
948047
+ {
948048
+ event: failureEventName,
948049
+ errorCode: code5,
948050
+ attributes: {
948051
+ error_message: errorMessage
948052
+ }
948053
+ },
948054
+ {
948055
+ error: reportedError
948056
+ }
948057
+ );
948058
+ }
947729
948059
 
947730
948060
  // src/telemetry/SentryClient.ts
947731
948061
  init_lib6();
@@ -947783,16 +948113,33 @@ var SentryClient = class {
947783
948113
  setSentryRunIdTags();
947784
948114
  }
947785
948115
  }
947786
- captureException(error50, code5) {
948116
+ captureException(error50, options2) {
947787
948117
  if (this.sentry == null) {
947788
- return;
948118
+ return void 0;
947789
948119
  }
947790
948120
  try {
947791
- this.sentry.captureException(
947792
- error50,
947793
- code5 != null ? { captureContext: { tags: { "error.code": code5 } } } : void 0
947794
- );
948121
+ const tags = options2?.tags;
948122
+ const context3 = options2?.context;
948123
+ const hasTags = tags != null && Object.keys(tags).length > 0;
948124
+ const hasContext = context3 != null && Object.values(context3).some((value2) => value2 != null);
948125
+ if (!hasTags && !hasContext) {
948126
+ return this.sentry.captureException(error50);
948127
+ }
948128
+ return withScope2((scope) => {
948129
+ if (hasTags) {
948130
+ scope.setTags(tags);
948131
+ }
948132
+ if (context3 != null) {
948133
+ for (const [key2, value2] of Object.entries(context3)) {
948134
+ if (value2 != null) {
948135
+ scope.setContext(key2, value2);
948136
+ }
948137
+ }
948138
+ }
948139
+ return this.sentry?.captureException(error50, void 0, scope);
948140
+ });
947795
948141
  } catch {
948142
+ return void 0;
947796
948143
  }
947797
948144
  }
947798
948145
  async flush() {
@@ -947858,6 +948205,7 @@ var TaskContextImpl = class {
947858
948205
  onResult;
947859
948206
  instrumentPostHogEventImpl;
947860
948207
  captureExceptionImpl;
948208
+ emitAutomationTelemetryEventImpl;
947861
948209
  constructor({
947862
948210
  logImmediately,
947863
948211
  logPrefix,
@@ -947866,7 +948214,8 @@ var TaskContextImpl = class {
947866
948214
  onResult,
947867
948215
  shouldBufferLogs,
947868
948216
  instrumentPostHogEvent,
947869
- captureException: captureException2
948217
+ captureException: captureException2,
948218
+ emitAutomationTelemetryEvent
947870
948219
  }) {
947871
948220
  this.logImmediately = logImmediately;
947872
948221
  this.logPrefix = logPrefix ?? "";
@@ -947876,6 +948225,7 @@ var TaskContextImpl = class {
947876
948225
  this.shouldBufferLogs = shouldBufferLogs;
947877
948226
  this.instrumentPostHogEventImpl = instrumentPostHogEvent;
947878
948227
  this.captureExceptionImpl = captureException2;
948228
+ this.emitAutomationTelemetryEventImpl = emitAutomationTelemetryEvent;
947879
948229
  }
947880
948230
  start() {
947881
948231
  this.status = "running";
@@ -947915,8 +948265,11 @@ var TaskContextImpl = class {
947915
948265
  getLastFailureMessage() {
947916
948266
  return this.lastFailureMessage;
947917
948267
  }
947918
- captureException(error50, code5) {
947919
- this.captureExceptionImpl?.(error50, code5);
948268
+ captureException(error50, options2) {
948269
+ return this.captureExceptionImpl?.(error50, options2);
948270
+ }
948271
+ emitAutomationTelemetryEvent(event, options2) {
948272
+ this.emitAutomationTelemetryEventImpl(event, options2);
947920
948273
  }
947921
948274
  getResult() {
947922
948275
  return this.result;
@@ -947959,7 +948312,8 @@ var TaskContextImpl = class {
947959
948312
  onResult: this.onResult,
947960
948313
  shouldBufferLogs: this.shouldBufferLogs,
947961
948314
  instrumentPostHogEvent: (event) => this.instrumentPostHogEventImpl(event),
947962
- captureException: this.captureExceptionImpl
948315
+ captureException: this.captureExceptionImpl,
948316
+ emitAutomationTelemetryEvent: this.emitAutomationTelemetryEventImpl
947963
948317
  });
947964
948318
  this.subtasks.push(subtask);
947965
948319
  return subtask;
@@ -948356,6 +948710,7 @@ var CliContext = class _CliContext {
948356
948710
  environment;
948357
948711
  sentryClient;
948358
948712
  posthogManager;
948713
+ automationTelemetryManager;
948359
948714
  didSucceed = true;
948360
948715
  numTasks = 0;
948361
948716
  ttyAwareLogger;
@@ -948383,6 +948738,7 @@ var CliContext = class _CliContext {
948383
948738
  cliName
948384
948739
  };
948385
948740
  this.sentryClient = new SentryClient({ release: `cli@${this.environment.packageVersion}` });
948741
+ this.automationTelemetryManager = new AutomationTelemetryManager(this);
948386
948742
  }
948387
948743
  getPackageName() {
948388
948744
  if (false) {
@@ -948394,7 +948750,7 @@ var CliContext = class _CliContext {
948394
948750
  if (false) {
948395
948751
  this.logger.error("CLI_VERSION is not defined");
948396
948752
  }
948397
- return "5.26.5";
948753
+ return "5.27.0";
948398
948754
  }
948399
948755
  getCliName() {
948400
948756
  if (false) {
@@ -948459,6 +948815,7 @@ var CliContext = class _CliContext {
948459
948815
  } catch {
948460
948816
  }
948461
948817
  await this.sentryClient.flush();
948818
+ await this.automationTelemetryManager.flush();
948462
948819
  this.exitProgram({ code: code5 });
948463
948820
  }
948464
948821
  async nudgeUpgradeIfAvailable() {
@@ -948501,6 +948858,7 @@ var CliContext = class _CliContext {
948501
948858
  project;
948502
948859
  registerProject(project) {
948503
948860
  this.project = project;
948861
+ this.automationTelemetryManager.setOrganization(project.config.organization);
948504
948862
  }
948505
948863
  runTask(run) {
948506
948864
  return this.runTaskWithInit(this.constructTaskInit(), run);
@@ -948535,8 +948893,16 @@ var CliContext = class _CliContext {
948535
948893
  this.posthogManager.sendEvent(event);
948536
948894
  }
948537
948895
  }
948538
- captureException(error50, code5) {
948539
- this.sentryClient.captureException(error50, code5);
948896
+ instrumentPostHogAutomationEvent(event) {
948897
+ if (!this.isLocal) {
948898
+ this.posthogManager.sendAutomationEvent(event);
948899
+ }
948900
+ }
948901
+ captureException(error50, options2) {
948902
+ return this.sentryClient.captureException(error50, options2);
948903
+ }
948904
+ emitAutomationTelemetryEvent(event, options2) {
948905
+ this.automationTelemetryManager.emit(event, options2);
948540
948906
  }
948541
948907
  logger = createLogger((level, ...args) => this.log(level, ...args));
948542
948908
  stderr = createLogger((level, ...args) => this.logStderr(level, ...args));
@@ -948566,9 +948932,8 @@ var CliContext = class _CliContext {
948566
948932
  this.instrumentPostHogEvent(event);
948567
948933
  },
948568
948934
  shouldBufferLogs: false,
948569
- captureException: (error50, code5) => {
948570
- this.sentryClient.captureException(error50, code5);
948571
- }
948935
+ captureException: (error50, options2) => this.sentryClient.captureException(error50, options2),
948936
+ emitAutomationTelemetryEvent: (event, options2) => this.emitAutomationTelemetryEvent(event, options2)
948572
948937
  };
948573
948938
  }
948574
948939
  log(level, ...parts) {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.26.5",
2
+ "version": "5.27.0",
3
3
  "repository": {
4
4
  "type": "git",
5
5
  "url": "git+https://github.com/fern-api/fern.git",