@danainnovations/directory 0.1.1 → 0.1.2

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,6 +1,6 @@
1
1
  # @danainnovations/directory
2
2
 
3
- Sonance employee directory SDK. Zero-config access to the company's active directory (synced from Okta/AD via SCIM).
3
+ Sonance employee directory SDK. Access the company's active directory (synced live from Okta/AD via SCIM).
4
4
 
5
5
  ## Install
6
6
 
@@ -8,7 +8,24 @@ Sonance employee directory SDK. Zero-config access to the company's active direc
8
8
  npm install @danainnovations/directory
9
9
  ```
10
10
 
11
- No environment variables or API keys needed. Just install and use.
11
+ ## Setup (pick one)
12
+
13
+ **Option A: Environment variable**
14
+
15
+ Add to your `.env`:
16
+ ```
17
+ DIRECTORY_KEY=your-key-here
18
+ ```
19
+
20
+ **Option B: Call `init()` at app startup**
21
+
22
+ ```ts
23
+ import { init } from '@danainnovations/directory'
24
+
25
+ init('your-key-here')
26
+ ```
27
+
28
+ Get your key from the Sonance IT team or internal wiki.
12
29
 
13
30
  ## React Hooks
14
31
 
@@ -90,16 +107,17 @@ interface UserSearchParams {
90
107
 
91
108
  ## How It Works
92
109
 
93
- This package connects directly to a Supabase database that receives live SCIM provisioning from Okta. The data updates automatically whenever IT makes changes in Okta/Active Directory (new hires, terminations, department changes, etc.). Only active employees are returned — non-person accounts (service accounts, rooms, test users) are filtered out by row-level security.
110
+ This package connects directly to a Supabase database that receives live SCIM provisioning from Okta. The data updates automatically whenever IT makes changes in Okta/Active Directory (new hires, terminations, department changes, etc.). Only active employees are returned — non-person accounts (service accounts, rooms, test users) are filtered out by row-level security. A valid directory key is required to access the data.
94
111
 
95
112
  ## AI Integration Notes
96
113
 
97
114
  When integrating this package into a project:
115
+ - **IMPORTANT**: The project must have a `DIRECTORY_KEY` env var set, or call `init("key")` before any queries. Without it, all queries return empty results.
98
116
  - Use the React hooks (`useUsers`, `useUser`, `useDepartments`, `useOrgChart`) for client components
99
117
  - Use the async functions (`getUsers`, `getUser`, `getDepartments`, `getOrgChart`) for server components, API routes, or scripts
100
118
  - All hooks return `{ loading, error }` alongside the data
101
119
  - The `useUsers` hook re-fetches automatically when search params change
102
- - No providers, context, or setup needed — just import and use
120
+ - No providers or context needed — just set the key and import
103
121
  - For people pickers / autocomplete, use `useUsers({ search: inputValue })` with a debounced input
104
122
  - For org charts, `useOrgChart()` returns a tree — each node has a `.reports[]` array of direct reports
105
123
  - For department filters, `useDepartments()` returns departments sorted alphabetically with employee counts
package/dist/index.d.mts CHANGED
@@ -38,6 +38,12 @@ interface OrgNode {
38
38
  reports: OrgNode[];
39
39
  }
40
40
 
41
+ /**
42
+ * Initialize the directory SDK with your access key.
43
+ * Alternatively, set the DIRECTORY_KEY environment variable.
44
+ */
45
+ declare function init(key: string): void;
46
+
41
47
  declare function getUsers(params?: UserSearchParams): Promise<UserSearchResult>;
42
48
  declare function getUser(emailOrId: string): Promise<DirectoryUser | null>;
43
49
  declare function getDepartments(): Promise<Department[]>;
@@ -65,4 +71,4 @@ declare function useOrgChart(): {
65
71
  error: Error | null;
66
72
  };
67
73
 
68
- export { type Department, type DirectoryUser, type OrgNode, type UserSearchParams, type UserSearchResult, getDepartments, getOrgChart, getUser, getUsers, useDepartments, useOrgChart, useUser, useUsers };
74
+ export { type Department, type DirectoryUser, type OrgNode, type UserSearchParams, type UserSearchResult, getDepartments, getOrgChart, getUser, getUsers, init, useDepartments, useOrgChart, useUser, useUsers };
package/dist/index.d.ts CHANGED
@@ -38,6 +38,12 @@ interface OrgNode {
38
38
  reports: OrgNode[];
39
39
  }
40
40
 
41
+ /**
42
+ * Initialize the directory SDK with your access key.
43
+ * Alternatively, set the DIRECTORY_KEY environment variable.
44
+ */
45
+ declare function init(key: string): void;
46
+
41
47
  declare function getUsers(params?: UserSearchParams): Promise<UserSearchResult>;
42
48
  declare function getUser(emailOrId: string): Promise<DirectoryUser | null>;
43
49
  declare function getDepartments(): Promise<Department[]>;
@@ -65,4 +71,4 @@ declare function useOrgChart(): {
65
71
  error: Error | null;
66
72
  };
67
73
 
68
- export { type Department, type DirectoryUser, type OrgNode, type UserSearchParams, type UserSearchResult, getDepartments, getOrgChart, getUser, getUsers, useDepartments, useOrgChart, useUser, useUsers };
74
+ export { type Department, type DirectoryUser, type OrgNode, type UserSearchParams, type UserSearchResult, getDepartments, getOrgChart, getUser, getUsers, init, useDepartments, useOrgChart, useUser, useUsers };
package/dist/index.js CHANGED
@@ -24,6 +24,7 @@ __export(index_exports, {
24
24
  getOrgChart: () => getOrgChart,
25
25
  getUser: () => getUser,
26
26
  getUsers: () => getUsers,
27
+ init: () => init,
27
28
  useDepartments: () => useDepartments,
28
29
  useOrgChart: () => useOrgChart,
29
30
  useUser: () => useUser,
@@ -36,12 +37,29 @@ var import_supabase_js = require("@supabase/supabase-js");
36
37
  var SUPABASE_URL = "https://vfwtukipsinfkfjtivbw.supabase.co";
37
38
  var SUPABASE_ANON_KEY = "sb_publishable_V0y4tzcVuftRGEAdvwHloA_iQf7tPUz";
38
39
  var client = null;
40
+ var directoryKey = null;
41
+ function init(key) {
42
+ directoryKey = key;
43
+ client = null;
44
+ }
45
+ function getKey() {
46
+ const key = directoryKey || typeof process !== "undefined" && process.env?.DIRECTORY_KEY || "";
47
+ if (!key) {
48
+ console.warn('[@danainnovations/directory] No DIRECTORY_KEY set. Call init("your-key") or set the DIRECTORY_KEY env var.');
49
+ }
50
+ return key;
51
+ }
39
52
  function getDirectoryClient() {
40
53
  if (!client) {
41
54
  client = (0, import_supabase_js.createClient)(SUPABASE_URL, SUPABASE_ANON_KEY, {
42
55
  auth: {
43
56
  autoRefreshToken: false,
44
57
  persistSession: false
58
+ },
59
+ global: {
60
+ headers: {
61
+ "x-directory-key": getKey()
62
+ }
45
63
  }
46
64
  });
47
65
  }
@@ -238,6 +256,7 @@ function useOrgChart() {
238
256
  getOrgChart,
239
257
  getUser,
240
258
  getUsers,
259
+ init,
241
260
  useDepartments,
242
261
  useOrgChart,
243
262
  useUser,
package/dist/index.mjs CHANGED
@@ -3,12 +3,29 @@ import { createClient } from "@supabase/supabase-js";
3
3
  var SUPABASE_URL = "https://vfwtukipsinfkfjtivbw.supabase.co";
4
4
  var SUPABASE_ANON_KEY = "sb_publishable_V0y4tzcVuftRGEAdvwHloA_iQf7tPUz";
5
5
  var client = null;
6
+ var directoryKey = null;
7
+ function init(key) {
8
+ directoryKey = key;
9
+ client = null;
10
+ }
11
+ function getKey() {
12
+ const key = directoryKey || typeof process !== "undefined" && process.env?.DIRECTORY_KEY || "";
13
+ if (!key) {
14
+ console.warn('[@danainnovations/directory] No DIRECTORY_KEY set. Call init("your-key") or set the DIRECTORY_KEY env var.');
15
+ }
16
+ return key;
17
+ }
6
18
  function getDirectoryClient() {
7
19
  if (!client) {
8
20
  client = createClient(SUPABASE_URL, SUPABASE_ANON_KEY, {
9
21
  auth: {
10
22
  autoRefreshToken: false,
11
23
  persistSession: false
24
+ },
25
+ global: {
26
+ headers: {
27
+ "x-directory-key": getKey()
28
+ }
12
29
  }
13
30
  });
14
31
  }
@@ -204,6 +221,7 @@ export {
204
221
  getOrgChart,
205
222
  getUser,
206
223
  getUsers,
224
+ init,
207
225
  useDepartments,
208
226
  useOrgChart,
209
227
  useUser,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danainnovations/directory",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Sonance employee directory — zero-config React hooks and async functions",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",