@connectedxm/admin 1.3.11 → 1.4.1

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,104 @@
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
13
+ ```
14
+
15
+ ## OPTION 1: Using the Functions directly
16
+
17
+ Here's a basic example of how to use the SDK to fetch user data:
18
+
19
+ ```typescript
20
+ import { AddAccountTier, AdminApiParams, GetAccount } from "@connectedxm/admin";
21
+
22
+ const ORGANIZATION_ID = "ORGANIZATION_ID";
23
+ const API_KEY = "API_KEY";
24
+
25
+ const ACCOUNT_ID = "INPUT_AN_ACCOUNT_ID";
26
+ const NEW_TIER_ID = "INPUT_AN_ACCOUNT_TIER_ID";
27
+
28
+ const adminApiParams: AdminApiParams = {
29
+ apiUrl: "https://admin-api.connected.dev",
30
+ apiKey: API_KEY,
31
+ organizationId: ORGANIZATION_ID,
32
+ };
33
+
34
+ // Example: Get account
35
+ let { data: account } = await GetAccount({
36
+ accountId: ACCOUNT_ID,
37
+ adminApiParams,
38
+ });
39
+
40
+ console.log(JSON.stringify(account, null, 2));
41
+
42
+ // Example: Add account tier
43
+ let { data } = await AddAccountTier({
44
+ adminApiParams,
45
+ accountId: ACCOUNT_ID,
46
+ tierId: NEW_TIER_ID,
47
+ });
48
+
49
+ console.log(JSON.stringify(data, null, 2));
50
+ ```
51
+
52
+ ## OPTION: 2 Using with React Query Hooks
53
+
54
+ First wrap your application in both QueryClientProvider and a ConnectedXMProvider
55
+
56
+ ```tsx
57
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
58
+ import { ConnectedXMProvider } from "@connectedxm/admin";
59
+
60
+ export default function App({ Component, pageProps }: AppProps) {
61
+ const [queryClient] = React.useState(new QueryClient());
62
+
63
+ const getToken = (): string => {
64
+ // GETS YOUR ACCESS TOKEN FOR THE SIGNED IN USER
65
+ return "ACCESS_TOKEN";
66
+ };
67
+
68
+ return (
69
+ <QueryClientProvider client={queryClient}>
70
+ <ConnectedXMProvider
71
+ queryClient={queryClient}
72
+ organizationId={YOUR_ORGANIZATION_ID}
73
+ apiUrl="https://admin-api.connected.dev"
74
+ getToken={GetAccessToken}
75
+
76
+ // OPTIONAL TRIGGERS
77
+ // onNotAuthorized={}
78
+ // onModuleForbidden={}
79
+ // onNotFound={}
80
+ // onMutationError={}
81
+ >
82
+ {" YOUR APP GOES HERE"}
83
+ </ConnectedXMProvider>
84
+ </QueryClientProvider>
85
+ );
86
+ }
87
+ ```
88
+
89
+ Inside of any react component you can use the exported react-query hook
90
+
91
+ ```tsx
92
+ const Component = ({ accountId }: { accountId: string }) => {
93
+ const { data: account, isLoading, isError, error } = useGetAccount(accountId);
94
+
95
+ if (isLoading) return <Loader />;
96
+ if (isError) return <ErrorComponent error={error} />;
97
+
98
+ return (
99
+ <div>
100
+ <p>{account.name}</p>
101
+ </div>
102
+ );
103
+ };
104
+ ```
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.1",
4
4
  "description": "Admin API javascript SDK",
5
5
  "author": "ConnectedXM Inc.",
6
6
  "repository": {