@owneraio/finp2p-sdk-js 0.27.11 → 0.27.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/lib/OwneraAPI/finp2p-node-api/custodies.d.ts +5 -0
- package/lib/OwneraAPI/finp2p-node-api/custodies.js +30 -0
- package/lib/OwneraAPI/finp2p-node-api/custodies.js.map +1 -0
- package/lib/OwneraAPI/index.js +2 -0
- package/lib/OwneraAPI/index.js.map +1 -1
- package/lib/OwneraAPI/oss-api/__tests__/externalQueryHandler.test.d.ts +1 -0
- package/lib/OwneraAPI/oss-api/__tests__/externalQueryHandler.test.js +203 -0
- package/lib/OwneraAPI/oss-api/__tests__/externalQueryHandler.test.js.map +1 -0
- package/lib/OwneraAPI/oss-api/computedValues.d.ts +17 -0
- package/lib/OwneraAPI/oss-api/computedValues.js +47 -0
- package/lib/OwneraAPI/oss-api/computedValues.js.map +1 -0
- package/lib/OwneraAPI/oss-api/executeDynamicQueryWithExternal.d.ts +126 -0
- package/lib/OwneraAPI/oss-api/executeDynamicQueryWithExternal.js +245 -0
- package/lib/OwneraAPI/oss-api/executeDynamicQueryWithExternal.js.map +1 -0
- package/lib/OwneraAPI/oss-api/externalQueryHandler.d.ts +67 -0
- package/lib/OwneraAPI/oss-api/externalQueryHandler.js +294 -0
- package/lib/OwneraAPI/oss-api/externalQueryHandler.js.map +1 -0
- package/lib/OwneraAPI/oss-api/filterUtils.d.ts +19 -0
- package/lib/OwneraAPI/oss-api/filterUtils.js +77 -0
- package/lib/OwneraAPI/oss-api/filterUtils.js.map +1 -0
- package/lib/OwneraAPI/oss-api/index.d.ts +6 -0
- package/lib/OwneraAPI/oss-api/index.js +25 -0
- package/lib/OwneraAPI/oss-api/index.js.map +1 -0
- package/lib/OwneraAPI/oss-api/oss.js +955 -692
- package/lib/OwneraAPI/oss-api/oss.js.map +1 -1
- package/lib/OwneraAPI/oss-api/queryUtils.d.ts +20 -0
- package/lib/OwneraAPI/oss-api/queryUtils.js +259 -0
- package/lib/OwneraAPI/oss-api/queryUtils.js.map +1 -0
- package/lib/OwneraAPI/oss-api/queryValidation.d.ts +38 -0
- package/lib/OwneraAPI/oss-api/queryValidation.js +156 -0
- package/lib/OwneraAPI/oss-api/queryValidation.js.map +1 -0
- package/lib/core/sdk.d.ts +2 -1
- package/lib/core/sdk.js +8 -0
- package/lib/core/sdk.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/schemas/assets.json +264 -0
- package/lib/schemas/index.d.ts +40 -0
- package/lib/schemas/index.js +75 -0
- package/lib/schemas/index.js.map +1 -0
- package/lib/schemas/tests/test-assets-schema-execution.d.ts +1 -0
- package/lib/schemas/tests/test-assets-schema-execution.js +261 -0
- package/lib/schemas/tests/test-assets-schema-execution.js.map +1 -0
- package/lib/schemas/tests/test-transactions-filter.d.ts +1 -0
- package/lib/schemas/tests/test-transactions-filter.js +226 -0
- package/lib/schemas/tests/test-transactions-filter.js.map +1 -0
- package/lib/schemas/tests/test-users-inline-fragments.d.ts +1 -0
- package/lib/schemas/tests/test-users-inline-fragments.js +47 -0
- package/lib/schemas/tests/test-users-inline-fragments.js.map +1 -0
- package/lib/schemas/transactions.json +174 -0
- package/lib/schemas/users.json +78 -0
- package/lib/types/Core/OwneraAPI.d.ts +2 -1
- package/lib/types/Core/sdk.d.ts +37 -0
- package/lib/types/Ledgers/Custodies.d.ts +80 -0
- package/lib/types/Ledgers/Custodies.js +3 -0
- package/lib/types/Ledgers/Custodies.js.map +1 -0
- package/lib/types/Ledgers/index.d.ts +1 -0
- package/lib/types/Ledgers/index.js +1 -0
- package/lib/types/Ledgers/index.js.map +1 -1
- package/lib/types/Oss/Oss.d.ts +84 -1
- package/lib/types/Oss/OssResponses.d.ts +4 -1
- package/lib/types/Oss/OssSchemas.d.ts +11 -0
- package/package.json +1 -1
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.executeDynamicQueryWithExternal = executeDynamicQueryWithExternal;
|
|
13
|
+
exports.createStandardExternalDataFetcher = createStandardExternalDataFetcher;
|
|
14
|
+
const externalQueryHandler_1 = require("./externalQueryHandler");
|
|
15
|
+
/**
|
|
16
|
+
* Executes a dynamic query and automatically fetches and merges external data
|
|
17
|
+
*
|
|
18
|
+
* @param executeDynamicQuery - The base executeDynamicQuery function
|
|
19
|
+
* @param externalDataFetcher - Function to fetch external data
|
|
20
|
+
* @param options - Query options
|
|
21
|
+
* @param logger - Logger instance
|
|
22
|
+
* @returns Query results with external data merged
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const result = await executeDynamicQueryWithExternal(
|
|
27
|
+
* api.query.executeDynamicQuery,
|
|
28
|
+
* async (graphqlType, filterIds) => {
|
|
29
|
+
* if (graphqlType === 'users') {
|
|
30
|
+
* const usersResult = await api.oss.getUsers({
|
|
31
|
+
* filter: { id: filterIds }
|
|
32
|
+
* });
|
|
33
|
+
* return usersResult.data;
|
|
34
|
+
* }
|
|
35
|
+
* return [];
|
|
36
|
+
* },
|
|
37
|
+
* {
|
|
38
|
+
* queryConfig: assetsSchema,
|
|
39
|
+
* selectedFields: ['id', 'name', 'country_of_issue'],
|
|
40
|
+
* relationshipKey: 'issuer_id',
|
|
41
|
+
* },
|
|
42
|
+
* logger
|
|
43
|
+
* );
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
function executeDynamicQueryWithExternal(executeDynamicQuery, externalDataFetcher, options, logger) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const { queryConfig, selectedFields, filter, paginate, fetchExternalData = true } = options;
|
|
49
|
+
// Step 1: Identify external queries needed
|
|
50
|
+
const externalQueries = (0, externalQueryHandler_1.identifyExternalQueries)(queryConfig, selectedFields);
|
|
51
|
+
if (externalQueries.size === 0 || !fetchExternalData) {
|
|
52
|
+
return executeDynamicQuery({ queryConfig, selectedFields, filter, paginate });
|
|
53
|
+
}
|
|
54
|
+
// Step 2: Execute main query
|
|
55
|
+
const mainResult = yield executeDynamicQuery({
|
|
56
|
+
queryConfig,
|
|
57
|
+
selectedFields,
|
|
58
|
+
filter,
|
|
59
|
+
paginate,
|
|
60
|
+
});
|
|
61
|
+
if (!mainResult.data || mainResult.data.length === 0) {
|
|
62
|
+
return mainResult;
|
|
63
|
+
}
|
|
64
|
+
// Step 3: Collect IDs and execute external queries
|
|
65
|
+
const externalResults = [];
|
|
66
|
+
const externalQueriesExecuted = [];
|
|
67
|
+
for (const [queryKey, queryInfo] of externalQueries.entries()) {
|
|
68
|
+
try {
|
|
69
|
+
const relationshipIds = new Set();
|
|
70
|
+
mainResult.data.forEach((item) => {
|
|
71
|
+
const id = item[queryInfo.relationshipPath];
|
|
72
|
+
if (id) {
|
|
73
|
+
// Handle both single values and arrays
|
|
74
|
+
if (Array.isArray(id)) {
|
|
75
|
+
id.forEach((val) => {
|
|
76
|
+
if (val)
|
|
77
|
+
relationshipIds.add(val);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
relationshipIds.add(id);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
logger === null || logger === void 0 ? void 0 : logger.info(`Collected relationship IDs for queryKey ${queryKey}`, {
|
|
86
|
+
relationshipPath: queryInfo.relationshipPath,
|
|
87
|
+
count: relationshipIds.size,
|
|
88
|
+
ids: Array.from(relationshipIds)
|
|
89
|
+
});
|
|
90
|
+
if (relationshipIds.size === 0) {
|
|
91
|
+
logger === null || logger === void 0 ? void 0 : logger.info(`No relationship IDs found for queryKey ${queryKey}, skipping external query`);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
// Collect intent IDs if any field has intentFilterKey
|
|
95
|
+
const intentIds = new Set();
|
|
96
|
+
queryInfo.fields.forEach((field) => {
|
|
97
|
+
if (field.intentFilterKey) {
|
|
98
|
+
mainResult.data.forEach((item) => {
|
|
99
|
+
const intentId = item[field.intentFilterKey];
|
|
100
|
+
if (intentId) {
|
|
101
|
+
intentIds.add(intentId);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
logger === null || logger === void 0 ? void 0 : logger.info(`Fetching external data for queryKey ${queryKey}`, {
|
|
107
|
+
graphqlType: queryInfo.graphqlType,
|
|
108
|
+
filterFieldName: queryInfo.filterFieldName,
|
|
109
|
+
idsToFetch: Array.from(relationshipIds),
|
|
110
|
+
intentIdsToFilter: intentIds.size > 0 ? Array.from(intentIds) : undefined
|
|
111
|
+
});
|
|
112
|
+
const data = yield externalDataFetcher(queryInfo.graphqlType, queryInfo.filterFieldName, Array.from(relationshipIds), queryInfo.fields, intentIds.size > 0 ? Array.from(intentIds) : undefined);
|
|
113
|
+
logger === null || logger === void 0 ? void 0 : logger.info(`Fetched external data for queryKey ${queryKey}`, {
|
|
114
|
+
recordsReturned: (data === null || data === void 0 ? void 0 : data.length) || 0
|
|
115
|
+
});
|
|
116
|
+
externalResults.push({
|
|
117
|
+
graphqlType: queryInfo.graphqlType,
|
|
118
|
+
queryKey,
|
|
119
|
+
data,
|
|
120
|
+
});
|
|
121
|
+
externalQueriesExecuted.push(queryKey);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
logger === null || logger === void 0 ? void 0 : logger.error(`Failed to fetch external data for queryKey ${queryKey}`, { error: error.message });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Step 4: Merge external data into main results
|
|
128
|
+
const enrichedData = (0, externalQueryHandler_1.mergeExternalData)(mainResult.data, externalResults, externalQueries, queryConfig, selectedFields, logger);
|
|
129
|
+
return Object.assign(Object.assign({}, mainResult), { data: enrichedData, externalQueriesExecuted });
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Creates a simplified external data fetcher for common use cases
|
|
134
|
+
* @param api - The OwneraAPI instance
|
|
135
|
+
* @returns External data fetcher function
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* const fetcher = createStandardExternalDataFetcher(api);
|
|
140
|
+
* const result = await executeDynamicQueryWithExternal(
|
|
141
|
+
* api.query.executeDynamicQuery,
|
|
142
|
+
* fetcher,
|
|
143
|
+
* options,
|
|
144
|
+
* logger
|
|
145
|
+
* );
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
function createStandardExternalDataFetcher(api) {
|
|
149
|
+
return (graphqlType, filterFieldName, filterIds, fields, intentIds) => __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
// Merge all static filters from fields
|
|
151
|
+
const staticFilters = fields.reduce((acc, field) => {
|
|
152
|
+
if (field.staticFilters) {
|
|
153
|
+
return Object.assign(Object.assign({}, acc), field.staticFilters);
|
|
154
|
+
}
|
|
155
|
+
return acc;
|
|
156
|
+
}, {});
|
|
157
|
+
// Build filter object with the correct field name
|
|
158
|
+
const filter = Object.assign({ [filterFieldName]: filterIds }, staticFilters);
|
|
159
|
+
// Check if any field requires certificates
|
|
160
|
+
const needsCertificates = fields.some((field) => field.certificateType);
|
|
161
|
+
switch (graphqlType) {
|
|
162
|
+
case 'users': {
|
|
163
|
+
const result = yield api.oss.getUsers({ filter });
|
|
164
|
+
return result.data || [];
|
|
165
|
+
}
|
|
166
|
+
case 'assets': {
|
|
167
|
+
// Check if intent IDs were provided (meaning we need to filter intents)
|
|
168
|
+
if (intentIds && intentIds.length > 0) {
|
|
169
|
+
// Use intentFragment from the oss module
|
|
170
|
+
// The fragment includes all standard intent fields
|
|
171
|
+
const result = yield api.oss.getAssetsWithSpecificIntents({
|
|
172
|
+
assetIds: filterIds,
|
|
173
|
+
intentIds: intentIds,
|
|
174
|
+
fields: `
|
|
175
|
+
id
|
|
176
|
+
type
|
|
177
|
+
status
|
|
178
|
+
start
|
|
179
|
+
end
|
|
180
|
+
remainingQuantity
|
|
181
|
+
intent {
|
|
182
|
+
... on PrimarySale {
|
|
183
|
+
issuerId
|
|
184
|
+
settlementTerm {
|
|
185
|
+
details {
|
|
186
|
+
... on PartialSettlement { unitValue }
|
|
187
|
+
... on FullSettlement { amount }
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
... on RedemptionIntent {
|
|
192
|
+
issuerId
|
|
193
|
+
assetTerm { amount }
|
|
194
|
+
}
|
|
195
|
+
... on BuyingIntent {
|
|
196
|
+
buyer
|
|
197
|
+
settlementTerm {
|
|
198
|
+
details {
|
|
199
|
+
... on PartialSettlement { unitValue }
|
|
200
|
+
... on FullSettlement { amount }
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
... on SellingIntent {
|
|
205
|
+
seller
|
|
206
|
+
settlementTerm {
|
|
207
|
+
details {
|
|
208
|
+
... on PartialSettlement { unitValue }
|
|
209
|
+
... on FullSettlement { amount }
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
... on PrivateOfferIntent {
|
|
214
|
+
seller
|
|
215
|
+
buyer
|
|
216
|
+
assetTerm { amount }
|
|
217
|
+
}
|
|
218
|
+
... on RequestForTransferIntent {
|
|
219
|
+
debitor
|
|
220
|
+
creditor
|
|
221
|
+
assetTerm { amount }
|
|
222
|
+
}
|
|
223
|
+
... on LoanIntent {
|
|
224
|
+
borrower
|
|
225
|
+
lender
|
|
226
|
+
assetTerm { amount }
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
`,
|
|
230
|
+
assetFields: needsCertificates ? 'certificates { nodes { type data } }' : undefined,
|
|
231
|
+
});
|
|
232
|
+
return result.data || [];
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
// No intent filtering needed, use standard getAssets
|
|
236
|
+
const result = yield api.oss.getAssets({ filter });
|
|
237
|
+
return result.data || [];
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
default:
|
|
241
|
+
throw new Error(`Unsupported external graphqlType: ${graphqlType}`);
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
//# sourceMappingURL=executeDynamicQueryWithExternal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executeDynamicQueryWithExternal.js","sourceRoot":"","sources":["../../../src/OwneraAPI/oss-api/executeDynamicQueryWithExternal.ts"],"names":[],"mappings":";;;;;;;;;;;AA0GA,0EAoHC;AAkBD,8EAuGC;AApVD,iEAAyG;AAwEzG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,SAAsB,+BAA+B,CACnD,mBAK8C,EAC9C,mBAAwC,EACxC,OAA+C,EAC/C,MAAe;;QAEf,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,iBAAiB,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;QAE5F,2CAA2C;QAC3C,MAAM,eAAe,GAAG,IAAA,8CAAuB,EAAC,WAAW,EAAE,cAAc,CAAC,CAAC;QAE7E,IAAI,eAAe,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACrD,OAAO,mBAAmB,CAAC,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,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gBAC3B,CAAC;YACH,CAAC;YAED;gBACE,MAAM,IAAI,KAAK,CAAC,qCAAqC,WAAW,EAAE,CAAC,CAAC;QACxE,CAAC;IACH,CAAC,CAAA,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { QueryConfig } from '../../types/Oss/Oss';
|
|
2
|
+
import { Logger } from '../../types/Core';
|
|
3
|
+
/**
|
|
4
|
+
* Information about an external query that needs to be executed
|
|
5
|
+
*/
|
|
6
|
+
export interface ExternalQueryInfo {
|
|
7
|
+
graphqlType: string;
|
|
8
|
+
relationshipKey: string;
|
|
9
|
+
relationshipPath: string;
|
|
10
|
+
filterFieldName: string;
|
|
11
|
+
fields: {
|
|
12
|
+
apiField: string;
|
|
13
|
+
path: string;
|
|
14
|
+
graphqlPath: string;
|
|
15
|
+
idField?: string;
|
|
16
|
+
certificateType?: string;
|
|
17
|
+
staticFilters?: Record<string, any>;
|
|
18
|
+
intentFilterKey?: string;
|
|
19
|
+
}[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Result from executing external queries
|
|
23
|
+
*/
|
|
24
|
+
export interface ExternalQueryResult {
|
|
25
|
+
graphqlType: string;
|
|
26
|
+
data: any[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Identifies all external fields in selected fields and groups them by graphqlType + relationshipKey
|
|
30
|
+
* @param config - The query configuration
|
|
31
|
+
* @param selectedFields - Array of selected field names
|
|
32
|
+
* @returns Map of unique key (graphqlType:relationshipKey) to external field information
|
|
33
|
+
*/
|
|
34
|
+
export declare function identifyExternalQueries(config: QueryConfig, selectedFields: string[]): Map<string, ExternalQueryInfo>;
|
|
35
|
+
/**
|
|
36
|
+
* Gets the value from a nested path in an object
|
|
37
|
+
* Supports array notation:
|
|
38
|
+
* - [i] to get all array elements (e.g., "nodes[i].name")
|
|
39
|
+
* - [field=value] to filter by field value (e.g., "nodes[type=NAV].data")
|
|
40
|
+
* - [0], [1] for specific index (e.g., "nodes[0]")
|
|
41
|
+
* Supports alternative field names with pipe syntax (e.g., "unitValue|amount")
|
|
42
|
+
* @param obj - The object to extract value from
|
|
43
|
+
* @param path - Dot notation path (e.g., "certificates.nodes[type=NAV].data.currentNAV.navValue")
|
|
44
|
+
* @param intentId - Optional intent ID to filter intents array
|
|
45
|
+
* @returns The value at the path, or undefined if not found
|
|
46
|
+
*/
|
|
47
|
+
export declare function getValueFromPath(obj: any, path: string, intentId?: string): any;
|
|
48
|
+
/**
|
|
49
|
+
* Merges external query results into the main data
|
|
50
|
+
* @param mainData - The main query result data
|
|
51
|
+
* @param externalResults - Results from external queries with queryKey
|
|
52
|
+
* @param externalQueriesMap - Map of queryKey to ExternalQueryInfo (includes relationshipKey)
|
|
53
|
+
* @param config - The query configuration
|
|
54
|
+
* @param selectedFields - Array of selected field names
|
|
55
|
+
* @param logger - Logger instance
|
|
56
|
+
* @returns Main data enriched with external field values
|
|
57
|
+
*/
|
|
58
|
+
export declare function mergeExternalData(mainData: any[], externalResults: Array<ExternalQueryResult & {
|
|
59
|
+
queryKey: string;
|
|
60
|
+
}>, _externalQueriesMap: Map<string, ExternalQueryInfo>, // Prefix with _ to indicate intentionally unused
|
|
61
|
+
config: QueryConfig, selectedFields: string[], logger?: Logger): any[];
|
|
62
|
+
/**
|
|
63
|
+
* Validates external query configuration
|
|
64
|
+
* @param config - The query configuration
|
|
65
|
+
* @throws Error if external query configuration is invalid
|
|
66
|
+
*/
|
|
67
|
+
export declare function validateExternalQueryConfig(config: QueryConfig): void;
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.identifyExternalQueries = identifyExternalQueries;
|
|
4
|
+
exports.getValueFromPath = getValueFromPath;
|
|
5
|
+
exports.mergeExternalData = mergeExternalData;
|
|
6
|
+
exports.validateExternalQueryConfig = validateExternalQueryConfig;
|
|
7
|
+
/**
|
|
8
|
+
* Identifies all external fields in selected fields and groups them by graphqlType + relationshipKey
|
|
9
|
+
* @param config - The query configuration
|
|
10
|
+
* @param selectedFields - Array of selected field names
|
|
11
|
+
* @returns Map of unique key (graphqlType:relationshipKey) to external field information
|
|
12
|
+
*/
|
|
13
|
+
function identifyExternalQueries(config, selectedFields) {
|
|
14
|
+
const externalQueriesMap = new Map();
|
|
15
|
+
const selectedFieldsSet = new Set(selectedFields);
|
|
16
|
+
const selectedColumns = config.columns.filter((col) => selectedFieldsSet.has(col.apiField));
|
|
17
|
+
selectedColumns.forEach((col) => {
|
|
18
|
+
if (col.dataSource === 'external' && col.externalQuery) {
|
|
19
|
+
const { graphqlType, path, graphqlPath, relationshipKey, relationshipPath, filterFieldName, idField, certificateType, staticFilters, intentFilterKey } = col.externalQuery;
|
|
20
|
+
const queryKey = `${graphqlType}:${relationshipKey}:${filterFieldName}`;
|
|
21
|
+
if (!externalQueriesMap.has(queryKey)) {
|
|
22
|
+
externalQueriesMap.set(queryKey, {
|
|
23
|
+
graphqlType,
|
|
24
|
+
relationshipKey,
|
|
25
|
+
relationshipPath,
|
|
26
|
+
filterFieldName,
|
|
27
|
+
fields: [],
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
externalQueriesMap.get(queryKey).fields.push({
|
|
31
|
+
apiField: col.apiField,
|
|
32
|
+
path,
|
|
33
|
+
graphqlPath,
|
|
34
|
+
idField,
|
|
35
|
+
certificateType,
|
|
36
|
+
staticFilters,
|
|
37
|
+
intentFilterKey,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return externalQueriesMap;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Gets the value from a nested path in an object
|
|
45
|
+
* Supports array notation:
|
|
46
|
+
* - [i] to get all array elements (e.g., "nodes[i].name")
|
|
47
|
+
* - [field=value] to filter by field value (e.g., "nodes[type=NAV].data")
|
|
48
|
+
* - [0], [1] for specific index (e.g., "nodes[0]")
|
|
49
|
+
* Supports alternative field names with pipe syntax (e.g., "unitValue|amount")
|
|
50
|
+
* @param obj - The object to extract value from
|
|
51
|
+
* @param path - Dot notation path (e.g., "certificates.nodes[type=NAV].data.currentNAV.navValue")
|
|
52
|
+
* @param intentId - Optional intent ID to filter intents array
|
|
53
|
+
* @returns The value at the path, or undefined if not found
|
|
54
|
+
*/
|
|
55
|
+
function getValueFromPath(obj, path, intentId) {
|
|
56
|
+
var _a;
|
|
57
|
+
if (!obj || !path)
|
|
58
|
+
return undefined;
|
|
59
|
+
const parts = path.split('.');
|
|
60
|
+
let current = obj;
|
|
61
|
+
for (const part of parts) {
|
|
62
|
+
if (!current)
|
|
63
|
+
return undefined;
|
|
64
|
+
// Special handling for 'intents' field when intentId is provided
|
|
65
|
+
if (part === 'intents' && intentId) {
|
|
66
|
+
// Check if intents is wrapped in nodes
|
|
67
|
+
const intentsArray = Array.isArray((_a = current.intents) === null || _a === void 0 ? void 0 : _a.nodes)
|
|
68
|
+
? current.intents.nodes
|
|
69
|
+
: Array.isArray(current.intents)
|
|
70
|
+
? current.intents
|
|
71
|
+
: undefined;
|
|
72
|
+
if (intentsArray) {
|
|
73
|
+
const matchingIntent = intentsArray.find((intent) => intent.id === intentId);
|
|
74
|
+
if (!matchingIntent) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
current = matchingIntent;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Handle array notation [i] for all elements
|
|
82
|
+
if (part.endsWith('[i]')) {
|
|
83
|
+
const arrayKey = part.slice(0, -3);
|
|
84
|
+
const array = current[arrayKey];
|
|
85
|
+
if (!Array.isArray(array))
|
|
86
|
+
return undefined;
|
|
87
|
+
// Return array of values from all elements
|
|
88
|
+
const remainingPath = parts.slice(parts.indexOf(part) + 1).join('.');
|
|
89
|
+
if (!remainingPath)
|
|
90
|
+
return array;
|
|
91
|
+
return array.map((item) => getValueFromPath(item, remainingPath, intentId)).filter((v) => v !== undefined);
|
|
92
|
+
}
|
|
93
|
+
// Handle array notation [field=value] for filtering (e.g., nodes[type=NAV])
|
|
94
|
+
const filterMatch = part.match(/^(.+)\[(\w+)=([^\]]+)\]$/);
|
|
95
|
+
if (filterMatch) {
|
|
96
|
+
const arrayKey = filterMatch[1];
|
|
97
|
+
const filterField = filterMatch[2];
|
|
98
|
+
const filterValue = filterMatch[3];
|
|
99
|
+
const array = current[arrayKey];
|
|
100
|
+
if (!Array.isArray(array))
|
|
101
|
+
return undefined;
|
|
102
|
+
// Find the first element where field matches value
|
|
103
|
+
const matchingElement = array.find((item) => item && item[filterField] === filterValue);
|
|
104
|
+
if (!matchingElement)
|
|
105
|
+
return undefined;
|
|
106
|
+
current = matchingElement;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
// Handle array notation [0], [1], etc. for specific index
|
|
110
|
+
const arrayMatch = part.match(/^(.+)\[(\d+)\]$/);
|
|
111
|
+
if (arrayMatch) {
|
|
112
|
+
const arrayKey = arrayMatch[1];
|
|
113
|
+
const index = parseInt(arrayMatch[2], 10);
|
|
114
|
+
const array = current[arrayKey];
|
|
115
|
+
if (!Array.isArray(array) || index >= array.length)
|
|
116
|
+
return undefined;
|
|
117
|
+
current = array[index];
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
// Handle alternative field names with pipe syntax (e.g., "unitValue|amount")
|
|
121
|
+
if (part.includes('|')) {
|
|
122
|
+
const alternatives = part.split('|');
|
|
123
|
+
let found = false;
|
|
124
|
+
for (const alt of alternatives) {
|
|
125
|
+
if (current[alt] !== undefined) {
|
|
126
|
+
current = current[alt];
|
|
127
|
+
found = true;
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (!found)
|
|
132
|
+
return undefined;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
current = current[part];
|
|
136
|
+
}
|
|
137
|
+
return current;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Merges external query results into the main data
|
|
141
|
+
* @param mainData - The main query result data
|
|
142
|
+
* @param externalResults - Results from external queries with queryKey
|
|
143
|
+
* @param externalQueriesMap - Map of queryKey to ExternalQueryInfo (includes relationshipKey)
|
|
144
|
+
* @param config - The query configuration
|
|
145
|
+
* @param selectedFields - Array of selected field names
|
|
146
|
+
* @param logger - Logger instance
|
|
147
|
+
* @returns Main data enriched with external field values
|
|
148
|
+
*/
|
|
149
|
+
function mergeExternalData(mainData, externalResults, _externalQueriesMap, // Prefix with _ to indicate intentionally unused
|
|
150
|
+
config, selectedFields, logger) {
|
|
151
|
+
if (externalResults.length === 0) {
|
|
152
|
+
return mainData;
|
|
153
|
+
}
|
|
154
|
+
const selectedFieldsSet = new Set(selectedFields);
|
|
155
|
+
const externalFields = config.columns.filter((col) => selectedFieldsSet.has(col.apiField) && col.dataSource === 'external');
|
|
156
|
+
if (externalFields.length === 0) {
|
|
157
|
+
return mainData;
|
|
158
|
+
}
|
|
159
|
+
// Build lookup maps for external data by ID
|
|
160
|
+
const externalDataMaps = new Map();
|
|
161
|
+
externalResults.forEach((result) => {
|
|
162
|
+
var _a;
|
|
163
|
+
const dataMap = new Map();
|
|
164
|
+
const queryInfo = _externalQueriesMap.get(result.queryKey);
|
|
165
|
+
const idFieldName = ((_a = queryInfo === null || queryInfo === void 0 ? void 0 : queryInfo.fields[0]) === null || _a === void 0 ? void 0 : _a.idField) || 'id';
|
|
166
|
+
result.data.forEach((item) => {
|
|
167
|
+
const id = item[idFieldName];
|
|
168
|
+
if (id) {
|
|
169
|
+
dataMap.set(id, item);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
logger === null || logger === void 0 ? void 0 : logger.info(`Built external data map for queryKey ${result.queryKey}`, {
|
|
173
|
+
idFieldName,
|
|
174
|
+
recordCount: dataMap.size,
|
|
175
|
+
ids: Array.from(dataMap.keys())
|
|
176
|
+
});
|
|
177
|
+
externalDataMaps.set(result.queryKey, dataMap);
|
|
178
|
+
});
|
|
179
|
+
// Cache relationshipPath lookups
|
|
180
|
+
const queryInfoCache = new Map();
|
|
181
|
+
externalFields.forEach((field) => {
|
|
182
|
+
if (!field.externalQuery)
|
|
183
|
+
return;
|
|
184
|
+
const { graphqlType, relationshipKey, filterFieldName } = field.externalQuery;
|
|
185
|
+
const queryKey = `${graphqlType}:${relationshipKey}:${filterFieldName}`;
|
|
186
|
+
if (!queryInfoCache.has(queryKey)) {
|
|
187
|
+
const queryInfo = _externalQueriesMap.get(queryKey);
|
|
188
|
+
queryInfoCache.set(queryKey, {
|
|
189
|
+
relationshipPath: (queryInfo === null || queryInfo === void 0 ? void 0 : queryInfo.relationshipPath) || relationshipKey
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
// Merge external data into main results
|
|
194
|
+
const enrichedData = mainData.map((mainItem) => {
|
|
195
|
+
let enrichedItem = mainItem;
|
|
196
|
+
let hasEnrichment = false;
|
|
197
|
+
externalFields.forEach((field) => {
|
|
198
|
+
var _a, _b;
|
|
199
|
+
if (!field.externalQuery)
|
|
200
|
+
return;
|
|
201
|
+
const { graphqlType, path, relationshipKey, filterFieldName, certificateType } = field.externalQuery;
|
|
202
|
+
const queryKey = `${graphqlType}:${relationshipKey}:${filterFieldName}`;
|
|
203
|
+
const externalDataMap = externalDataMaps.get(queryKey);
|
|
204
|
+
if (!externalDataMap) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const cachedInfo = queryInfoCache.get(queryKey);
|
|
208
|
+
const relationshipPath = (cachedInfo === null || cachedInfo === void 0 ? void 0 : cachedInfo.relationshipPath) || relationshipKey;
|
|
209
|
+
const relationshipValue = mainItem[relationshipPath];
|
|
210
|
+
if (!relationshipValue) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
// Handle both single values and arrays for relationship value
|
|
214
|
+
let externalItem;
|
|
215
|
+
if (Array.isArray(relationshipValue)) {
|
|
216
|
+
// For arrays, try to find the first matching external item
|
|
217
|
+
for (const val of relationshipValue) {
|
|
218
|
+
externalItem = externalDataMap.get(val);
|
|
219
|
+
if (externalItem)
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
if (!externalItem) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
externalItem = externalDataMap.get(relationshipValue);
|
|
228
|
+
if (!externalItem) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// Extract value from certificate if specified
|
|
233
|
+
if (certificateType) {
|
|
234
|
+
const certsList = ((_a = externalItem.certificates) === null || _a === void 0 ? void 0 : _a.nodes) || externalItem.certificates;
|
|
235
|
+
if (certsList && Array.isArray(certsList)) {
|
|
236
|
+
const matchingCert = certsList.find((cert) => cert.type === certificateType);
|
|
237
|
+
if (matchingCert) {
|
|
238
|
+
let parsedData = {};
|
|
239
|
+
try {
|
|
240
|
+
parsedData = typeof matchingCert.data === 'string'
|
|
241
|
+
? JSON.parse(matchingCert.data)
|
|
242
|
+
: matchingCert.data;
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
logger === null || logger === void 0 ? void 0 : logger.warning(`Failed to parse certificate data for type ${certificateType}`, {
|
|
246
|
+
error: error.message,
|
|
247
|
+
certificateId: matchingCert.id
|
|
248
|
+
});
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
externalItem = parsedData;
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
// Get intent ID if intentFilterKey is specified
|
|
259
|
+
const intentFilterKey = (_b = field.externalQuery) === null || _b === void 0 ? void 0 : _b.intentFilterKey;
|
|
260
|
+
const intentId = intentFilterKey ? mainItem[intentFilterKey] : undefined;
|
|
261
|
+
const value = getValueFromPath(externalItem, path, intentId);
|
|
262
|
+
if (!hasEnrichment) {
|
|
263
|
+
enrichedItem = Object.assign({}, mainItem);
|
|
264
|
+
hasEnrichment = true;
|
|
265
|
+
}
|
|
266
|
+
enrichedItem[field.apiField] = value;
|
|
267
|
+
});
|
|
268
|
+
return enrichedItem;
|
|
269
|
+
});
|
|
270
|
+
return enrichedData;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Validates external query configuration
|
|
274
|
+
* @param config - The query configuration
|
|
275
|
+
* @throws Error if external query configuration is invalid
|
|
276
|
+
*/
|
|
277
|
+
function validateExternalQueryConfig(config) {
|
|
278
|
+
const externalFields = config.columns.filter((col) => col.dataSource === 'external');
|
|
279
|
+
externalFields.forEach((field) => {
|
|
280
|
+
if (!field.externalQuery) {
|
|
281
|
+
throw new Error(`External field ${field.apiField} missing externalQuery configuration`);
|
|
282
|
+
}
|
|
283
|
+
if (!field.externalQuery.graphqlType) {
|
|
284
|
+
throw new Error(`External field ${field.apiField} missing externalQuery.graphqlType`);
|
|
285
|
+
}
|
|
286
|
+
if (!field.externalQuery.path) {
|
|
287
|
+
throw new Error(`External field ${field.apiField} missing externalQuery.path`);
|
|
288
|
+
}
|
|
289
|
+
if (!field.externalQuery.graphqlPath) {
|
|
290
|
+
throw new Error(`External field ${field.apiField} missing externalQuery.graphqlPath`);
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
//# sourceMappingURL=externalQueryHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"externalQueryHandler.js","sourceRoot":"","sources":["../../../src/OwneraAPI/oss-api/externalQueryHandler.ts"],"names":[],"mappings":";;AAoCA,0DAmCC;AAcD,4CA4FC;AAYD,8CA6IC;AAOD,kEAoBC;AAvUD;;;;;GAKG;AACH,SAAgB,uBAAuB,CAAC,MAAmB,EAAE,cAAwB;IACnF,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAA6B,CAAC;IAChE,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,CAAC;IAClD,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO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C,QAAQ,sCAAsC,CAAC,CAAC;QAC1F,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC;YACrC,MAAM,IAAI,KAAK,CAAC,kBAAkB,KAAK,CAAC,QAAQ,oCAAoC,CAAC,CAAC;QACxF,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,kBAAkB,KAAK,CAAC,QAAQ,6BAA6B,CAAC,CAAC;QACjF,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC;YACrC,MAAM,IAAI,KAAK,CAAC,kBAAkB,KAAK,CAAC,QAAQ,oCAAoC,CAAC,CAAC;QACxF,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filter utilities for sanitizing and formatting GraphQL filter values
|
|
3
|
+
* These functions prevent injection attacks and ensure type safety
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Sanitizes a filter key to prevent injection attacks
|
|
7
|
+
* Only allows alphanumeric characters and underscores (GraphQL field naming convention)
|
|
8
|
+
*/
|
|
9
|
+
export declare const sanitizeFilterKey: (key: string) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Sanitizes a filter value to prevent injection attacks
|
|
12
|
+
* Escapes special characters in strings to prevent GraphQL injection
|
|
13
|
+
*/
|
|
14
|
+
export declare const sanitizeFilterValue: (value: any) => string;
|
|
15
|
+
/**
|
|
16
|
+
* Formats a filter value based on its type for GraphQL query construction
|
|
17
|
+
* Wraps values in quotes and handles boolean, number, and string types
|
|
18
|
+
*/
|
|
19
|
+
export declare const formatFilterValue: (value: any) => string;
|