@connectedxm/admin 1.3.11 → 1.4.0

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/README.md CHANGED
@@ -1,3 +1,106 @@
1
1
  # @connectedxm/admin-sdk
2
2
 
3
3
  A Javascript SDK for interacting with the ConnectedXM Admin API.
4
+
5
+ # Getting Started
6
+
7
+ ## Installation
8
+
9
+ To install the SDK, use npm or yarn:
10
+
11
+ ```sh
12
+ npm install @connectedxm/admin-sdk
13
+ # or
14
+ yarn add @connectedxm/admin-sdk
15
+ ```
16
+
17
+ ## Using with React Query Hooks
18
+
19
+ First wrap your application in both QueryClientProvider and a ConnectedXMProvider
20
+
21
+ ```tsx
22
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
23
+ import { ConnectedXMProvider } from "@connectedxm/admin";
24
+
25
+ export default function App({ Component, pageProps }: AppProps) {
26
+ const [queryClient] = React.useState(new QueryClient());
27
+
28
+ const getToken = (): string => {
29
+ // GETS YOUR ACCESS TOKEN FOR THE SIGNED IN USER
30
+ return "";
31
+ };
32
+
33
+ return (
34
+ <QueryClientProvider client={queryClient}>
35
+ <ConnectedXMProvider
36
+ queryClient={queryClient}
37
+ organizationId={YOUR_ORGANIZATION_ID}
38
+ apiUrl="https://admin-api.connected.dev"
39
+ getToken={GetAccessToken}
40
+
41
+ // OPTIONAL TRIGGERS
42
+ // onNotAuthorized={}
43
+ // onModuleForbidden={}
44
+ // onNotFound={}
45
+ // onMutationError={}
46
+ >
47
+ {" YOUR APP GOES HERE"}
48
+ </ConnectedXMProvider>
49
+ </QueryClientProvider>
50
+ );
51
+ }
52
+ ```
53
+
54
+ then inside of any component you can use the exported hook
55
+
56
+ ```tsx
57
+ const Component = ({ accountId }: { accountId: string }) => {
58
+ const { data: account, isLoading, isError, error } = useGetAccount(accountId);
59
+
60
+ if (isLoading) return <Loader />;
61
+ if (isError) return <ErrorComponent error={error} />;
62
+
63
+ return (
64
+ <div>
65
+ <p>{account.name}</p>
66
+ </div>
67
+ );
68
+ };
69
+ ```
70
+
71
+ ## Using the Functions directly
72
+
73
+ Here's a basic example of how to use the SDK to fetch user data:
74
+
75
+ ```typescript
76
+ import { AddAccountTier, AdminApiParams, GetAccount } from "@connectedxm/admin";
77
+
78
+ const ORGANIZATION_ID = "ORGANIZATION_ID";
79
+ const API_KEY = "API_KEY";
80
+
81
+ const ACCOUNT_ID = "INPUT_AN_ACCOUNT_ID";
82
+ const NEW_TIER_ID = "INPUT_AN_ACCOUNT_TIER_ID";
83
+
84
+ const adminApiParams: AdminApiParams = {
85
+ apiUrl: "https://admin-api.connected.dev",
86
+ apiKey: API_KEY,
87
+ organizationId: ORGANIZATION_ID,
88
+ };
89
+
90
+ // Example: Get account
91
+ let { data: account } = await GetAccount({
92
+ accountId: ACCOUNT_ID,
93
+ adminApiParams,
94
+ });
95
+
96
+ console.log(JSON.stringify(account, null, 2));
97
+
98
+ // Example: Add account tier
99
+ let { data } = await AddAccountTier({
100
+ adminApiParams,
101
+ accountId: ACCOUNT_ID,
102
+ tierId: NEW_TIER_ID,
103
+ });
104
+
105
+ console.log(JSON.stringify(data, null, 2));
106
+ ```
package/dist/index.d.mts CHANGED
@@ -2560,7 +2560,7 @@ interface Lead extends BaseLead {
2560
2560
  interface ConnectedXMClientContextState {
2561
2561
  queryClient: QueryClient;
2562
2562
  organizationId: string;
2563
- apiUrl: "https://admin-api.connectedxm.com" | "https://staging-admin-api.connectedxm.com" | "http://localhost:4001";
2563
+ apiUrl: "https://admin-api.connected.dev" | "https://staging-admin-api.connected.dev" | "http://localhost:4001";
2564
2564
  authenticated: boolean;
2565
2565
  setAuthenticated: (authenticated: boolean) => void;
2566
2566
  getToken: () => Promise<string | undefined>;
@@ -4090,9 +4090,10 @@ declare function MergeInfinitePages<TData>(data: InfiniteData<ConnectedXMRespons
4090
4090
  declare const TransformPrice: (value: number, withDollar?: boolean, freeText?: string) => string | undefined;
4091
4091
 
4092
4092
  interface AdminApiParams {
4093
- apiUrl: "https://admin-api.connectedxm.com" | "https://staging-admin-api.connectedxm.com" | "http://localhost:4001";
4093
+ apiUrl: "https://admin-api.connected.dev" | "https://staging-admin-api.connected.dev" | "http://localhost:4001";
4094
4094
  organizationId: string;
4095
- getToken: () => Promise<string | undefined> | string | undefined;
4095
+ getToken?: () => Promise<string | undefined> | string | undefined;
4096
+ apiKey?: string;
4096
4097
  getExecuteAs?: () => Promise<string | undefined> | string | undefined;
4097
4098
  }
4098
4099
  /**
package/dist/index.d.ts CHANGED
@@ -2560,7 +2560,7 @@ interface Lead extends BaseLead {
2560
2560
  interface ConnectedXMClientContextState {
2561
2561
  queryClient: QueryClient;
2562
2562
  organizationId: string;
2563
- apiUrl: "https://admin-api.connectedxm.com" | "https://staging-admin-api.connectedxm.com" | "http://localhost:4001";
2563
+ apiUrl: "https://admin-api.connected.dev" | "https://staging-admin-api.connected.dev" | "http://localhost:4001";
2564
2564
  authenticated: boolean;
2565
2565
  setAuthenticated: (authenticated: boolean) => void;
2566
2566
  getToken: () => Promise<string | undefined>;
@@ -4090,9 +4090,10 @@ declare function MergeInfinitePages<TData>(data: InfiniteData<ConnectedXMRespons
4090
4090
  declare const TransformPrice: (value: number, withDollar?: boolean, freeText?: string) => string | undefined;
4091
4091
 
4092
4092
  interface AdminApiParams {
4093
- apiUrl: "https://admin-api.connectedxm.com" | "https://staging-admin-api.connectedxm.com" | "http://localhost:4001";
4093
+ apiUrl: "https://admin-api.connected.dev" | "https://staging-admin-api.connected.dev" | "http://localhost:4001";
4094
4094
  organizationId: string;
4095
- getToken: () => Promise<string | undefined> | string | undefined;
4095
+ getToken?: () => Promise<string | undefined> | string | undefined;
4096
+ apiKey?: string;
4096
4097
  getExecuteAs?: () => Promise<string | undefined> | string | undefined;
4097
4098
  }
4098
4099
  /**
package/dist/index.js CHANGED
@@ -2139,13 +2139,14 @@ var import_react = __toESM(require("react"));
2139
2139
  // src/AdminAPI.ts
2140
2140
  var import_axios = __toESM(require("axios"));
2141
2141
  var GetAdminAPI = async (params) => {
2142
- const token = await params.getToken();
2142
+ const token = !!params.getToken && await params.getToken();
2143
2143
  const executeAs = params.getExecuteAs ? await params.getExecuteAs() : void 0;
2144
2144
  return import_axios.default.create({
2145
2145
  baseURL: params.apiUrl,
2146
2146
  headers: {
2147
2147
  organization: params.organizationId,
2148
2148
  authorization: token,
2149
+ "api-key": params.apiKey,
2149
2150
  executeAs
2150
2151
  }
2151
2152
  });
package/dist/index.mjs CHANGED
@@ -10,13 +10,14 @@ import React from "react";
10
10
  // src/AdminAPI.ts
11
11
  import axios from "axios";
12
12
  var GetAdminAPI = async (params) => {
13
- const token = await params.getToken();
13
+ const token = !!params.getToken && await params.getToken();
14
14
  const executeAs = params.getExecuteAs ? await params.getExecuteAs() : void 0;
15
15
  return axios.create({
16
16
  baseURL: params.apiUrl,
17
17
  headers: {
18
18
  organization: params.organizationId,
19
19
  authorization: token,
20
+ "api-key": params.apiKey,
20
21
  executeAs
21
22
  }
22
23
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@connectedxm/admin",
3
- "version": "1.3.11",
3
+ "version": "1.4.0",
4
4
  "description": "Admin API javascript SDK",
5
5
  "author": "ConnectedXM Inc.",
6
6
  "repository": {