@doow/track 0.1.4 → 0.1.10

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.
@@ -220,5 +220,371 @@ declare class FileOfflineStore implements OfflineStore {
220
220
  get directory(): string;
221
221
  }
222
222
 
223
- export { DoowTracker, FileOfflineStore };
224
- export type { BatchPayload, CustomTransport, DoowTrackerOptions, OfflineStore, PartialAcceptResponse, RateLimit, SdkError, SdkErrorKind, SerializedBatch, SerializedEvent, TrackEvent, TransportPayload, TransportResponse };
223
+ /**
224
+ * Types for SDK Management API (CRUD operations for apps, contracts, licenses, metrics)
225
+ */
226
+ interface PaginationParams {
227
+ cursor?: string;
228
+ limit?: number;
229
+ }
230
+ interface PaginatedResponse<T> {
231
+ data: T[];
232
+ cursor?: string;
233
+ has_more: boolean;
234
+ }
235
+ interface CreateAppInput {
236
+ name: string;
237
+ description?: string;
238
+ website?: string;
239
+ logo_url?: string;
240
+ categories?: string[];
241
+ }
242
+ interface UpdateAppInput {
243
+ name?: string;
244
+ description?: string;
245
+ website?: string;
246
+ logo_url?: string;
247
+ categories?: string[];
248
+ }
249
+ interface App {
250
+ id: string;
251
+ name: string;
252
+ description?: string;
253
+ website?: string;
254
+ logo_url?: string;
255
+ categories?: string[];
256
+ saas_application_id: string;
257
+ created_at: string;
258
+ updated_at: string;
259
+ }
260
+ interface ListAppsParams extends PaginationParams {
261
+ name?: string;
262
+ }
263
+ type ContractType = 'PAY_AS_YOU_GO' | 'ENTERPRISE' | 'UNKNOWN';
264
+ type CostAmortization = 'PRORATA' | 'MONTHS' | 'QUARTER' | 'YEARS';
265
+ interface Expense {
266
+ id: string;
267
+ app_id: string | null;
268
+ contract_id: string | null;
269
+ license_id: string | null;
270
+ total: number;
271
+ date: string;
272
+ month: number;
273
+ year: number;
274
+ description: string | null;
275
+ transaction_id: string | null;
276
+ vendor: string | null;
277
+ payment_channel: string | null;
278
+ created_at: string;
279
+ updated_at: string | null;
280
+ }
281
+ interface ListExpensesParams extends PaginationParams {
282
+ app_id?: string;
283
+ contract_id?: string;
284
+ year?: number;
285
+ month?: number;
286
+ }
287
+ /**
288
+ * Input for creating a license inline with a contract.
289
+ *
290
+ * SDK only supports USAGE_BASED licenses — SEAT_BASED must be created via UI.
291
+ * total_cost is optional (calculated from usage metrics).
292
+ */
293
+ interface LicenseInput {
294
+ name: string;
295
+ /** Defaults to USAGE_BASED. SDK only supports USAGE_BASED. */
296
+ license_type?: LicenseType;
297
+ seats?: number;
298
+ price_per_seat?: number;
299
+ total_cost?: number;
300
+ discount?: Record<string, unknown>;
301
+ discount_amount?: number;
302
+ discounted_cost?: number;
303
+ original_cost?: number;
304
+ tenure?: number;
305
+ seats_included_in_base_plan?: number;
306
+ }
307
+ /**
308
+ * License in contract response. Uses AllLicenseType since responses may include
309
+ * UI-created SEAT_BASED licenses.
310
+ */
311
+ interface LicenseInContract {
312
+ id: string;
313
+ name: string;
314
+ license_type: AllLicenseType;
315
+ seats?: number;
316
+ price_per_seat?: number;
317
+ total_cost?: number;
318
+ discount?: Record<string, unknown>;
319
+ discount_amount?: number;
320
+ discounted_cost?: number;
321
+ original_cost?: number;
322
+ tenure?: number;
323
+ seats_included_in_base_plan?: number;
324
+ }
325
+ interface CreateContractInput {
326
+ title?: string;
327
+ contract_type?: ContractType;
328
+ start_date?: string;
329
+ end_date?: string;
330
+ currency?: string;
331
+ cost?: number;
332
+ cost_break_down?: Record<string, unknown>;
333
+ cost_amortization?: CostAmortization;
334
+ add_ons?: Record<string, unknown>;
335
+ add_ons_total_cost?: number;
336
+ total_contract_cost?: number;
337
+ total_discount_amount?: number;
338
+ total_original_cost?: number;
339
+ licenses: LicenseInput[];
340
+ expense_ids?: string[];
341
+ }
342
+ interface UpdateContractInput {
343
+ title?: string;
344
+ contract_type?: ContractType;
345
+ start_date?: string;
346
+ end_date?: string;
347
+ currency?: string;
348
+ cost?: number;
349
+ cost_break_down?: Record<string, unknown>;
350
+ cost_amortization?: CostAmortization;
351
+ add_ons?: Record<string, unknown>;
352
+ add_ons_total_cost?: number;
353
+ total_contract_cost?: number;
354
+ total_discount_amount?: number;
355
+ total_original_cost?: number;
356
+ }
357
+ interface Contract {
358
+ id: string;
359
+ app_id: string;
360
+ title: string;
361
+ contract_type: ContractType;
362
+ start_date?: string;
363
+ end_date?: string;
364
+ currency?: string;
365
+ cost?: number;
366
+ cost_break_down?: Record<string, unknown>;
367
+ cost_amortization?: CostAmortization;
368
+ add_ons?: Record<string, unknown>;
369
+ add_ons_total_cost?: number;
370
+ total_contract_cost?: number;
371
+ total_discount_amount?: number;
372
+ total_original_cost?: number;
373
+ licenses?: LicenseInContract[];
374
+ expenses?: Expense[];
375
+ created_at: string;
376
+ updated_at: string;
377
+ }
378
+ interface ListContractsParams extends PaginationParams {
379
+ contract_type?: ContractType;
380
+ }
381
+ /**
382
+ * License types for SDK creation. SDK only supports USAGE_BASED.
383
+ * SEAT_BASED licenses must be created via the UI.
384
+ */
385
+ type LicenseType = 'USAGE_BASED';
386
+ /**
387
+ * All license types (for responses that may include UI-created licenses)
388
+ */
389
+ type AllLicenseType = 'USAGE_BASED' | 'SEAT_BASED' | 'PREPAID_CREDITS' | 'FLAT_RATE';
390
+ interface CreateLicenseInput {
391
+ name: string;
392
+ license_type?: LicenseType;
393
+ seats?: number;
394
+ price_per_seat?: number;
395
+ total_cost?: number;
396
+ discount?: Record<string, unknown>;
397
+ discount_amount?: number;
398
+ discounted_cost?: number;
399
+ original_cost?: number;
400
+ tenure?: number;
401
+ seats_included_in_base_plan?: number;
402
+ }
403
+ interface UpdateLicenseInput {
404
+ name?: string;
405
+ license_type?: LicenseType;
406
+ seats?: number;
407
+ price_per_seat?: number;
408
+ total_cost?: number;
409
+ discount?: Record<string, unknown>;
410
+ discount_amount?: number;
411
+ discounted_cost?: number;
412
+ original_cost?: number;
413
+ tenure?: number;
414
+ seats_included_in_base_plan?: number;
415
+ }
416
+ /**
417
+ * License response. Uses AllLicenseType since responses may include
418
+ * UI-created SEAT_BASED licenses.
419
+ */
420
+ interface License {
421
+ id: string;
422
+ contract_id: string;
423
+ name: string;
424
+ license_type: AllLicenseType;
425
+ seats?: number;
426
+ price_per_seat?: number;
427
+ total_cost?: number;
428
+ discount?: Record<string, unknown>;
429
+ discount_amount?: number;
430
+ discounted_cost?: number;
431
+ original_cost?: number;
432
+ tenure?: number;
433
+ seats_included_in_base_plan?: number;
434
+ }
435
+ interface ListLicensesParams extends PaginationParams {
436
+ license_type?: AllLicenseType;
437
+ }
438
+ type UsageAggregationType = 'SUM' | 'MAX' | 'CUMULATIVE';
439
+ type RateKind = 'PER_UNIT' | 'FLAT_FEE' | 'PER_SEAT' | 'TIERED' | 'VOLUME';
440
+ type EntitlementPeriod = 'MONTHLY' | 'YEARLY' | 'QUARTERLY' | 'WEEKLY' | 'DAILY' | 'ONE_TIME';
441
+ type CarryoverPolicy = 'EXPIRE_AT_PERIOD_END' | 'ROLLOVER' | 'ROLLOVER_CAPPED';
442
+ interface CreateMetricInput {
443
+ metric_type: string;
444
+ usage_aggregation_type?: UsageAggregationType;
445
+ rate_kind?: RateKind;
446
+ entitlement_period?: EntitlementPeriod;
447
+ carryover_policy?: CarryoverPolicy;
448
+ usage_rate?: number;
449
+ usage_limit?: number;
450
+ usage_included?: number;
451
+ per_unit_cap?: number;
452
+ usage_rate_is_estimated?: boolean;
453
+ usage_custom_unit_label?: string;
454
+ expected_emission_interval_minutes?: number;
455
+ }
456
+ interface UpdateMetricInput {
457
+ metric_type?: string;
458
+ usage_aggregation_type?: UsageAggregationType;
459
+ rate_kind?: RateKind;
460
+ entitlement_period?: EntitlementPeriod;
461
+ carryover_policy?: CarryoverPolicy;
462
+ usage_rate?: number;
463
+ usage_limit?: number;
464
+ usage_included?: number;
465
+ per_unit_cap?: number;
466
+ usage_rate_is_estimated?: boolean;
467
+ usage_custom_unit_label?: string;
468
+ expected_emission_interval_minutes?: number;
469
+ }
470
+ interface Metric {
471
+ id: string;
472
+ license_id: string;
473
+ metric_type: string;
474
+ usage_aggregation_type: UsageAggregationType;
475
+ rate_kind: RateKind;
476
+ entitlement_period: EntitlementPeriod;
477
+ carryover_policy: CarryoverPolicy;
478
+ usage_rate?: number;
479
+ usage_limit?: number;
480
+ usage_included?: number;
481
+ per_unit_cap?: number;
482
+ usage_rate_is_estimated?: boolean;
483
+ usage_custom_unit_label?: string;
484
+ expected_emission_interval_minutes?: number;
485
+ created_at: string;
486
+ updated_at: string;
487
+ }
488
+ interface ListMetricsParams extends PaginationParams {
489
+ metric_type?: string;
490
+ }
491
+ interface DoowManagementOptions {
492
+ /** Server endpoint. Default: https://api.doow.co */
493
+ endpoint?: string;
494
+ /** Request timeout in ms. Default: 30000 */
495
+ timeout?: number;
496
+ /** Enable debug logging */
497
+ debug?: boolean;
498
+ }
499
+ interface ApiError {
500
+ status: number;
501
+ message: string;
502
+ code?: string;
503
+ details?: Record<string, unknown>;
504
+ }
505
+
506
+ /**
507
+ * DoowManagement — CRUD operations for apps, contracts, licenses, and metrics
508
+ *
509
+ * Usage:
510
+ * import { DoowManagement } from '@doow/track';
511
+ * const mgmt = new DoowManagement('dk_your_api_key');
512
+ *
513
+ * // Create an app
514
+ * const app = await mgmt.apps.create({ name: 'My SaaS' });
515
+ *
516
+ * // Create a contract under the app
517
+ * const contract = await mgmt.contracts.create(app.id, { title: 'Enterprise Plan' });
518
+ *
519
+ * // Create a license under the contract
520
+ * const license = await mgmt.licenses.create(contract.id, { name: 'API Usage' });
521
+ *
522
+ * // Create a metric under the license
523
+ * const metric = await mgmt.metrics.create(license.id, { metric_type: 'api_calls' });
524
+ */
525
+
526
+ declare class ManagementApiError extends Error {
527
+ readonly status: number;
528
+ readonly code?: string | undefined;
529
+ readonly details?: Record<string, unknown> | undefined;
530
+ constructor(error: ApiError);
531
+ }
532
+ declare class DoowManagement {
533
+ private readonly _apiKey;
534
+ private readonly _endpoint;
535
+ private readonly _timeout;
536
+ private readonly _debug;
537
+ readonly apps: AppsClient;
538
+ readonly contracts: ContractsClient;
539
+ readonly licenses: LicensesClient;
540
+ readonly metrics: MetricsClient;
541
+ readonly expenses: ExpensesClient;
542
+ constructor(apiKey: string, options?: DoowManagementOptions);
543
+ private log;
544
+ request<T>(method: string, path: string, body?: Record<string, unknown>, query?: Record<string, string | number | undefined>): Promise<T>;
545
+ }
546
+ declare class AppsClient {
547
+ private readonly mgmt;
548
+ constructor(mgmt: DoowManagement);
549
+ create(input: CreateAppInput): Promise<App>;
550
+ list(params?: ListAppsParams): Promise<PaginatedResponse<App>>;
551
+ get(id: string): Promise<App>;
552
+ update(id: string, input: UpdateAppInput): Promise<App>;
553
+ delete(id: string): Promise<void>;
554
+ }
555
+ declare class ContractsClient {
556
+ private readonly mgmt;
557
+ constructor(mgmt: DoowManagement);
558
+ create(appId: string, input: CreateContractInput): Promise<Contract>;
559
+ listByApp(appId: string, params?: ListContractsParams): Promise<PaginatedResponse<Contract>>;
560
+ get(id: string): Promise<Contract>;
561
+ update(id: string, input: UpdateContractInput): Promise<Contract>;
562
+ delete(id: string): Promise<void>;
563
+ }
564
+ declare class LicensesClient {
565
+ private readonly mgmt;
566
+ constructor(mgmt: DoowManagement);
567
+ create(contractId: string, input: CreateLicenseInput): Promise<License>;
568
+ listByContract(contractId: string, params?: ListLicensesParams): Promise<PaginatedResponse<License>>;
569
+ get(id: string): Promise<License>;
570
+ update(id: string, input: UpdateLicenseInput): Promise<License>;
571
+ delete(id: string): Promise<void>;
572
+ }
573
+ declare class MetricsClient {
574
+ private readonly mgmt;
575
+ constructor(mgmt: DoowManagement);
576
+ create(licenseId: string, input: CreateMetricInput): Promise<Metric>;
577
+ listByLicense(licenseId: string, params?: ListMetricsParams): Promise<PaginatedResponse<Metric>>;
578
+ get(id: string): Promise<Metric>;
579
+ update(id: string, input: UpdateMetricInput): Promise<Metric>;
580
+ delete(id: string): Promise<void>;
581
+ }
582
+ declare class ExpensesClient {
583
+ private readonly mgmt;
584
+ constructor(mgmt: DoowManagement);
585
+ list(params?: ListExpensesParams): Promise<PaginatedResponse<Expense>>;
586
+ get(id: string): Promise<Expense>;
587
+ }
588
+
589
+ export { DoowManagement, DoowTracker, FileOfflineStore, ManagementApiError };
590
+ export type { ApiError, App, BatchPayload, CarryoverPolicy, Contract, ContractType, CostAmortization, CreateAppInput, CreateContractInput, CreateLicenseInput, CreateMetricInput, CustomTransport, DoowManagementOptions, DoowTrackerOptions, EntitlementPeriod, Expense, License, LicenseInContract, LicenseInput, LicenseType, ListAppsParams, ListContractsParams, ListExpensesParams, ListLicensesParams, ListMetricsParams, Metric, OfflineStore, PaginatedResponse, PaginationParams, PartialAcceptResponse, RateKind, RateLimit, SdkError, SdkErrorKind, SerializedBatch, SerializedEvent, TrackEvent, TransportPayload, TransportResponse, UpdateAppInput, UpdateContractInput, UpdateLicenseInput, UpdateMetricInput, UsageAggregationType };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doow/track",
3
- "version": "0.1.4",
3
+ "version": "0.1.10",
4
4
  "description": "Customer-facing SDK for emitting usage telemetry to Doow",
5
5
  "license": "MIT",
6
6
  "author": "Doow",