@pomeloanalytics/api 0.1.0-beta.4 → 0.1.0-beta.5

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,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.0-beta.5
4
+
5
+ - **Type break.** `quotas` of `/v1/me`, and `meta.usage` and `meta.billable_overage`
6
+ of metered responses, are now optional: an API token limited to followed
7
+ workspaces does not receive the organization's consumption. Narrow them
8
+ before use (`data.quotas?.used_units`). Unrestricted tokens still receive them.
9
+ - Add `pomelo.tenants.write(body, options?)` for `POST /v1/tenants` (scope
10
+ `tenants:write`, never restricted to some tenants): additive, idempotent
11
+ registration of up to 100 tenants of a site. New types `TenantsWriteBody` and
12
+ `TenantsWriteData`; the body keeps wire field names.
13
+ - The client sends one JSON POST for this operation; every other operation
14
+ remains a single GET.
15
+
3
16
  ## 0.1.0-beta.4
4
17
 
5
18
  - Sync the reviewed public contract for a single audience measurement and the
package/README.md CHANGED
@@ -88,6 +88,7 @@ The default timeout is 30 seconds and covers reading the response body.
88
88
  | `pomelo.me(options?)` | `/v1/me` |
89
89
  | `pomelo.sites.list(options?)` | `/v1/sites` |
90
90
  | `pomelo.tenants.list(params, options?)` | `/v1/tenants` |
91
+ | `pomelo.tenants.write(body, options?)` | `POST /v1/tenants` |
91
92
  | `pomelo.metrics.timeseries(params, options?)` | `/v1/metrics/timeseries` |
92
93
  | `pomelo.metrics.breakdown(params, options?)` | `/v1/metrics/breakdown` |
93
94
  | `pomelo.reports.overview(params, options?)` | `/v1/reports/overview` |
@@ -99,6 +100,15 @@ The default timeout is 30 seconds and covers reading the response body.
99
100
  | `pomelo.usage.current(options?)` | `/v1/usage/current` |
100
101
  | `pomelo.usage.history(params?, options?)` | `/v1/usage/history` |
101
102
 
103
+ `tenants.write` is the only operation that is not a GET. It needs a token with the
104
+ dedicated `tenants:write` scope (never restricted to some tenants), takes the
105
+ wire body (`{ site_id, tenants: [{ tenant_id, tenant_slug, tenant_name, status? }] }`,
106
+ at most 100 tenants) and is additive and idempotent.
107
+
108
+ A token restricted to followed workspaces does not see the organization's
109
+ consumption: `/v1/me` has no `quotas`, and `meta.usage` and `meta.billable_overage`
110
+ are absent from metered responses. Treat them as optional.
111
+
102
112
  Parameters use camelCase (`siteId`, `tenantId`, `actionFamily`, `actionKey`) and map
103
113
  to the API's exact wire names. Other names, such as `from`, `to`, `metric`, and
104
114
  `include`, are unchanged. `filters` is a JSON string, as defined by the API.
package/dist/client.d.ts CHANGED
@@ -9,6 +9,9 @@ export type ApiParams<Path extends ApiPath> = [WireParams<Path>] extends [never]
9
9
  [Key in keyof WireParams<Path> as Key extends string ? CamelCase<Key> : never]: WireParams<Path>[Key];
10
10
  };
11
11
  export type TenantsParams = ApiParams<'/v1/tenants'>;
12
+ /** Body of `POST /v1/tenants`: wire field names (`site_id`, `tenant_slug`, ...). */
13
+ export type TenantsWriteBody = paths['/v1/tenants']['post']['requestBody']['content']['application/json'];
14
+ export type TenantsWriteData = paths['/v1/tenants']['post']['responses'][200]['content']['application/json'];
12
15
  export type TimeseriesParams = ApiParams<'/v1/metrics/timeseries'>;
13
16
  export type BreakdownParams = ApiParams<'/v1/metrics/breakdown'>;
14
17
  export type OverviewParams = ApiParams<'/v1/reports/overview'>;
