@forge/usage 0.1.2-next.0 → 0.2.0-next.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @forge/usage
2
2
 
3
+ ## 0.2.0-next.1
4
+
5
+ ### Minor Changes
6
+
7
+ - 519caaf: Require a `billableAction` string on the `reportUsageCount` payload and send it in the usage event instead of a hardcoded value
8
+
3
9
  ## 0.1.2-next.0
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -10,6 +10,8 @@ Library for reporting billable usage from a Forge app, for Marketplace usage-bas
10
10
  import { reportUsageCount } from '@forge/usage';
11
11
 
12
12
  await reportUsageCount({
13
+ // The billable action this usage is for, as configured in your Marketplace pricing.
14
+ billableAction: 'api-call',
13
15
  usageCount: 1,
14
16
  usageTimestamp: Date.now(),
15
17
  // Optional: Atlassian account ID the usage is attributed to.
package/out/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import type { APIResponse, FetchMethod } from '@forge/api';
2
2
  export declare const USAGE_EVENTS_PATH = "/marketplace/metering/v1/usage-events";
3
- export declare const BILLABLE_ACTION = "api-call";
4
3
  export declare const DEFAULT_ACTOR = "ari:cloud:identity::user/atlassian-internal-system";
5
4
  export type ReportUsageCountParams = {
5
+ billableAction: string;
6
6
  usageCount: number;
7
7
  usageTimestamp: number | Date;
8
8
  user?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE3D,eAAO,MAAM,iBAAiB,0CAA0C,CAAC;AACzE,eAAO,MAAM,eAAe,aAAa,CAAC;AAC1C,eAAO,MAAM,aAAa,uDAAuD,CAAC;AAKlF,MAAM,MAAM,sBAAsB,GAAG;IAEnC,UAAU,EAAE,MAAM,CAAC;IAEnB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAE9B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AA2CF,eAAO,MAAM,sBAAsB,GAAI,kBAAkB,WAAW,MAC3B,QAAQ,sBAAsB,KAAG,OAAO,CAAC,WAAW,CAwB5F,CAAC;AAKF,eAAO,MAAM,gBAAgB,WA7BoB,sBAAsB,KAAG,OAAO,CAAC,WAAW,CA6Bd,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE3D,eAAO,MAAM,iBAAiB,0CAA0C,CAAC;AACzE,eAAO,MAAM,aAAa,uDAAuD,CAAC;AAKlF,MAAM,MAAM,sBAAsB,GAAG;IAEnC,cAAc,EAAE,MAAM,CAAC;IAEvB,UAAU,EAAE,MAAM,CAAC;IAEnB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAE9B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AA+CF,eAAO,MAAM,sBAAsB,GAAI,kBAAkB,WAAW,MAC3B,QAAQ,sBAAsB,KAAG,OAAO,CAAC,WAAW,CAwB5F,CAAC;AAKF,eAAO,MAAM,gBAAgB,WA7BoB,sBAAsB,KAAG,OAAO,CAAC,WAAW,CA6Bd,CAAC"}
package/out/index.js CHANGED
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.reportUsageCount = exports.createReportUsageCount = exports.DEFAULT_ACTOR = exports.BILLABLE_ACTION = exports.USAGE_EVENTS_PATH = void 0;
3
+ exports.reportUsageCount = exports.createReportUsageCount = exports.DEFAULT_ACTOR = exports.USAGE_EVENTS_PATH = void 0;
4
4
  const crypto_1 = require("crypto");
5
5
  const api_1 = require("@forge/api");
6
6
  exports.USAGE_EVENTS_PATH = '/marketplace/metering/v1/usage-events';
7
- exports.BILLABLE_ACTION = 'api-call';
8
7
  exports.DEFAULT_ACTOR = 'ari:cloud:identity::user/atlassian-internal-system';
9
8
  const COUNTER_METRIC_TYPE = 'COUNTER';
10
9
  const MAX_FUTURE_MS = 5 * 60 * 1000;
@@ -14,7 +13,10 @@ const toUserAri = (aaid) => {
14
13
  }
15
14
  return `ari:cloud:identity::user/${aaid}`;
16
15
  };
17
- const validate = ({ usageCount, usageTimestamp, user }) => {
16
+ const validate = ({ billableAction, usageCount, usageTimestamp, user }) => {
17
+ if (typeof billableAction !== 'string' || billableAction.length === 0) {
18
+ throw new Error('Invalid usage report: billableAction must be a non-empty string.');
19
+ }
18
20
  if (typeof usageCount !== 'number' ||
19
21
  !Number.isFinite(usageCount) ||
20
22
  !Number.isInteger(usageCount) ||
@@ -36,7 +38,7 @@ const createReportUsageCount = (requestAtlassian) => {
36
38
  const { timestamp: usageTimestamp, actor } = validate(params);
37
39
  const { contextAri } = (0, api_1.__getRuntime)();
38
40
  const dimensions = [
39
- { id: 'billableAction', value: exports.BILLABLE_ACTION },
41
+ { id: 'billableAction', value: params.billableAction },
40
42
  { id: 'actor', value: actor },
41
43
  { id: 'installationContext', value: contextAri }
42
44
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/usage",
3
- "version": "0.1.2-next.0",
3
+ "version": "0.2.0-next.1",
4
4
  "description": "Forge Usage SDK",
5
5
  "main": "out/index.js",
6
6
  "types": "out/index.d.ts",