@newhomestar/sdk 0.8.11 → 0.8.13
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/dist/index.js +30 -1
- package/dist/integration.d.ts +20 -0
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import dotenv from "dotenv";
|
|
2
|
+
import cors from "cors";
|
|
2
3
|
import { createClient } from "@supabase/supabase-js";
|
|
3
4
|
import { OpenFgaClient } from "@openfga/sdk";
|
|
4
5
|
import { createServer } from "node:http";
|
|
@@ -648,6 +649,17 @@ import { auth } from "express-oauth2-jwt-bearer";
|
|
|
648
649
|
*/
|
|
649
650
|
export function runHttpServer(def, opts = {}) {
|
|
650
651
|
const app = express();
|
|
652
|
+
// ── CORS (must be registered BEFORE auth so OPTIONS preflight bypasses JWKS) ──
|
|
653
|
+
// Permissive by default — integrations are called by the Odyssey admin UI
|
|
654
|
+
// from browser origins (localhost:3000, admin dashboards, etc.). The actual
|
|
655
|
+
// security boundary is the JWT Bearer token verified by JWKS below.
|
|
656
|
+
app.use(cors({
|
|
657
|
+
origin: true, // reflect request origin
|
|
658
|
+
credentials: true,
|
|
659
|
+
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
|
|
660
|
+
allowedHeaders: ['Content-Type', 'Authorization', 'X-Requested-With'],
|
|
661
|
+
maxAge: 86400,
|
|
662
|
+
}));
|
|
651
663
|
app.use(bodyParser.json());
|
|
652
664
|
// ── Determine whether auth is enabled ──
|
|
653
665
|
const skipAuth = opts.skipAuth ??
|
|
@@ -894,12 +906,29 @@ export function runHttpServer(def, opts = {}) {
|
|
|
894
906
|
// Resolve credentials (same flow as action handlers)
|
|
895
907
|
const credCtx = buildCredentialCtx(def.name, authToken);
|
|
896
908
|
const credentials = await credCtx.resolveCredentials();
|
|
897
|
-
//
|
|
909
|
+
// Extract and normalize the scope identifiers from the request body.
|
|
910
|
+
// The UI posts `{ config, remoteId, remoteType }`. Both may be null
|
|
911
|
+
// for legacy / unscoped lookups. We keep them typed so handlers
|
|
912
|
+
// using `ctx.remoteId` get proper autocomplete.
|
|
913
|
+
const rawRemoteId = req.body?.remoteId;
|
|
914
|
+
const rawRemoteType = req.body?.remoteType;
|
|
915
|
+
const remoteId = typeof rawRemoteId === 'string' && rawRemoteId.trim() !== ''
|
|
916
|
+
? rawRemoteId
|
|
917
|
+
: null;
|
|
918
|
+
const remoteType = rawRemoteType === 'account' || rawRemoteType === 'company'
|
|
919
|
+
? rawRemoteType
|
|
920
|
+
: null;
|
|
921
|
+
// Build OptionsContext for the handler. `remoteId`/`remoteType`
|
|
922
|
+
// let the handler scope its lookup to the currently-selected
|
|
923
|
+
// ticketing account / HRIS company (e.g. list only Jira
|
|
924
|
+
// projects tied to *this* account's connection).
|
|
898
925
|
const optionsCtx = {
|
|
899
926
|
fetch: credCtx.fetch,
|
|
900
927
|
config: req.body?.config ?? {},
|
|
901
928
|
credentials,
|
|
902
929
|
tenantId: req.auth?.sub ?? 'unknown',
|
|
930
|
+
remoteId,
|
|
931
|
+
remoteType,
|
|
903
932
|
};
|
|
904
933
|
// Run the optionsFetcher handler
|
|
905
934
|
console.log(`[nova] 🔧 Running optionsFetcher for config field "${field.key}"`);
|
package/dist/integration.d.ts
CHANGED
|
@@ -144,6 +144,26 @@ export interface OptionsContext {
|
|
|
144
144
|
credentials: ResolvedCredentials;
|
|
145
145
|
/** Tenant ID for calling internal Nova platform services */
|
|
146
146
|
tenantId: string;
|
|
147
|
+
/**
|
|
148
|
+
* Scope UUID this options lookup belongs to. For ticketing integrations
|
|
149
|
+
* this is the `TicketingAccount.id`; for HRIS integrations it's the
|
|
150
|
+
* `HrisCompany.id`. May be null/undefined when the caller hasn't
|
|
151
|
+
* selected a scope yet (legacy / unscoped lookups).
|
|
152
|
+
*
|
|
153
|
+
* Use this to filter the options query when the same user administers
|
|
154
|
+
* multiple accounts — e.g. only list Jira projects linked to this
|
|
155
|
+
* specific ticketing account's connection, not all of the user's
|
|
156
|
+
* accessible projects.
|
|
157
|
+
*/
|
|
158
|
+
remoteId?: string | null;
|
|
159
|
+
/**
|
|
160
|
+
* Scope type discriminator so the handler knows which domain the
|
|
161
|
+
* `remoteId` came from without having to infer it from the integration
|
|
162
|
+
* category.
|
|
163
|
+
* • "account" → ticketing (TicketingAccount.id)
|
|
164
|
+
* • "company" → HRIS (HrisCompany.id)
|
|
165
|
+
*/
|
|
166
|
+
remoteType?: 'account' | 'company' | null;
|
|
147
167
|
}
|
|
148
168
|
/**
|
|
149
169
|
* A handler function that fetches select options dynamically.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newhomestar/sdk",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.13",
|
|
4
4
|
"description": "Type-safe SDK for building Nova pipelines (workers & functions)",
|
|
5
5
|
"homepage": "https://github.com/newhomestar/nova-node-sdk#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"@orpc/server": "1.7.4",
|
|
42
42
|
"@supabase/supabase-js": "^2.39.0",
|
|
43
43
|
"body-parser": "^1.20.2",
|
|
44
|
+
"cors": "^2.8.6",
|
|
44
45
|
"dotenv": "^16.4.3",
|
|
45
46
|
"express": "^4.18.2",
|
|
46
47
|
"express-oauth2-jwt-bearer": "^1.7.4",
|
|
@@ -51,6 +52,7 @@
|
|
|
51
52
|
"zod": ">=4.0.0"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
55
|
+
"@types/cors": "^2.8.19",
|
|
54
56
|
"@types/node": "^20.11.17",
|
|
55
57
|
"typescript": "^5.4.4",
|
|
56
58
|
"zod": "^4.3.0"
|