@@ -18,7 +21,7 @@ export type ActionsParams = ApiParams<'/v1/reports/actions'>;
18
21
  export type GoalsParams = ApiParams<'/v1/goals'>;
19
22
  export type GoalConversionsParams = ApiParams<'/v1/goals/conversions'>;
20
23
  export type UsageHistoryParams = ApiParams<'/v1/usage/history'>;
21
- /** Server-side API client. Each operation performs exactly one GET request. */
24
+ /** Server-side API client. Each operation performs exactly one request: GET, except `tenants.write` (POST). */
22
25
  export declare class PomeloClient {
23
26
  #private;
24
27
  constructor(options: PomeloClientOptions);
@@ -28,6 +31,12 @@ export declare class PomeloClient {
28
31
  };
29
32
  readonly tenants: {
30
33
  list: (params: TenantsParams, options?: RequestOptions) => Promise<ApiResponse<ApiData<"/v1/tenants">>>;
34
+ /**
35
+ * Registers or updates tenants of a site (additive, idempotent). Requires a token
36
+ * with the `tenants:write` scope, which cannot be restricted to some tenants.
37
+ * The body keeps the wire field names of the public contract.
38
+ */
39
+ write: (body: TenantsWriteBody, options?: RequestOptions) => Promise<ApiResponse<TenantsWriteData>>;
31
40
  };
32
41
  readonly metrics: {
33
42
  timeseries: (params: TimeseriesParams, options?: RequestOptions) => Promise<ApiResponse<ApiData<"/v1/metrics/timeseries">>>;
package/dist/client.js CHANGED
@@ -10,7 +10,7 @@ function wireQuery(params) {
10
10
  }
11
11
  return query;
12
12
  }
13
- /** Server-side API client. Each operation performs exactly one GET request. */
13
+ /** Server-side API client. Each operation performs exactly one request: GET, except `tenants.write` (POST). */
14
14
  export class PomeloClient {
15
15
  #transport;
16
16
  constructor(options) {
@@ -22,6 +22,12 @@ export class PomeloClient {
22
22
  };
23
23
  tenants = {
24
24
  list: (params, options) => this.#transport.get('/v1/tenants', wireQuery(params), options),
25
+ /**
26
+ * Registers or updates tenants of a site (additive, idempotent). Requires a token
27
+ * with the `tenants:write` scope, which cannot be restricted to some tenants.
28
+ * The body keeps the wire field names of the public contract.
29
+ */
30
+ write: (body, options) => this.#transport.post('/v1/tenants', body, options),
25
31
  };
26
32
  metrics = {
27
33
  timeseries: (params, options) => this.#transport.get('/v1/metrics/timeseries', wireQuery(params), options),
@@ -179,7 +179,7 @@ export interface paths {
179
179
  /**
180
180
  * @description Grouping dimension for breakdown endpoint.
181
181
  * When `dimension=tenant`, rows are grouped by stable `tenant_id`. The
182
- * statistics of a tenant are those of the page's client space. The
182
+ * statistics of a tenant are those of the page's tracked space. The
183
183
  * response also includes `tenant_slug` and `tenant_name` as display labels.
184
184
  */
185
185
  dimension?: components["parameters"]["BreakdownDimension"];
@@ -764,7 +764,65 @@ export interface paths {
764
764
  };
765
765
  };
766
766
  put?: never;
767
- post?: never;
767
+ /**
768
+ * Register or update tenants of a site
769
+ * @description Requires the dedicated `tenants:write` scope, distinct from the read
770
+ * scopes; a token restricted to some tenants cannot hold it.
771
+ *
772
+ * Additive and idempotent. The listed tenants are created or updated;
773
+ * tenants that are not listed are never changed. Sending the same body
774
+ * again changes nothing (`unchanged`). A tenant is deactivated only by
775
+ * an explicit `status: INACTIVE`. The whole body is validated before
776
+ * the first write; a batch interrupted by a failure is resumed by
777
+ * sending it again. At most 100 tenants per request: send larger
778
+ * registries in several requests. A slug already used by another tenant
779
+ * of the site is refused with `409 TENANT_SLUG_CONFLICT`. A tenant
780
+ * changed by another write between the read and the write is refused with
781
+ * `409 TENANT_CONFLICT`: nothing is overwritten, send the request again.
782
+ */
783
+ post: {
784
+ parameters: {
785
+ query?: never;
786
+ header?: {
787
+ /** @description Optional idempotency/request correlation identifier. */
788
+ "X-Request-Id"?: components["parameters"]["RequestIdHeader"];
789
+ };
790
+ path?: never;
791
+ cookie?: never;
792
+ };
793
+ requestBody: {
794
+ content: {
795
+ "application/json": components["schemas"]["TenantsWriteRequest"];
796
+ };
797
+ };
798
+ responses: {
799
+ /** @description OK */
800
+ 200: {
801
+ headers: {
802
+ "X-Pomelo-Usage-Warning": components["headers"]["XPomeloUsageWarning"];
803
+ "X-Request-Id": components["headers"]["XRequestId"];
804
+ [name: string]: unknown;
805
+ };
806
+ content: {
807
+ "application/json": components["schemas"]["TenantsWriteResponse"];
808
+ };
809
+ };
810
+ 401: components["responses"]["Unauthorized"];
811
+ 403: components["responses"]["Forbidden"];
812
+ /** @description `TENANT_SLUG_CONFLICT`: a slug is already used by another tenant of the site. `TENANT_CONFLICT`: a tenant was changed concurrently; send the request again. */
813
+ 409: {
814
+ headers: {
815
+ "X-Request-Id": components["headers"]["XRequestId"];
816
+ [name: string]: unknown;
817
+ };
818
+ content: {
819
+ "application/json": components["schemas"]["TenantConflictErrorResponse"];
820
+ };
821
+ };
822
+ 422: components["responses"]["InvalidParams"];
823
+ 429: components["responses"]["RateLimited"];
824
+ };
825
+ };
768
826
  delete?: never;
769
827
  options?: never;
770
828
  head?: never;
@@ -782,6 +840,8 @@ export interface paths {
782
840
  * Current billing period usage
783
841
  * @description Requires `usage:read` scope. Tokens with `metrics:read` also
784
842
  * have implicit access to this endpoint.
843
+ * A token restricted to tenants (`allowed_tenant_ids`) is refused with
844
+ * `403 FORBIDDEN`: it cannot read the organization's consumption.
785
845
  */
786
846
  get: {
787
847
  parameters: {
@@ -829,6 +889,8 @@ export interface paths {
829
889
  * Usage history by month
830
890
  * @description Requires `usage:read` scope. Tokens with `metrics:read` also
831
891
  * have implicit access to this endpoint.
892
+ * A token restricted to tenants (`allowed_tenant_ids`) is refused with
893
+ * `403 FORBIDDEN`: it cannot read the organization's consumption.
832
894
  */
833
895
  get: {
834
896
  parameters: {
@@ -1066,6 +1128,15 @@ export interface components {
1066
1128
  BreakdownResponse: {
1067
1129
  availability: components["schemas"]["ReportAvailability"];
1068
1130
  meta: components["schemas"]["MeteredMeta"];
1131
+ /**
1132
+ * @description Values of ten visits or more, except the whole-site breakdowns
1133
+ * exact from 1. With a filter, a client space or a raw referrer, the
1134
+ * values under ten visits are grouped in one last row,
1135
+ * `key: "(other)"`, summed before the cut to `limit`; its `value` is
1136
+ * exact from 10 and `null` from 1 to 9, and the row is absent when
1137
+ * nothing is grouped. A client that reads the rows as entities must
1138
+ * skip it.
1139
+ */
1069
1140
  rows: components["schemas"]["BreakdownRow"][];
1070
1141
  };
1071
1142
  BreakdownRow: {
@@ -1156,10 +1227,11 @@ export interface components {
1156
1227
  * @description Dense, strictly increasing daily series in the site's time zone. It
1157
1228
  * contains exactly one point per requested day, including zero-valued
1158
1229
  * empty days. The
1159
- * exact daily pageviews add up to the exact period total, but each
1160
- * point and `totals.pageviews` are published independently: a count
1161
- * from 1 to 9 is published as `null` (« < 10 »; zero stays `0`), so
1162
- * the returned points cannot be added up; use `totals.pageviews`.
1230
+ * exact daily pageviews add up to the exact period total. Without
1231
+ * any filter, each point and `totals.pageviews` are published
1232
+ * exactly from 1. With a filter, a count from 1 to 9 is published
1233
+ * as `null` (« < 10 »; zero stays `0`), so the returned points
1234
+ * cannot be added up; use `totals.pageviews`.
1163
1235
  */
1164
1236
  timeseries: {
1165
1237
  /** Format: date */
@@ -1245,17 +1317,17 @@ export interface components {
1245
1317
  docs_url: string;
1246
1318
  org_id: string;
1247
1319
  product: components["schemas"]["WorkspaceProductConfiguration"];
1248
- quotas: components["schemas"]["Quotas"];
1320
+ quotas?: components["schemas"]["Quotas"];
1249
1321
  rate_limits: {
1250
1322
  rps: number;
1251
1323
  };
1252
1324
  };
1253
1325
  MeteredMeta: {
1254
- billable_overage: boolean;
1326
+ billable_overage?: boolean;
1255
1327
  request_id: string;
1256
1328
  surface?: components["schemas"]["SurfaceMeta"];
1257
1329
  units_charged: number;
1258
- usage: components["schemas"]["UsageMeta"];
1330
+ usage?: components["schemas"]["UsageMeta"];
1259
1331
  };
1260
1332
  OverviewCurrent: {
1261
1333
  acquisition: {
@@ -1271,39 +1343,80 @@ export interface components {
1271
1343
  }[];
1272
1344
  /**
1273
1345
  * @description Named sources, all visits: the domains of one service under
1274
- * its name, counted before the ten-visit threshold.
1346
+ * its name, counted before the ten-visit threshold. Outside the
1347
+ * whole-site view the sources under ten visits are grouped in
1348
+ * one last row, `source: "(other)"` of type `other`, counted as
1349
+ * `audience.countries`.
1275
1350
  */
1276
1351
  top_referrer_sources: components["schemas"]["TopReferrerSource"][];
1352
+ /**
1353
+ * @description Raw referring domains of ten visits or more. The domains under
1354
+ * ten visits are grouped in one last row, `domain: "(other)"`;
1355
+ * its `sessions` is exact from 10 and `null` from 1 to 9, and
1356
+ * the row is absent when nothing is grouped.
1357
+ */
1277
1358
  top_referrers: components["schemas"]["TopReferrer"][];
1278
1359
  };
1279
1360
  audience: {
1361
+ /**
1362
+ * @description Browser families. Outside the whole-site view the families
1363
+ * under ten visits are grouped in one last row,
1364
+ * `browser_family: "(other)"`, counted as `countries`.
1365
+ */
1280
1366
  browsers: {
1281
1367
  browser_family: string;
1282
1368
  sessions: number | null;
1283
1369
  }[];
1284
1370
  /**
1285
- * @description Cities of ten visits or more. The city is read alone: the list
1286
- * is empty with a hostname, client space, filter or segment.
1371
+ * @description Cities of ten visits or more. The cities under ten visits are
1372
+ * grouped in one last row, `city: "(other)"` and
1373
+ * `country: "(other)"`; its `sessions` is exact from 10 and
1374
+ * `null` from 1 to 9, and the row is absent when nothing is
1375
+ * grouped. The city is read alone: the list is empty with a
1376
+ * hostname, client space, filter or segment.
1287
1377
  */
1288
1378
  cities?: {
1289
1379
  city: string;
1290
1380
  country: string;
1291
1381
  sessions: number | null;
1292
1382
  }[];
1383
+ /**
1384
+ * @description Countries of ten visits or more (exact from 1 on the whole
1385
+ * site with no filter). Elsewhere the countries under ten visits
1386
+ * are grouped in one last row, `country: "(other)"`; its
1387
+ * `sessions` is exact from 10 and `null` from 1 to 9, and the row
1388
+ * is absent when nothing is grouped.
1389
+ */
1293
1390
  countries: {
1294
1391
  country: string;
1295
1392
  sessions: number | null;
1296
1393
  }[];
1394
+ /**
1395
+ * @description Device types. Outside the whole-site view the types under ten
1396
+ * visits are grouped in one last row, `device_type: "(other)"`,
1397
+ * counted as `countries`; its averages are `null`.
1398
+ */
1297
1399
  devices: {
1298
1400
  avg_pages_per_session?: number | null;
1299
1401
  avg_session_eng_time_ms?: number | null;
1300
1402
  device_type: string;
1301
1403
  sessions: number | null;
1302
1404
  }[];
1405
+ /**
1406
+ * @description Operating system families. Outside the whole-site view the
1407
+ * families under ten visits are grouped in one last row,
1408
+ * `os_family: "(other)"`, counted as `countries`.
1409
+ */
1303
1410
  os: {
1304
1411
  os_family: string;
1305
1412
  sessions: number | null;
1306
1413
  }[];
1414
+ /**
1415
+ * @description Regions of ten visits or more (exact from 1 on the whole site
1416
+ * with no filter). Elsewhere the regions under ten visits are
1417
+ * grouped in one last row, `region: "(other)"` and
1418
+ * `country: "(other)"`, counted as `countries`.
1419
+ */
1307
1420
  regions: {
1308
1421
  country: string;
1309
1422
  region: string;
@@ -1488,6 +1601,7 @@ export interface components {
1488
1601
  siteId: string;
1489
1602
  /** @enum {string} */
1490
1603
  status: "ACTIVE" | "SUSPENDED";
1604
+ timezone: string;
1491
1605
  };
1492
1606
  SiteProductConfiguration: {
1493
1607
  api: components["schemas"]["ProductApi"];
@@ -1559,7 +1673,7 @@ export interface components {
1559
1673
  compareWindow: components["schemas"]["SurfaceCompareWindow"];
1560
1674
  dataFreshness: components["schemas"]["SurfaceDataFreshness"];
1561
1675
  exportCapability: components["schemas"]["SurfaceExportCapability"];
1562
- /** @description Analytics counts are exact from 10 and 0 is a measured empty count. A count of 1..9 is `null` in totals, list rows and time series points alike: render it as less than 10, never as a number. A field absent from a response was not measured. Totals are computed on exact values, then published by the same rule; never add up displayed values. A share is `null` for a row under 10 visits. A change (`delta`, `delta_pct`) is published only when both counts are, and `delta_pct` is a ratio (0.56 is +56%). Rates are published to the percent; 0.005 and 0.995 represent the open tails below 1% and above 99%. Rates, means, durations and percentiles are null under 10 contributors. Last conversion dates have day precision. Usage metering, billing, limits and diagnostics remain exact. This policy reduces detail; it is not a guarantee of anonymity. */
1676
+ /** @description On the whole site, with no filter and no client space, these counts are exact from 1: the totals and the per-day series (visitors, visits, page views, events, and the `period_total` and points of a `day` series), the breakdowns by country, region, device, system, browser, language and screen size, the pages and entry pages, the named sources and the types of referring site, and the goals with their conversions. The cities (a list of those with at least ten visits), the raw referring domains, the `hour` series, every filtered or crossed report and the Campagnes sections publish counts exact from 10; a count of 1..9 is `null`: render it as less than 10, never as a number. 0 is a measured empty count. A filtered report keeps the complement rule. Totals are computed on exact values, then published by the same rule; never add up displayed values. A share follows its count: it is `null` when the count is. A change (`delta`, `delta_pct`) is published only when both counts are 0 or at least 10, and `delta_pct` is a ratio (0.56 is +56%). Rates are published to the percent; 0.005 and 0.995 represent the open tails below 1% and above 99%. Rates, means, durations and percentiles are null under 10 contributors. Last conversion dates have day precision. Usage metering, billing, limits and diagnostics remain exact. This policy reduces detail; it is not a guarantee of anonymity. */
1563
1677
  reportingPrecision?: {
1564
1678
  /** @enum {integer} */
1565
1679
  minimumCount: 10;
@@ -1569,6 +1683,18 @@ export interface components {
1569
1683
  version: "exact-masked-counts-v1";
1570
1684
  };
1571
1685
  };
1686
+ TenantConflictErrorBody: {
1687
+ /** @enum {string} */
1688
+ code: "TENANT_SLUG_CONFLICT" | "TENANT_CONFLICT";
1689
+ details?: {
1690
+ [key: string]: unknown;
1691
+ } | null;
1692
+ message: string;
1693
+ request_id: string;
1694
+ };
1695
+ TenantConflictErrorResponse: {
1696
+ error: components["schemas"]["TenantConflictErrorBody"];
1697
+ };
1572
1698
  TenantItem: {
1573
1699
  /** @enum {string} */
1574
1700
  status: "ACTIVE" | "INACTIVE";
@@ -1582,6 +1708,34 @@ export interface components {
1582
1708
  TenantsResponse: {
1583
1709
  items: components["schemas"]["TenantItem"][];
1584
1710
  };
1711
+ TenantsWriteRequest: {
1712
+ site_id: string;
1713
+ tenants: components["schemas"]["TenantWriteItem"][];
1714
+ };
1715
+ TenantsWriteResponse: {
1716
+ created: number;
1717
+ items: components["schemas"]["TenantWriteResultItem"][];
1718
+ unchanged: number;
1719
+ updated: number;
1720
+ };
1721
+ TenantWriteItem: {
1722
+ /**
1723
+ * @description Omitted keeps the stored status (`ACTIVE` for a new tenant).
1724
+ * `INACTIVE` is the only way to deactivate a tenant.
1725
+ * @enum {string}
1726
+ */
1727
+ status?: "ACTIVE" | "INACTIVE";
1728
+ /** @description Stable tenant identifier chosen by the platform. */
1729
+ tenant_id: string;
1730
+ /** @description Display name. */
1731
+ tenant_name: string;
1732
+ /** @description Routing slug, unique within the site. */
1733
+ tenant_slug: string;
1734
+ };
1735
+ TenantWriteResultItem: components["schemas"]["TenantItem"] & {
1736
+ /** @enum {string} */
1737
+ result: "created" | "updated" | "unchanged";
1738
+ };
1585
1739
  TimeseriesPoint: {
1586
1740
  ts: string;
1587
1741
  value: number | null;
@@ -1903,7 +2057,7 @@ export interface components {
1903
2057
  /**
1904
2058
  * @description Grouping dimension for breakdown endpoint.
1905
2059
  * When `dimension=tenant`, rows are grouped by stable `tenant_id`. The
1906
- * statistics of a tenant are those of the page's client space. The
2060
+ * statistics of a tenant are those of the page's tracked space. The
1907
2061
  * response also includes `tenant_slug` and `tenant_name` as display labels.
1908
2062
  */
1909
2063
  BreakdownDimension: "device" | "referrer" | "page" | "browser" | "os" | "country" | "tenant";
@@ -1955,6 +2109,13 @@ export interface components {
1955
2109
  };
1956
2110
  requestBodies: never;
1957
2111
  headers: {
2112
+ /**
2113
+ * @description Present with the value `near_hard_cap` once the workspace has used 80 %
2114
+ * of its monthly API hard cap. Plan for the ceiling before requests are
2115
+ * refused with `HARD_CAP_REACHED`. Never sent to a token restricted to
2116
+ * tenants.
2117
+ */
2118
+ XPomeloUsageWarning: "near_hard_cap";
1958
2119
  /** @description Maximum requests allowed during current short window. */
1959
2120
  XRateLimitLimit: number;
1960
2121
  /** @description Remaining requests in current short window. */
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { createPomeloClient, PomeloClient } from './client.js';
2
- export type { ApiPath, ApiData, ApiParams, TenantsParams, TimeseriesParams, BreakdownParams, OverviewParams, ContentParams, AcquisitionParams, ActionsParams, GoalsParams, GoalConversionsParams, UsageHistoryParams } from './client.js';
2
+ export type { ApiPath, ApiData, ApiParams, TenantsParams, TenantsWriteBody, TenantsWriteData, TimeseriesParams, BreakdownParams, OverviewParams, ContentParams, AcquisitionParams, ActionsParams, GoalsParams, GoalConversionsParams, UsageHistoryParams } from './client.js';
3
3
  export type { components, paths } from './generated/openapi.js';
4
4
  export { PomeloApiError, PomeloTransportError } from './errors.js';
5
5
  export type { ApiResponse, Fetch, PomeloClientOptions, RequestOptions, ResponseMetadata, TransportErrorCode } from './types.js';
@@ -5,5 +5,7 @@ export declare class Transport {
5
5
  #private;
6
6
  constructor(options: PomeloClientOptions);
7
7
  get<T>(path: string, query: Query, options?: RequestOptions): Promise<ApiResponse<T>>;
8
+ /** Single JSON POST. Only used for the reviewed `POST /v1/tenants` operation. */
9
+ post<T>(path: string, body: object, options?: RequestOptions): Promise<ApiResponse<T>>;
8
10
  }
9
11
  export {};
package/dist/transport.js CHANGED
@@ -61,7 +61,14 @@ export class Transport {
61
61
  throw new PomeloTransportError('INVALID_OPTIONS');
62
62
  }
63
63
  }
64
- async get(path, query, options = {}) {
64
+ get(path, query, options = {}) {
65
+ return this.#request('GET', path, query, undefined, options);
66
+ }
67
+ /** Single JSON POST. Only used for the reviewed `POST /v1/tenants` operation. */
68
+ post(path, body, options = {}) {
69
+ return this.#request('POST', path, {}, body, options);
70
+ }
71
+ async #request(method, path, query, body, options) {
65
72
  assertServer();
66
73
  if (!/^\/v1\/[a-z/]+$/.test(path) || (options.requestId !== undefined && !identifier.test(options.requestId))) {
67
74
  throw new PomeloTransportError('INVALID_OPTIONS');
@@ -77,6 +84,18 @@ export class Transport {
77
84
  const requestId = options.requestId ?? globalThis.crypto.randomUUID();
78
85
  const headers = new Headers({ Accept: 'application/json', Authorization: `Bearer ${this.#token}` });
79
86
  headers.set('X-Request-Id', requestId);
87
+ let serialized;
88
+ if (body !== undefined) {
89
+ try {
90
+ serialized = JSON.stringify(body);
91
+ }
92
+ catch {
93
+ throw new PomeloTransportError('INVALID_OPTIONS');
94
+ }
95
+ if (typeof serialized !== 'string')
96
+ throw new PomeloTransportError('INVALID_OPTIONS');
97
+ headers.set('Content-Type', 'application/json');
98
+ }
80
99
  const controller = new AbortController();
81
100
  let timedOut = false;
82
101
  const abort = () => controller.abort();
@@ -89,7 +108,7 @@ export class Transport {
89
108
  controller.signal.addEventListener('abort', abortRequest, { once: true });
90
109
  });
91
110
  try {
92
- const response = await Promise.race([this.#fetch(url, { method: 'GET', headers, signal: controller.signal, redirect: 'error', credentials: 'omit', cache: 'no-store' }), aborted]);
111
+ const response = await Promise.race([this.#fetch(url, { method, headers, ...(serialized !== undefined ? { body: serialized } : {}), signal: controller.signal, redirect: 'error', credentials: 'omit', cache: 'no-store' }), aborted]);
93
112
  metadata = responseMetadata(response.headers, requestId);
94
113
  let payload;
95
114
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pomeloanalytics/api",
3
- "version": "0.1.0-beta.4",
3
+ "version": "0.1.0-beta.5",
4
4
  "description": "TypeScript client for reading Pomelo Analytics reports, sites and goals from Node.js servers.",
5
5
  "homepage": "https://www.pomeloanalytics.com/",
6
6
  "keywords": ["pomelo", "analytics", "web-analytics", "typescript", "nodejs", "sdk", "api-client"],