@pomeloanalytics/api 0.1.0-beta.3 → 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/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.3",
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"],