@terros-inc/sdk 1.0.2 → 1.0.3

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.
@@ -0,0 +1,12 @@
1
+ import { type ApiRoute } from './models';
2
+ export type ClientConfig = {
3
+ apiKey?: string;
4
+ baseUrl?: string;
5
+ };
6
+ export declare class ApiCaller {
7
+ private readonly baseUrl;
8
+ private readonly auth;
9
+ private readonly analytics;
10
+ constructor(config: ClientConfig);
11
+ call<Success>(route: ApiRoute, input: object): Promise<Success>;
12
+ }
@@ -0,0 +1,44 @@
1
+ import { isResponseError } from './models';
2
+ import { getAnalyticsHeaders } from './analytics';
3
+ const PROD_BASE_URL = 'https://api.terros.com';
4
+ export class ApiCaller {
5
+ baseUrl;
6
+ auth;
7
+ analytics;
8
+ constructor(config) {
9
+ this.baseUrl = config.baseUrl ?? readProcessEnv('TERROS_SDK_BASE_URL') ?? PROD_BASE_URL;
10
+ this.analytics = getAnalyticsHeaders();
11
+ const auth = config.apiKey ?? readProcessEnv('TERROS_API_KEY');
12
+ if (!auth)
13
+ throw new Error('No auth provided: set TERROS_API_KEY or pass config.auth');
14
+ this.auth = auth;
15
+ }
16
+ async call(route, input) {
17
+ let response;
18
+ try {
19
+ response = await fetch(`${this.baseUrl}/${route}`, {
20
+ method: 'POST',
21
+ headers: {
22
+ ...this.analytics,
23
+ 'Content-Type': 'application/json',
24
+ authorization: `ApiKey ${this.auth}`,
25
+ },
26
+ body: JSON.stringify(input),
27
+ });
28
+ }
29
+ catch (cause) {
30
+ throw new Error(`Request to ${route} failed`, { cause });
31
+ }
32
+ if (!response.ok)
33
+ throw new Error(response.statusText);
34
+ const output = await response.json();
35
+ if (isResponseError(output))
36
+ throw new Error(output.message ?? output.error);
37
+ return output;
38
+ }
39
+ }
40
+ function readProcessEnv(key) {
41
+ if (typeof globalThis.process === 'undefined')
42
+ return undefined;
43
+ return globalThis.process.env[key];
44
+ }
package/dist/client.d.ts CHANGED
@@ -1,16 +1,5 @@
1
- import { type ApiRoute } from './models/index.ts';
2
- import { AccountClient, CalendarClient, UserClient } from './clients/index.ts';
3
- export type ClientConfig = {
4
- apiKey?: string;
5
- baseUrl?: string;
6
- };
7
- export declare class ApiCaller {
8
- private readonly baseUrl;
9
- private readonly auth;
10
- private readonly analytics;
11
- constructor(config: ClientConfig);
12
- call<Success>(route: ApiRoute, input: object): Promise<Success>;
13
- }
1
+ import { UserClient, AccountClient, CalendarClient } from './clients';
2
+ import { type ClientConfig } from './apiCaller';
14
3
  export declare class TerrosClient {
15
4
  readonly user: UserClient;
16
5
  readonly account: AccountClient;
package/dist/client.js CHANGED
@@ -1,48 +1,5 @@
1
- import { isResponseError } from "./models/index.js";
2
- import { AccountClient, CalendarClient, UserClient } from "./clients/index.js";
3
- import { getAnalyticsHeaders } from "./analytics.js";
4
- const PROD_BASE_URL = 'https://api.terros.com';
5
- export class ApiCaller {
6
- baseUrl;
7
- auth;
8
- analytics;
9
- constructor(config) {
10
- this.baseUrl = config.baseUrl ?? readProcessEnv('TERROS_SDK_BASE_URL') ?? PROD_BASE_URL;
11
- this.analytics = getAnalyticsHeaders();
12
- const auth = config.apiKey ?? readProcessEnv('TERROS_API_KEY');
13
- if (!auth)
14
- throw new Error('No auth provided: set TERROS_API_KEY or pass config.auth');
15
- this.auth = auth;
16
- }
17
- async call(route, input) {
18
- let response;
19
- try {
20
- response = await fetch(`${this.baseUrl}/${route}`, {
21
- method: 'POST',
22
- headers: {
23
- ...this.analytics,
24
- 'Content-Type': 'application/json',
25
- authorization: `ApiKey ${this.auth}`,
26
- },
27
- body: JSON.stringify(input),
28
- });
29
- }
30
- catch (cause) {
31
- throw new Error(`Request to ${route} failed`, { cause });
32
- }
33
- if (!response.ok)
34
- throw new Error(response.statusText);
35
- const output = await response.json();
36
- if (isResponseError(output))
37
- throw new Error(output.message ?? output.error);
38
- return output;
39
- }
40
- }
41
- function readProcessEnv(key) {
42
- if (typeof globalThis.process === 'undefined')
43
- return undefined;
44
- return globalThis.process.env[key];
45
- }
1
+ import { UserClient, AccountClient, CalendarClient } from './clients';
2
+ import { ApiCaller } from './apiCaller';
46
3
  export class TerrosClient {
47
4
  user;
48
5
  account;
@@ -1,5 +1,5 @@
1
1
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
- import { ApiCaller } from "./client.js";
2
+ import { ApiCaller } from './apiCaller';
3
3
  describe('ApiCaller', () => {
4
4
  const originalFetch = globalThis.fetch;
5
5
  afterEach(() => {
@@ -1,6 +1,5 @@
1
- import type { ApiSuccess } from '../models/shared.ts';
2
- import type { AccountAddInput, AccountAddSuccess, AccountGetInput, AccountGetSuccess, AccountListInput, AccountListSuccess, AccountMatchInput, AccountMatchSuccess, AccountRemoveInput, AccountStatusAddInput, AccountStatusAddSuccess, AccountStatusListInput, AccountStatusListSuccess, AccountStatusRemoveInput, AccountStatusUpdateInput, AccountStatusUpdateSuccess, AccountUpdateBatchInput, AccountUpdateBatchSuccess, AccountUpdateInput, AccountUpdateSuccess, AccountUpsertInput, AccountUpsertSuccess, BulkModifyAccountsInput } from '../models/account/api.ts';
3
- import type { ApiCaller } from '../client.ts';
1
+ import { type AccountStatusAddInput, type AccountStatusAddSuccess, type AccountStatusUpdateInput, type AccountStatusUpdateSuccess, type AccountStatusListInput, type AccountStatusListSuccess, type AccountStatusRemoveInput, type ApiSuccess, type AccountAddInput, type AccountAddSuccess, type AccountUpdateInput, type AccountUpdateSuccess, type AccountUpdateBatchInput, type AccountUpdateBatchSuccess, type AccountListInput, type AccountListSuccess, type BulkModifyAccountsInput, type AccountGetInput, type AccountGetSuccess, type AccountMatchInput, type AccountMatchSuccess, type AccountRemoveInput, type AccountUpsertInput, type AccountUpsertSuccess } from '../models';
2
+ import { type ApiCaller } from '../apiCaller';
4
3
  export declare class AccountStatusClient {
5
4
  private readonly api;
6
5
  constructor(api: ApiCaller);
@@ -1,6 +1,5 @@
1
- import type { ApiSuccess } from '../models/shared.ts';
2
- import type { CalendarAvailabilityInput, CalendarAvailabilitySuccess, CalendarClosersInput, CalendarClosersSuccess, CalendarEventAddInput, CalendarEventAddSuccess, CalendarEventConfirmInput, CalendarEventConfirmSuccess, CalendarEventGetInput, CalendarEventGetSuccess, CalendarEventListInput, CalendarEventListSuccess, CalendarEventRemoveInput, CalendarEventUpdateInput, CalendarEventUpdateSuccess, CalendarEventUpsertInput, CalendarEventUpsertSuccess, CalendarTimeslotsInput, CalendarTimeslotsSuccess } from '../models/calendar/api.ts';
3
- import type { ApiCaller } from '../client.ts';
1
+ import { type CalendarEventAddInput, type CalendarEventAddSuccess, type CalendarEventGetInput, type CalendarEventGetSuccess, type CalendarEventListInput, type CalendarEventListSuccess, type CalendarEventUpdateInput, type CalendarEventUpdateSuccess, type CalendarEventUpsertInput, type CalendarEventUpsertSuccess, type CalendarEventConfirmInput, type CalendarEventConfirmSuccess, type CalendarEventRemoveInput, type ApiSuccess, type CalendarAvailabilityInput, type CalendarAvailabilitySuccess, type CalendarClosersInput, type CalendarClosersSuccess, type CalendarTimeslotsInput, type CalendarTimeslotsSuccess } from '../models';
2
+ import { type ApiCaller } from '../apiCaller';
4
3
  export declare class CalendarEventClient {
5
4
  private readonly api;
6
5
  constructor(api: ApiCaller);
@@ -1,3 +1,3 @@
1
- export * from './account.ts';
2
- export * from './calendar.ts';
3
- export * from './user.ts';
1
+ export * from './account';
2
+ export * from './calendar';
3
+ export * from './user';
@@ -1,3 +1,3 @@
1
- export * from "./account.js";
2
- export * from "./calendar.js";
3
- export * from "./user.js";
1
+ export * from './account';
2
+ export * from './calendar';
3
+ export * from './user';
@@ -1,6 +1,5 @@
1
- import type { UserAddInput, UserAddSuccess, UserBulkUpdateInput, UserBulkUpdateSuccess, UserClosersInput, UserClosersSuccess, UserGetInput, UserGetSuccess, UserListInput, UserListSuccess, UserManagerInput, UserManagerSuccess, UserProfileInput, UserProfileSuccess, UserRemoveInput, UserReportInput, UserReportSuccess, UserSearchInput, UserSearchSuccess, UserTimezoneInput, UserUpdateInput, UserUpdateSuccess } from '../models/user/api.ts';
2
- import type { ApiSuccess } from '../models/shared.ts';
3
- import type { ApiCaller } from '../client.ts';
1
+ import { type UserListInput, type UserListSuccess, type UserAddInput, type UserAddSuccess, type UserUpdateInput, type UserUpdateSuccess, type UserBulkUpdateInput, type UserBulkUpdateSuccess, type UserRemoveInput, type ApiSuccess, type UserGetInput, type UserGetSuccess, type UserProfileInput, type UserProfileSuccess, type UserSearchInput, type UserSearchSuccess, type UserTimezoneInput, type UserReportInput, type UserReportSuccess, type UserClosersInput, type UserClosersSuccess, type UserManagerInput, type UserManagerSuccess } from '../models';
2
+ import { type ApiCaller } from '../apiCaller';
4
3
  export declare class UserClient {
5
4
  private readonly api;
6
5
  constructor(api: ApiCaller);
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './models/index.ts';
2
- export * from './clients/index.ts';
1
+ export * from './client';
2
+ export * from './models';
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./models/index.js";
2
- export * from "./clients/index.js";
1
+ export * from './client';
2
+ export * from './models';
@@ -1,8 +1,8 @@
1
- import type { ApiSuccess, CustomFieldMap } from '../shared.ts';
2
- import type { RoleId, SmallUser, TeamId, UserId, UserIdentifier } from '../user/model.ts';
3
- import type { LatLng } from '../location/model.ts';
4
- import type { CompanyId } from '../company/model.ts';
5
- import type { AccountData, AccountDataResponse, AccountId, AccountSortBy, AccountSortOrder, AccountStatusData, AccountStatusId, BulkModifyAccountsAction, ContactId, CustomFieldFilter, ElasticFilter, LocationId, NoteId, PartialAddress, RangeFilter, SortCursor, StatusHistoryItem, TagId, UnsavedAccount, UnsavedAccountContact, UnsavedAccountNote, UnsavedAccountStatus, UpsertLatLng, UpsertTinyResidentData, WorkflowActionId, WorkflowId, WorkflowStageId } from './model.ts';
1
+ import type { RoleId, SmallUser, TeamId, UserId, UserIdentifier } from '../user';
2
+ import type { ApiSuccess, CustomFieldMap } from '../shared';
3
+ import type { LatLng } from '../location';
4
+ import type { CompanyId } from '../company';
5
+ import type { AccountData, AccountDataResponse, AccountId, AccountSortBy, AccountSortOrder, AccountStatusData, AccountStatusId, BulkModifyAccountsAction, ContactId, CustomFieldFilter, ElasticFilter, LocationId, NoteId, PartialAddress, RangeFilter, SortCursor, StatusHistoryItem, TagId, UnsavedAccount, UnsavedAccountContact, UnsavedAccountNote, UnsavedAccountStatus, UpsertLatLng, UpsertTinyResidentData, WorkflowActionId, WorkflowId, WorkflowStageId } from './model';
6
6
  export type AccountStatusSearchInput = {
7
7
  accountIds?: AccountId[];
8
8
  workflowId?: WorkflowId;
@@ -1,2 +1,2 @@
1
- export * from './model.ts';
2
- export * from './api.ts';
1
+ export * from './model';
2
+ export * from './api';
@@ -1,2 +1,2 @@
1
- export * from "./model.js";
2
- export * from "./api.js";
1
+ export * from './model';
2
+ export * from './api';
@@ -1,6 +1,6 @@
1
- import type { RoleId, SmallUser, TeamId, UserId } from '../user/model.ts';
2
- import type { CustomFieldMap } from '../shared.ts';
3
- import type { LatLng, SmallAddress } from '../location/model.ts';
1
+ import type { RoleId, SmallUser, TeamId, UserId } from '../user';
2
+ import type { CustomFieldMap } from '../shared';
3
+ import type { LatLng, SmallAddress } from '../location';
4
4
  export type AccountId = `Account:${string}` | `Account.${string}`;
5
5
  export type AccountStatusId = `AS.${string}`;
6
6
  export type WorkflowId = `WF.${string}`;
@@ -1,8 +1,8 @@
1
- import type { ApiSuccess } from '../shared.ts';
2
- import type { AvailableCloser, RoleId, TeamId, TinyCloser, UserId } from '../user/model.ts';
3
- import type { LatLng } from '../location/model.ts';
4
- import type { AccountId, LocationId, UpsertLatLng } from '../account/model.ts';
5
- import type { CalendarEventData, CalendarEventDataWithDetails, CalendarEventId, EventType, UnsavedCalendarEventData } from './model.ts';
1
+ import type { AvailableCloser, RoleId, TeamId, TinyCloser, UserId } from '../user';
2
+ import type { ApiSuccess } from '../shared';
3
+ import type { LatLng } from '../location';
4
+ import type { AccountId, LocationId, UpsertLatLng } from '../account';
5
+ import type { CalendarEventData, CalendarEventDataWithDetails, CalendarEventId, EventType, UnsavedCalendarEventData } from './model';
6
6
  type CalendarEventRoleFilter = 'owner' | 'attendee';
7
7
  type OptionalCalendarEventLocation = UpsertLatLng & {
8
8
  locationId?: LocationId;
@@ -1,2 +1,2 @@
1
- export * from './model.ts';
2
- export * from './api.ts';
1
+ export * from './model';
2
+ export * from './api';
@@ -1,2 +1,2 @@
1
- export * from "./model.js";
2
- export * from "./api.js";
1
+ export * from './model';
2
+ export * from './api';
@@ -1,7 +1,7 @@
1
- import type { SmallUser, TeamId, UserId } from '../user/model.ts';
2
- import type { TinyTeam } from '../team/model.ts';
3
- import type { Address, LatLng } from '../location/model.ts';
4
- import type { AccountId, DispositionId, LocationId, TinyResidentData, TinyWorkflowAccount } from '../account/model.ts';
1
+ import type { SmallUser, TeamId, UserId } from '../user';
2
+ import type { TinyTeam } from '../team';
3
+ import type { Address, LatLng } from '../location';
4
+ import type { AccountId, DispositionId, LocationId, TinyResidentData, TinyWorkflowAccount } from '../account';
5
5
  export type CalendarEventId = `Event:${string}` | `Event.${string}`;
6
6
  /** @deprecated */
7
7
  export type EventOutcomeId = `O.${string}`;
@@ -1 +1 @@
1
- export * from './model.ts';
1
+ export * from './model';
@@ -1 +1 @@
1
- export * from "./model.js";
1
+ export * from './model';
@@ -1,4 +1,4 @@
1
- import type { UserId } from '../user/model.ts';
1
+ import type { UserId } from '../user';
2
2
  export type CompanyState = 'active' | 'trial' | 'internal' | 'demo' | 'sandbox' | 'template' | 'suspended';
3
3
  export type CompanyKind = 'customer' | 'sandbox' | 'demo' | 'template' | 'development';
4
4
  export type AccessStatus = 'active' | 'suspended';
@@ -1,7 +1,7 @@
1
- export * from './shared.ts';
2
- export * from './location/index.ts';
3
- export * from './team/index.ts';
4
- export * from './company/index.ts';
5
- export * from './user/index.ts';
6
- export * from './account/index.ts';
7
- export * from './calendar/index.ts';
1
+ export * from './shared';
2
+ export * from './location';
3
+ export * from './team';
4
+ export * from './company';
5
+ export * from './user';
6
+ export * from './account';
7
+ export * from './calendar';
@@ -1,7 +1,7 @@
1
- export * from "./shared.js";
2
- export * from "./location/index.js";
3
- export * from "./team/index.js";
4
- export * from "./company/index.js";
5
- export * from "./user/index.js";
6
- export * from "./account/index.js";
7
- export * from "./calendar/index.js";
1
+ export * from './shared';
2
+ export * from './location';
3
+ export * from './team';
4
+ export * from './company';
5
+ export * from './user';
6
+ export * from './account';
7
+ export * from './calendar';
@@ -1 +1 @@
1
- export * from './model.ts';
1
+ export * from './model';
@@ -1 +1 @@
1
- export * from "./model.js";
1
+ export * from './model';
@@ -1,4 +1,4 @@
1
- import type { UserId } from './user/model.ts';
1
+ import type { UserId } from './user';
2
2
  /** A Connect API route string, e.g. "user/get" or "account/status/add". */
3
3
  export type ApiRoute = string;
4
4
  export type ApiSuccess<T = unknown> = {
@@ -1 +1 @@
1
- export * from './model.ts';
1
+ export * from './model';
@@ -1 +1 @@
1
- export * from "./model.js";
1
+ export * from './model';
@@ -1,4 +1,4 @@
1
- import type { TeamId } from '../user/model.ts';
1
+ import type { TeamId } from '../user';
2
2
  export type TinyTeam = {
3
3
  teamId: TeamId;
4
4
  name: string;
@@ -1,6 +1,6 @@
1
- import type { ApiSuccess } from '../shared.ts';
2
- import type { CompanyData, CompanyId } from '../company/model.ts';
3
- import type { CloserStatus, EntityId, RoleId, SmallCloser, SmallUser, TeamId, TinyUser, UnsavedUser, UserData, UserId, UserIdentifier, UserProfileData } from './model.ts';
1
+ import type { ApiSuccess } from '../shared';
2
+ import type { CompanyData, CompanyId } from '../company';
3
+ import type { CloserStatus, EntityId, RoleId, SmallCloser, SmallUser, TeamId, TinyUser, UnsavedUser, UserData, UserId, UserIdentifier, UserProfileData } from './model';
4
4
  export type UserListInput = {
5
5
  showArchived?: true | false | 'all';
6
6
  companyId?: CompanyId;
@@ -1,2 +1,2 @@
1
- export * from './model.ts';
2
- export * from './api.ts';
1
+ export * from './model';
2
+ export * from './api';
@@ -1,2 +1,2 @@
1
- export * from "./model.js";
2
- export * from "./api.js";
1
+ export * from './model';
2
+ export * from './api';
@@ -1,7 +1,7 @@
1
- import type { TinyTeam } from '../team/model.ts';
2
- import type { AuditProps, CustomFieldMap } from '../shared.ts';
3
- import type { Address } from '../location/model.ts';
4
- import type { CompanyId } from '../company/model.ts';
1
+ import type { TinyTeam } from '../team';
2
+ import type { AuditProps, CustomFieldMap } from '../shared';
3
+ import type { Address } from '../location';
4
+ import type { CompanyId } from '../company';
5
5
  export type UserId = `U:${string}` | `U.${string}`;
6
6
  export type TeamId = `Team:${string}` | `Team.${string}`;
7
7
  export type RoleId = `Role.${string}`;
package/package.json CHANGED
@@ -24,6 +24,7 @@
24
24
  ],
25
25
  "license": "MIT",
26
26
  "main": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
27
28
  "name": "@terros-inc/sdk",
28
29
  "publishConfig": {
29
30
  "access": "public",
@@ -34,7 +35,7 @@
34
35
  "url": "git+https://github.com/terros-inc/sdk.git"
35
36
  },
36
37
  "type": "module",
37
- "version": "1.0.2",
38
+ "version": "1.0.3",
38
39
  "scripts": {
39
40
  "build": "tsc",
40
41
  "format": "oxfmt --write .",