@owneraio/finp2p-sdk-js 0.27.11 → 0.27.12

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.
Files changed (50) hide show
  1. package/lib/OwneraAPI/oss-api/__tests__/externalQueryHandler.test.d.ts +1 -0
  2. package/lib/OwneraAPI/oss-api/__tests__/externalQueryHandler.test.js +203 -0
  3. package/lib/OwneraAPI/oss-api/__tests__/externalQueryHandler.test.js.map +1 -0
  4. package/lib/OwneraAPI/oss-api/computedValues.d.ts +17 -0
  5. package/lib/OwneraAPI/oss-api/computedValues.js +47 -0
  6. package/lib/OwneraAPI/oss-api/computedValues.js.map +1 -0
  7. package/lib/OwneraAPI/oss-api/executeDynamicQueryWithExternal.d.ts +126 -0
  8. package/lib/OwneraAPI/oss-api/executeDynamicQueryWithExternal.js +245 -0
  9. package/lib/OwneraAPI/oss-api/executeDynamicQueryWithExternal.js.map +1 -0
  10. package/lib/OwneraAPI/oss-api/externalQueryHandler.d.ts +67 -0
  11. package/lib/OwneraAPI/oss-api/externalQueryHandler.js +294 -0
  12. package/lib/OwneraAPI/oss-api/externalQueryHandler.js.map +1 -0
  13. package/lib/OwneraAPI/oss-api/filterUtils.d.ts +19 -0
  14. package/lib/OwneraAPI/oss-api/filterUtils.js +77 -0
  15. package/lib/OwneraAPI/oss-api/filterUtils.js.map +1 -0
  16. package/lib/OwneraAPI/oss-api/index.d.ts +6 -0
  17. package/lib/OwneraAPI/oss-api/index.js +25 -0
  18. package/lib/OwneraAPI/oss-api/index.js.map +1 -0
  19. package/lib/OwneraAPI/oss-api/oss.js +931 -692
  20. package/lib/OwneraAPI/oss-api/oss.js.map +1 -1
  21. package/lib/OwneraAPI/oss-api/queryUtils.d.ts +20 -0
  22. package/lib/OwneraAPI/oss-api/queryUtils.js +259 -0
  23. package/lib/OwneraAPI/oss-api/queryUtils.js.map +1 -0
  24. package/lib/OwneraAPI/oss-api/queryValidation.d.ts +38 -0
  25. package/lib/OwneraAPI/oss-api/queryValidation.js +156 -0
  26. package/lib/OwneraAPI/oss-api/queryValidation.js.map +1 -0
  27. package/lib/core/sdk.d.ts +2 -1
  28. package/lib/core/sdk.js +8 -0
  29. package/lib/core/sdk.js.map +1 -1
  30. package/lib/index.d.ts +1 -0
  31. package/lib/index.js +1 -0
  32. package/lib/index.js.map +1 -1
  33. package/lib/schemas/assets.json +264 -0
  34. package/lib/schemas/index.d.ts +40 -0
  35. package/lib/schemas/index.js +75 -0
  36. package/lib/schemas/index.js.map +1 -0
  37. package/lib/schemas/tests/test-assets-schema-execution.d.ts +1 -0
  38. package/lib/schemas/tests/test-assets-schema-execution.js +261 -0
  39. package/lib/schemas/tests/test-assets-schema-execution.js.map +1 -0
  40. package/lib/schemas/tests/test-transactions-filter.d.ts +1 -0
  41. package/lib/schemas/tests/test-transactions-filter.js +226 -0
  42. package/lib/schemas/tests/test-transactions-filter.js.map +1 -0
  43. package/lib/schemas/tests/test-users-inline-fragments.d.ts +1 -0
  44. package/lib/schemas/tests/test-users-inline-fragments.js +47 -0
  45. package/lib/schemas/tests/test-users-inline-fragments.js.map +1 -0
  46. package/lib/schemas/transactions.json +174 -0
  47. package/lib/schemas/users.json +78 -0
  48. package/lib/types/Core/sdk.d.ts +37 -0
  49. package/lib/types/Oss/Oss.d.ts +77 -0
  50. package/package.json +1 -1
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // Test for external query handler utilities
4
+ const externalQueryHandler_1 = require("../externalQueryHandler");
5
+ const queryValidation_1 = require("../queryValidation");
6
+ describe('External Query Handler', () => {
7
+ // Mock query config
8
+ const mockAssetsConfig = {
9
+ name: 'Assets',
10
+ graphqlType: 'assets',
11
+ columns: [
12
+ {
13
+ apiField: 'id',
14
+ header: 'id',
15
+ path: 'id',
16
+ graphqlPath: 'id',
17
+ },
18
+ {
19
+ apiField: 'name',
20
+ header: 'name',
21
+ path: 'name',
22
+ graphqlPath: 'name',
23
+ },
24
+ {
25
+ apiField: 'issuer_id',
26
+ header: 'issuer_id',
27
+ path: 'issuerId',
28
+ graphqlPath: 'issuerId',
29
+ },
30
+ {
31
+ apiField: 'country_of_issue',
32
+ header: 'country_of_issue',
33
+ dataSource: 'external',
34
+ externalQuery: {
35
+ graphqlType: 'users',
36
+ relationshipKey: 'issuer_id',
37
+ relationshipPath: 'issuerId',
38
+ filterFieldName: 'id',
39
+ idField: 'userId',
40
+ certificateType: 'individual_info',
41
+ path: 'address.country',
42
+ graphqlPath: 'id certificates { nodes { type data } }',
43
+ },
44
+ },
45
+ {
46
+ apiField: 'issuer_name',
47
+ header: 'issuer_name',
48
+ dataSource: 'external',
49
+ externalQuery: {
50
+ graphqlType: 'users',
51
+ relationshipKey: 'issuer_id',
52
+ relationshipPath: 'issuerId',
53
+ filterFieldName: 'id',
54
+ idField: 'userId',
55
+ path: 'name',
56
+ graphqlPath: 'name',
57
+ },
58
+ },
59
+ ],
60
+ };
61
+ const selectedFields = ['id', 'name', 'issuer_id', 'country_of_issue', 'issuer_name'];
62
+ describe('identifyExternalQueries', () => {
63
+ it('should identify external queries and group them correctly', () => {
64
+ const externalQueries = (0, externalQueryHandler_1.identifyExternalQueries)(mockAssetsConfig, selectedFields);
65
+ expect(externalQueries.size).toBe(1);
66
+ // QueryKey is now "graphqlType:relationshipKey:filterFieldName"
67
+ const queryKey = 'users:issuer_id:id';
68
+ const usersQuery = externalQueries.get(queryKey);
69
+ expect(usersQuery).toBeDefined();
70
+ expect(usersQuery.fields.length).toBe(2);
71
+ expect(usersQuery.graphqlType).toBe('users');
72
+ expect(usersQuery.relationshipKey).toBe('issuer_id');
73
+ expect(usersQuery.filterFieldName).toBe('id');
74
+ });
75
+ });
76
+ describe('getValueFromPath', () => {
77
+ const testObject = {
78
+ name: 'John Doe',
79
+ certificates: {
80
+ nodes: [
81
+ { type: 'kyc', data: { verified: true } },
82
+ { type: 'individual_info', data: { country: 'USA', state: 'CA' } },
83
+ { type: 'tax', data: { id: '123' } },
84
+ ],
85
+ },
86
+ };
87
+ it('should extract values from nested array paths', () => {
88
+ const countryValue = (0, externalQueryHandler_1.getValueFromPath)(testObject, 'certificates.nodes[i].data.country');
89
+ expect(Array.isArray(countryValue)).toBe(true);
90
+ expect(countryValue).toContain('USA');
91
+ });
92
+ it('should extract simple field values', () => {
93
+ const nameValue = (0, externalQueryHandler_1.getValueFromPath)(testObject, 'name');
94
+ expect(nameValue).toBe('John Doe');
95
+ });
96
+ });
97
+ describe('mergeExternalData', () => {
98
+ const mainData = [
99
+ { id: 'asset-1', name: 'Asset One', issuerId: 'user-1' },
100
+ { id: 'asset-2', name: 'Asset Two', issuerId: 'user-2' },
101
+ { id: 'asset-3', name: 'Asset Three', issuerId: 'user-1' },
102
+ ];
103
+ const externalResults = [
104
+ {
105
+ graphqlType: 'users',
106
+ queryKey: 'users:issuer_id:id',
107
+ data: [
108
+ {
109
+ userId: 'user-1',
110
+ name: 'Issuer One',
111
+ certificates: {
112
+ nodes: [{ type: 'individual_info', data: '{"address":{"country":"USA"}}' }],
113
+ },
114
+ },
115
+ {
116
+ userId: 'user-2',
117
+ name: 'Issuer Two',
118
+ certificates: {
119
+ nodes: [{ type: 'individual_info', data: '{"address":{"country":"UK"}}' }],
120
+ },
121
+ },
122
+ ],
123
+ },
124
+ ];
125
+ const mockLogger = {
126
+ debug: jest.fn(),
127
+ info: jest.fn(),
128
+ warn: jest.fn(),
129
+ error: jest.fn(),
130
+ };
131
+ it('should merge external data into main results correctly', () => {
132
+ const externalQueries = (0, externalQueryHandler_1.identifyExternalQueries)(mockAssetsConfig, selectedFields);
133
+ const enrichedData = (0, externalQueryHandler_1.mergeExternalData)(mainData, externalResults, externalQueries, mockAssetsConfig, selectedFields, mockLogger);
134
+ expect(enrichedData).toHaveLength(3);
135
+ // Check Asset One
136
+ expect(enrichedData[0].country_of_issue).toBe('USA');
137
+ expect(enrichedData[0].issuer_name).toBe('Issuer One');
138
+ // Check Asset Two
139
+ expect(enrichedData[1].country_of_issue).toBe('UK');
140
+ expect(enrichedData[1].issuer_name).toBe('Issuer Two');
141
+ // Check Asset Three (should also have Issuer One data)
142
+ expect(enrichedData[2].country_of_issue).toBe('USA');
143
+ expect(enrichedData[2].issuer_name).toBe('Issuer One');
144
+ });
145
+ });
146
+ describe('validateExternalQueryConfig', () => {
147
+ it('should validate a correct configuration', () => {
148
+ expect(() => (0, externalQueryHandler_1.validateExternalQueryConfig)(mockAssetsConfig)).not.toThrow();
149
+ });
150
+ it('should throw error for missing externalQuery', () => {
151
+ const invalidConfig = {
152
+ name: 'Invalid',
153
+ graphqlType: 'invalid',
154
+ columns: [
155
+ {
156
+ apiField: 'bad_field',
157
+ header: 'bad_field',
158
+ dataSource: 'external',
159
+ // Missing externalQuery
160
+ },
161
+ ],
162
+ };
163
+ expect(() => (0, externalQueryHandler_1.validateExternalQueryConfig)(invalidConfig)).toThrow();
164
+ });
165
+ });
166
+ });
167
+ describe('Query Validation', () => {
168
+ describe('validateSelectedFields', () => {
169
+ it('should detect GraphQL syntax in field names', () => {
170
+ const invalidFields = ['id', 'certificates', '{', 'nodes', '}'];
171
+ expect(() => (0, queryValidation_1.validateSelectedFields)(invalidFields)).toThrow(/GraphQL syntax/);
172
+ expect(() => (0, queryValidation_1.validateSelectedFields)(invalidFields)).toThrow(/graphqlPath/);
173
+ });
174
+ it('should pass for valid field names', () => {
175
+ const validFields = ['id', 'name', 'issuer_id', 'country_of_issue'];
176
+ expect(() => (0, queryValidation_1.validateSelectedFields)(validFields)).not.toThrow();
177
+ });
178
+ });
179
+ describe('validateFieldsExistInConfig', () => {
180
+ const mockConfig = {
181
+ name: 'Test',
182
+ graphqlType: 'testType',
183
+ columns: [
184
+ { apiField: 'id', header: 'id', path: 'id', graphqlPath: 'id' },
185
+ { apiField: 'name', header: 'name', path: 'name', graphqlPath: 'name' },
186
+ ],
187
+ };
188
+ it('should detect GraphQL tokens in invalid fields', () => {
189
+ const invalidFields = ['id', 'nodes', 'data', '{'];
190
+ expect(() => (0, queryValidation_1.validateFieldsExistInConfig)(invalidFields, mockConfig)).toThrow(/GraphQL path tokens/);
191
+ expect(() => (0, queryValidation_1.validateFieldsExistInConfig)(invalidFields, mockConfig)).toThrow(/apiField names/);
192
+ });
193
+ it('should provide helpful message for regular invalid fields', () => {
194
+ const invalidFields = ['id', 'unknown_field'];
195
+ expect(() => (0, queryValidation_1.validateFieldsExistInConfig)(invalidFields, mockConfig)).toThrow(/Available fields/);
196
+ });
197
+ it('should pass for valid fields', () => {
198
+ const validFields = ['id', 'name'];
199
+ expect(() => (0, queryValidation_1.validateFieldsExistInConfig)(validFields, mockConfig)).not.toThrow();
200
+ });
201
+ });
202
+ });
203
+ //# sourceMappingURL=externalQueryHandler.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"externalQueryHandler.test.js","sourceRoot":"","sources":["../../../../src/OwneraAPI/oss-api/__tests__/externalQueryHandler.test.ts"],"names":[],"mappings":";;AAAA,4CAA4C;AAC5C,kEAKiC;AACjC,wDAAyF;AAGzF,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,oBAAoB;IACpB,MAAM,gBAAgB,GAAgB;QACpC,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,QAAQ;QACrB,OAAO,EAAE;YACP;gBACE,QAAQ,EAAE,IAAI;gBACd,MAAM,EAAE,IAAI;gBACZ,IAAI,EAAE,IAAI;gBACV,WAAW,EAAE,IAAI;aAClB;YACD;gBACE,QAAQ,EAAE,MAAM;gBAChB,MAAM,EAAE,MAAM;gBACd,IAAI,EAAE,MAAM;gBACZ,WAAW,EAAE,MAAM;aACpB;YACD;gBACE,QAAQ,EAAE,WAAW;gBACrB,MAAM,EAAE,WAAW;gBACnB,IAAI,EAAE,UAAU;gBAChB,WAAW,EAAE,UAAU;aACxB;YACD;gBACE,QAAQ,EAAE,kBAAkB;gBAC5B,MAAM,EAAE,kBAAkB;gBAC1B,UAAU,EAAE,UAAU;gBACtB,aAAa,EAAE;oBACb,WAA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AAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE;aACxE;SACF,CAAC;QAEF,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;YACxD,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;YACnD,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,6CAA2B,EAAC,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;YACpG,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,6CAA2B,EAAC,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;QACjG,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,2DAA2D,EAAE,GAAG,EAAE;YACnE,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;YAC9C,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,6CAA2B,EAAC,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;QACnG,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE;YACtC,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YACnC,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,6CAA2B,EAAC,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;QACnF,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { ComputedValueType } from '../../types/Oss/Oss';
2
+ /**
3
+ * Computes a runtime value based on the ComputedValueType
4
+ * @param computedValue - The type of computed value to generate
5
+ * @returns The computed value
6
+ */
7
+ export declare function computeRuntimeValue(computedValue: ComputedValueType | string): any;
8
+ /**
9
+ * Applies computed values to a data row based on column configuration
10
+ * @param row - The data row to populate
11
+ * @param columns - Array of column configurations
12
+ * @returns The row with computed values populated
13
+ */
14
+ export declare function applyComputedValues(row: Record<string, any>, columns: Array<{
15
+ apiField: string;
16
+ computedValue?: string;
17
+ }>): Record<string, any>;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.computeRuntimeValue = computeRuntimeValue;
4
+ exports.applyComputedValues = applyComputedValues;
5
+ /**
6
+ * Computes a runtime value based on the ComputedValueType
7
+ * @param computedValue - The type of computed value to generate
8
+ * @returns The computed value
9
+ */
10
+ function computeRuntimeValue(computedValue) {
11
+ switch (computedValue) {
12
+ case 'currentTimestamp':
13
+ // Returns milliseconds since epoch
14
+ return Date.now();
15
+ case 'currentDate':
16
+ // Returns ISO 8601 date string (e.g., "2025-01-15T10:30:45.123Z")
17
+ return new Date().toISOString();
18
+ case 'currentDateLocal':
19
+ // Returns localized date string
20
+ return new Date().toLocaleString();
21
+ case 'currentUnixTime':
22
+ // Returns seconds since epoch
23
+ return Math.floor(Date.now() / 1000);
24
+ default:
25
+ // For custom computed values, return undefined
26
+ // This allows for future extensibility
27
+ return undefined;
28
+ }
29
+ }
30
+ /**
31
+ * Applies computed values to a data row based on column configuration
32
+ * @param row - The data row to populate
33
+ * @param columns - Array of column configurations
34
+ * @returns The row with computed values populated
35
+ */
36
+ function applyComputedValues(row, columns) {
37
+ columns.forEach((col) => {
38
+ if (col.computedValue) {
39
+ const value = computeRuntimeValue(col.computedValue);
40
+ if (value !== undefined) {
41
+ row[col.apiField] = value;
42
+ }
43
+ }
44
+ });
45
+ return row;
46
+ }
47
+ //# sourceMappingURL=computedValues.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"computedValues.js","sourceRoot":"","sources":["../../../src/OwneraAPI/oss-api/computedValues.ts"],"names":[],"mappings":";;AAOA,kDAuBC;AAQD,kDAaC;AAjDD;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,aAAyC;IAC3E,QAAQ,aAAa,EAAE,CAAC;QACtB,KAAK,kBAAkB;YACrB,mCAAmC;YACnC,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC;QAEpB,KAAK,aAAa;YAChB,kEAAkE;YAClE,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAElC,KAAK,kBAAkB;YACrB,gCAAgC;YAChC,OAAO,IAAI,IAAI,EAAE,CAAC,cAAc,EAAE,CAAC;QAErC,KAAK,iBAAiB;YACpB,8BAA8B;YAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;QAEvC;YACE,+CAA+C;YAC/C,uCAAuC;YACvC,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAgB,mBAAmB,CACjC,GAAwB,EACxB,OAA4D;IAE5D,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACtB,IAAI,GAAG,CAAC,aAAa,EAAE,CAAC;YACtB,MAAM,KAAK,GAAG,mBAAmB,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;YACrD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;YAC5B,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,126 @@
1
+ import { QueryConfig } from '../../types/Oss/Oss';
2
+ import { PaginateInput } from '../../types/Oss';
3
+ import { Logger } from '../../types/Core';
4
+ /**
5
+ * Options for executing dynamic query with external data
6
+ */
7
+ export interface ExecuteDynamicQueryWithExternalOptions {
8
+ queryConfig: QueryConfig;
9
+ selectedFields: string[];
10
+ filter?: Record<string, any>;
11
+ paginate?: PaginateInput;
12
+ relationshipKey?: string;
13
+ fetchExternalData?: boolean;
14
+ }
15
+ /**
16
+ * External data fetcher function type
17
+ * This function should execute the external query and return the results
18
+ *
19
+ * @param graphqlType - The GraphQL type to query (e.g., 'users', 'assets')
20
+ * @param filterFieldName - The field name to use for filtering (e.g., 'id', 'assetIds')
21
+ * @param filterIds - Array of IDs to filter by
22
+ * @param fields - Array of field configurations from the external query definition.
23
+ * IMPORTANT: The `graphqlPath` in these fields describes the GraphQL structure
24
+ * for extracting values AFTER fetching, not the fields to query.
25
+ * Use `apiField` to identify which values to extract, and `path` for extraction logic.
26
+ *
27
+ * @returns Promise resolving to array of fetched records
28
+ *
29
+ * @example Standard implementation using hardcoded methods
30
+ * ```typescript
31
+ * const fetcher = async (graphqlType, filterFieldName, filterIds, fields) => {
32
+ * if (graphqlType === 'users') {
33
+ * const result = await api.oss.getUsers({
34
+ * filter: { [filterFieldName]: filterIds }
35
+ * });
36
+ * return result.data;
37
+ * }
38
+ * // ... handle other types
39
+ * };
40
+ * ```
41
+ *
42
+ * @example Custom implementation using executeDynamicQuery
43
+ * ```typescript
44
+ * const fetcher = async (graphqlType, filterFieldName, filterIds, fields) => {
45
+ * if (graphqlType === 'users') {
46
+ * const usersSchema = getUsersSchema(); // Get proper QueryConfig for users
47
+ * // Use schema's apiField names, NOT the graphqlPath strings from fields parameter
48
+ * const result = await api.query.executeDynamicQuery({
49
+ * queryConfig: usersSchema,
50
+ * selectedFields: ['user_id', 'account_fin_id'], // Use actual field names from schema
51
+ * filter: { [filterFieldName]: filterIds }
52
+ * });
53
+ * return result.data;
54
+ * }
55
+ * };
56
+ * ```
57
+ */
58
+ export type ExternalDataFetcher = (graphqlType: string, filterFieldName: string, filterIds: string[], fields: {
59
+ apiField: string;
60
+ path: string;
61
+ graphqlPath: string;
62
+ certificateType?: string;
63
+ staticFilters?: Record<string, any>;
64
+ intentFilterKey?: string;
65
+ }[], intentIds?: string[]) => Promise<any[]>;
66
+ /**
67
+ * Executes a dynamic query and automatically fetches and merges external data
68
+ *
69
+ * @param executeDynamicQuery - The base executeDynamicQuery function
70
+ * @param externalDataFetcher - Function to fetch external data
71
+ * @param options - Query options
72
+ * @param logger - Logger instance
73
+ * @returns Query results with external data merged
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * const result = await executeDynamicQueryWithExternal(
78
+ * api.query.executeDynamicQuery,
79
+ * async (graphqlType, filterIds) => {
80
+ * if (graphqlType === 'users') {
81
+ * const usersResult = await api.oss.getUsers({
82
+ * filter: { id: filterIds }
83
+ * });
84
+ * return usersResult.data;
85
+ * }
86
+ * return [];
87
+ * },
88
+ * {
89
+ * queryConfig: assetsSchema,
90
+ * selectedFields: ['id', 'name', 'country_of_issue'],
91
+ * relationshipKey: 'issuer_id',
92
+ * },
93
+ * logger
94
+ * );
95
+ * ```
96
+ */
97
+ export declare function executeDynamicQueryWithExternal(executeDynamicQuery: (request: {
98
+ queryConfig: QueryConfig;
99
+ selectedFields: string[];
100
+ filter?: Record<string, any>;
101
+ paginate?: PaginateInput;
102
+ }) => Promise<{
103
+ data: any[];
104
+ pageInfo?: any;
105
+ }>, externalDataFetcher: ExternalDataFetcher, options: ExecuteDynamicQueryWithExternalOptions, logger?: Logger): Promise<{
106
+ data: any[];
107
+ pageInfo?: any;
108
+ externalQueriesExecuted?: string[];
109
+ }>;
110
+ /**
111
+ * Creates a simplified external data fetcher for common use cases
112
+ * @param api - The OwneraAPI instance
113
+ * @returns External data fetcher function
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * const fetcher = createStandardExternalDataFetcher(api);
118
+ * const result = await executeDynamicQueryWithExternal(
119
+ * api.query.executeDynamicQuery,
120
+ * fetcher,
121
+ * options,
122
+ * logger
123
+ * );
124
+ * ```
125
+ */
126
+ export declare function createStandardExternalDataFetcher(api: any): ExternalDataFetcher;
@@ -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