@ingeno/pipedream-services 1.0.55

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 (115) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +102 -0
  3. package/dist/aws/apn/index.d.ts +3 -0
  4. package/dist/aws/apn/index.d.ts.map +1 -0
  5. package/dist/aws/apn/index.js +3 -0
  6. package/dist/aws/apn/index.js.map +1 -0
  7. package/dist/aws/apn/partner-central-client.d.ts +39 -0
  8. package/dist/aws/apn/partner-central-client.d.ts.map +1 -0
  9. package/dist/aws/apn/partner-central-client.js +135 -0
  10. package/dist/aws/apn/partner-central-client.js.map +1 -0
  11. package/dist/aws/apn/zoho-crm/apn-opportunities-sync-step.d.ts +20 -0
  12. package/dist/aws/apn/zoho-crm/apn-opportunities-sync-step.d.ts.map +1 -0
  13. package/dist/aws/apn/zoho-crm/apn-opportunities-sync-step.js +51 -0
  14. package/dist/aws/apn/zoho-crm/apn-opportunities-sync-step.js.map +1 -0
  15. package/dist/aws/apn/zoho-crm/apn-opportunities-sync.d.ts +42 -0
  16. package/dist/aws/apn/zoho-crm/apn-opportunities-sync.d.ts.map +1 -0
  17. package/dist/aws/apn/zoho-crm/apn-opportunities-sync.js +147 -0
  18. package/dist/aws/apn/zoho-crm/apn-opportunities-sync.js.map +1 -0
  19. package/dist/aws/apn/zoho-crm/index.d.ts +7 -0
  20. package/dist/aws/apn/zoho-crm/index.d.ts.map +1 -0
  21. package/dist/aws/apn/zoho-crm/index.js +7 -0
  22. package/dist/aws/apn/zoho-crm/index.js.map +1 -0
  23. package/dist/aws/apn/zoho-crm/opportunity-matcher.d.ts +38 -0
  24. package/dist/aws/apn/zoho-crm/opportunity-matcher.d.ts.map +1 -0
  25. package/dist/aws/apn/zoho-crm/opportunity-matcher.js +93 -0
  26. package/dist/aws/apn/zoho-crm/opportunity-matcher.js.map +1 -0
  27. package/dist/aws/apn/zoho-crm/opportunity-transformer.d.ts +35 -0
  28. package/dist/aws/apn/zoho-crm/opportunity-transformer.d.ts.map +1 -0
  29. package/dist/aws/apn/zoho-crm/opportunity-transformer.js +139 -0
  30. package/dist/aws/apn/zoho-crm/opportunity-transformer.js.map +1 -0
  31. package/dist/aws/apn/zoho-crm/sync-orchestrator.d.ts +34 -0
  32. package/dist/aws/apn/zoho-crm/sync-orchestrator.d.ts.map +1 -0
  33. package/dist/aws/apn/zoho-crm/sync-orchestrator.js +104 -0
  34. package/dist/aws/apn/zoho-crm/sync-orchestrator.js.map +1 -0
  35. package/dist/aws/apn/zoho-crm/types.d.ts +22 -0
  36. package/dist/aws/apn/zoho-crm/types.d.ts.map +1 -0
  37. package/dist/aws/apn/zoho-crm/types.js +2 -0
  38. package/dist/aws/apn/zoho-crm/types.js.map +1 -0
  39. package/dist/aws/aws-cost.d.ts +33 -0
  40. package/dist/aws/aws-cost.d.ts.map +1 -0
  41. package/dist/aws/aws-cost.js +88 -0
  42. package/dist/aws/aws-cost.js.map +1 -0
  43. package/dist/aws/commands.d.ts +12 -0
  44. package/dist/aws/commands.d.ts.map +1 -0
  45. package/dist/aws/commands.js +52 -0
  46. package/dist/aws/commands.js.map +1 -0
  47. package/dist/aws/execute-as.d.ts +42 -0
  48. package/dist/aws/execute-as.d.ts.map +1 -0
  49. package/dist/aws/execute-as.js +85 -0
  50. package/dist/aws/execute-as.js.map +1 -0
  51. package/dist/aws/index.d.ts +4 -0
  52. package/dist/aws/index.d.ts.map +1 -0
  53. package/dist/aws/index.js +4 -0
  54. package/dist/aws/index.js.map +1 -0
  55. package/dist/collections/collections-summary.d.ts +3 -0
  56. package/dist/collections/collections-summary.d.ts.map +1 -0
  57. package/dist/collections/collections-summary.js +7 -0
  58. package/dist/collections/collections-summary.js.map +1 -0
  59. package/dist/collections/collections-to-table.d.ts +6 -0
  60. package/dist/collections/collections-to-table.d.ts.map +1 -0
  61. package/dist/collections/collections-to-table.js +80 -0
  62. package/dist/collections/collections-to-table.js.map +1 -0
  63. package/dist/collections/index.d.ts +4 -0
  64. package/dist/collections/index.d.ts.map +1 -0
  65. package/dist/collections/index.js +4 -0
  66. package/dist/collections/index.js.map +1 -0
  67. package/dist/collections/types.d.ts +23 -0
  68. package/dist/collections/types.d.ts.map +1 -0
  69. package/dist/collections/types.js +2 -0
  70. package/dist/collections/types.js.map +1 -0
  71. package/dist/date/date-range.d.ts +7 -0
  72. package/dist/date/date-range.d.ts.map +1 -0
  73. package/dist/date/date-range.js +16 -0
  74. package/dist/date/date-range.js.map +1 -0
  75. package/dist/date/index.d.ts +2 -0
  76. package/dist/date/index.d.ts.map +1 -0
  77. package/dist/date/index.js +2 -0
  78. package/dist/date/index.js.map +1 -0
  79. package/dist/index.d.ts +8 -0
  80. package/dist/index.d.ts.map +1 -0
  81. package/dist/index.js +8 -0
  82. package/dist/index.js.map +1 -0
  83. package/dist/postgres/index.d.ts +2 -0
  84. package/dist/postgres/index.d.ts.map +1 -0
  85. package/dist/postgres/index.js +2 -0
  86. package/dist/postgres/index.js.map +1 -0
  87. package/dist/postgres/postgres.d.ts +15 -0
  88. package/dist/postgres/postgres.d.ts.map +1 -0
  89. package/dist/postgres/postgres.js +92 -0
  90. package/dist/postgres/postgres.js.map +1 -0
  91. package/dist/streams/list-stream.d.ts +12 -0
  92. package/dist/streams/list-stream.d.ts.map +1 -0
  93. package/dist/streams/list-stream.js +14 -0
  94. package/dist/streams/list-stream.js.map +1 -0
  95. package/dist/temporary-files.d.ts +3 -0
  96. package/dist/temporary-files.d.ts.map +1 -0
  97. package/dist/temporary-files.js +14 -0
  98. package/dist/temporary-files.js.map +1 -0
  99. package/dist/zoho-crm/index.d.ts +7 -0
  100. package/dist/zoho-crm/index.d.ts.map +1 -0
  101. package/dist/zoho-crm/index.js +7 -0
  102. package/dist/zoho-crm/index.js.map +1 -0
  103. package/dist/zoho-crm/module-processor.d.ts +8 -0
  104. package/dist/zoho-crm/module-processor.d.ts.map +1 -0
  105. package/dist/zoho-crm/module-processor.js +118 -0
  106. package/dist/zoho-crm/module-processor.js.map +1 -0
  107. package/dist/zoho-crm/zoho-auth.d.ts +22 -0
  108. package/dist/zoho-crm/zoho-auth.d.ts.map +1 -0
  109. package/dist/zoho-crm/zoho-auth.js +92 -0
  110. package/dist/zoho-crm/zoho-auth.js.map +1 -0
  111. package/dist/zoho-crm/zoho-crm-client.d.ts +76 -0
  112. package/dist/zoho-crm/zoho-crm-client.d.ts.map +1 -0
  113. package/dist/zoho-crm/zoho-crm-client.js +303 -0
  114. package/dist/zoho-crm/zoho-crm-client.js.map +1 -0
  115. package/package.json +85 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ingeno
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # @ingeno/pipedream-services
2
+
3
+ Service utilities for Clarity data integrations.
4
+
5
+ ## Purpose
6
+
7
+ This package provides reusable service utilities for data integrations in the Clarity Pipedream project. It contains production-ready code that can be imported and used across different packages and deployed workflows.
8
+
9
+ ## Features
10
+
11
+ - **AWS Services**: Partner Central client, cost explorer, organizations, and STS utilities
12
+ - **Zoho CRM**: Complete CRM client with authentication, field metadata, and record management
13
+ - **PostgreSQL**: Database connection, table management, and bulk operations
14
+ - **Collections**: Data transformation and schema generation utilities
15
+ - **Date/Time**: Date manipulation and formatting helpers
16
+ - **Streams**: Reactive data streaming utilities
17
+
18
+ ## Usage
19
+
20
+ ### Zoho CRM Integration
21
+
22
+ ```javascript
23
+ import { ZohoCRMClient, ZohoAuth } from '@ingeno/pipedream-services'
24
+
25
+ const auth = new ZohoAuth(credentials)
26
+ const client = new ZohoCRMClient({
27
+ accessToken: await auth.getAccessToken(),
28
+ apiDomain: credentials.api_domain
29
+ })
30
+
31
+ const deals = await client.getDeals()
32
+ ```
33
+
34
+ ### PostgreSQL Operations
35
+
36
+ ```javascript
37
+ import { fillTables, collectionsToTables } from '@ingeno/pipedream-services'
38
+
39
+ const tablesRows = collectionsToTables(collections)
40
+ await fillTables({
41
+ auth: postgresCredentials,
42
+ tablesRows,
43
+ tablesPrefix: 'zoho_crm_'
44
+ })
45
+ ```
46
+
47
+ ### AWS Partner Central
48
+
49
+ ```javascript
50
+ import { PartnerCentralClient } from '@ingeno/pipedream-services'
51
+
52
+ const client = new PartnerCentralClient({ credentials })
53
+ const opportunities = await client.listAllOpportunities()
54
+ ```
55
+
56
+ ## Installation
57
+
58
+ This package is published to npm and can be installed via:
59
+
60
+ ```bash
61
+ npm install @ingeno/pipedream-services
62
+ # or
63
+ pnpm add @ingeno/pipedream-services
64
+ ```
65
+
66
+ ## Development
67
+
68
+ ```bash
69
+ # Build the package
70
+ pnpm build
71
+
72
+ # Run tests
73
+ pnpm test
74
+
75
+ # Lint code
76
+ pnpm lint
77
+
78
+ # Publish to npm
79
+ pnpm pub
80
+ ```
81
+
82
+ ## Architecture
83
+
84
+ This package contains only production code and is designed to be:
85
+
86
+ 1. **Lightweight**: No test utilities or development dependencies
87
+ 2. **Reusable**: Can be used across different packages and environments
88
+ 3. **Well-typed**: Full TypeScript support with proper type definitions
89
+ 4. **Modular**: Organized by service domain (AWS, Zoho, PostgreSQL, etc.)
90
+
91
+ ## Exports
92
+
93
+ The package provides both named and namespace exports:
94
+
95
+ - `@ingeno/pipedream-services` - Main entry point
96
+ - `@ingeno/pipedream-services/aws` - AWS-specific utilities
97
+ - `@ingeno/pipedream-services/zoho` - Zoho CRM utilities
98
+ - `@ingeno/pipedream-services/date` - Date utilities
99
+
100
+ ## License
101
+
102
+ MIT
@@ -0,0 +1,3 @@
1
+ export * from './partner-central-client.js';
2
+ export * from './zoho-crm/index.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/aws/apn/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qBAAqB,CAAA"}
@@ -0,0 +1,3 @@
1
+ export * from './partner-central-client.js';
2
+ export * from './zoho-crm/index.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/aws/apn/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qBAAqB,CAAA"}
@@ -0,0 +1,39 @@
1
+ import { OpportunitySummary, GetAwsOpportunitySummaryResponse, ListOpportunitiesResponse, GetOpportunityResponse } from '@aws-sdk/client-partnercentral-selling';
2
+ import { AwsCredentialIdentity } from '@aws-sdk/types';
3
+ import { Observable } from 'rxjs';
4
+ export interface PartnerCentralConfig {
5
+ credentials: AwsCredentialIdentity;
6
+ }
7
+ export interface StreamOpportunitiesOptions {
8
+ maxResults?: number;
9
+ lastModifiedAfter?: Date;
10
+ pageSize?: number;
11
+ includeDetails?: boolean;
12
+ includeAwsOpportunity?: boolean;
13
+ }
14
+ export interface AwsAugmentedOpportunity {
15
+ Id?: string;
16
+ AwsOpportunity?: GetAwsOpportunitySummaryResponse;
17
+ }
18
+ export declare class PartnerCentralClient {
19
+ private client;
20
+ private executor;
21
+ constructor(config: PartnerCentralConfig);
22
+ getAwsOpportunity(opportunityId: string): Promise<GetAwsOpportunitySummaryResponse | undefined>;
23
+ getOpportunity(opportunityId: string): Promise<GetOpportunityResponse>;
24
+ listOpportunities(options?: {
25
+ maxResults?: number;
26
+ nextToken?: string;
27
+ lastModifiedAfter?: Date;
28
+ }): Promise<ListOpportunitiesResponse>;
29
+ listAllOpportunities(filters?: {
30
+ maxResults?: number;
31
+ lastModifiedAfter?: Date;
32
+ }): Promise<any[]>;
33
+ getAllOpportunitiesDetailed(filters: {
34
+ maxResults?: number;
35
+ lastModifiedAfter?: Date;
36
+ }): Promise<GetOpportunityResponse[]>;
37
+ streamOpportunities(options: StreamOpportunitiesOptions): Observable<OpportunitySummary>;
38
+ }
39
+ //# sourceMappingURL=partner-central-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"partner-central-client.d.ts","sourceRoot":"","sources":["../../../src/aws/apn/partner-central-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,kBAAkB,EAClB,gCAAgC,EAChC,yBAAyB,EAIzB,sBAAsB,EACvB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AAEtD,OAAO,EAAY,UAAU,EAAa,MAAM,MAAM,CAAA;AAGtD,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,qBAAqB,CAAA;CACnC;AAED,MAAM,WAAW,0BAA0B;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,IAAI,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED,MAAM,WAAW,uBAAuB;IACtC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,cAAc,CAAC,EAAE,gCAAgC,CAAA;CAClD;AAED,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,MAAM,CAA6B;IAC3C,OAAO,CAAC,QAAQ,CAAiB;gBAErB,MAAM,EAAE,oBAAoB;IAYlC,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,gCAAgC,GAAG,SAAS,CAAC;IAe/F,cAAc,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAQtE,iBAAiB,CAAC,OAAO,GAAE;QAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,iBAAiB,CAAC,EAAE,IAAI,CAAA;KACpB,GAAG,OAAO,CAAC,yBAAyB,CAAC;IA0BrC,oBAAoB,CAAC,OAAO,GAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,iBAAiB,CAAC,EAAE,IAAI,CAAA;KAAO;IAoDpF,2BAA2B,CAAC,OAAO,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,iBAAiB,CAAC,EAAE,IAAI,CAAA;KAAE,GAAG,OAAO,CAAC,sBAAsB,EAAE,CAAC;IAgBhI,mBAAmB,CAAC,OAAO,EAAE,0BAA0B,GAAG,UAAU,CAAC,kBAAkB,CAAC;CA+BzF"}
@@ -0,0 +1,135 @@
1
+ import { GetOpportunityCommand, ListOpportunitiesCommand, PartnerCentralSellingClient, GetAwsOpportunitySummaryCommand, ResourceNotFoundException } from '@aws-sdk/client-partnercentral-selling';
2
+ import { CommandExecutor } from '../commands.js';
3
+ import { mergeMap, take, tap } from 'rxjs';
4
+ import { createPaginatedStream } from '../../streams/list-stream.js';
5
+ export class PartnerCentralClient {
6
+ client;
7
+ executor;
8
+ constructor(config) {
9
+ console.log(`šŸ”§ Initializing PartnerCentralClient`);
10
+ console.log(`šŸ”§ Credentials type: ${typeof config.credentials}`);
11
+ console.log(`šŸ”§ Has accessKeyId: ${!!config.credentials?.accessKeyId}`);
12
+ this.client = new PartnerCentralSellingClient({ ...config, region: 'us-east-1' });
13
+ this.executor = new CommandExecutor({
14
+ client: this.client,
15
+ maxConcurrency: 10, // Adjust as needed for your use case
16
+ });
17
+ console.log(`āœ… PartnerCentralClient initialized successfully`);
18
+ }
19
+ async getAwsOpportunity(opportunityId) {
20
+ const command = new GetAwsOpportunitySummaryCommand({
21
+ Catalog: 'AWS',
22
+ RelatedOpportunityIdentifier: opportunityId,
23
+ });
24
+ try {
25
+ return await this.executor.executeCommand(command, `get aws opportunity id = ${opportunityId}`);
26
+ }
27
+ catch (error) {
28
+ if (error instanceof ResourceNotFoundException) {
29
+ return undefined;
30
+ }
31
+ throw error;
32
+ }
33
+ }
34
+ async getOpportunity(opportunityId) {
35
+ const command = new GetOpportunityCommand({
36
+ Catalog: 'AWS', // Default catalog, can be overridden
37
+ Identifier: opportunityId,
38
+ });
39
+ return await this.executor.executeCommand(command, 'get opportunity');
40
+ }
41
+ async listOpportunities(options = {}) {
42
+ const { maxResults = 50, nextToken, lastModifiedAfter } = options;
43
+ const params = {
44
+ Catalog: 'AWS',
45
+ MaxResults: Math.min(maxResults, 100), // AWS API limit is 100
46
+ };
47
+ if (nextToken) {
48
+ params.NextToken = nextToken;
49
+ }
50
+ if (lastModifiedAfter) {
51
+ params.LastModifiedDate = {
52
+ AfterLastModifiedDate: lastModifiedAfter,
53
+ };
54
+ params.OpportunitySort = {
55
+ SortBy: 'LastModifiedDate',
56
+ SortOrder: 'DESCENDING',
57
+ };
58
+ }
59
+ const command = new ListOpportunitiesCommand(params);
60
+ return this.executor.executeCommand(command, 'list opportunities');
61
+ }
62
+ async listAllOpportunities(filters = {}) {
63
+ const allOpportunities = [];
64
+ let nextToken = undefined;
65
+ const { maxResults = Infinity, lastModifiedAfter } = filters;
66
+ let pageNumber = 1;
67
+ console.log(`šŸ“‹ Starting listAllOpportunities with maxResults: ${maxResults} lastModifiedAfter: ${lastModifiedAfter}`);
68
+ do {
69
+ const remainingItems = maxResults === Infinity ? 100 : maxResults - allOpportunities.length;
70
+ const pageSize = Math.min(100, remainingItems);
71
+ console.log(`šŸ“„ Page ${pageNumber}: requesting ${pageSize} items (${allOpportunities.length}/${maxResults === Infinity ? 'unlimited' : maxResults} collected so far)`);
72
+ const params = {
73
+ Catalog: 'AWS',
74
+ MaxResults: pageSize,
75
+ LastModifiedDate: {
76
+ AfterLastModifiedDate: lastModifiedAfter,
77
+ },
78
+ OpportunitySort: {
79
+ SortBy: 'LastModifiedDate',
80
+ SortOrder: 'DESCENDING', // Sort by last modified date descending
81
+ },
82
+ NextToken: nextToken,
83
+ };
84
+ const command = new ListOpportunitiesCommand(params);
85
+ const response = await this.executor.executeCommand(command, `list opportunities (page ${pageNumber})`);
86
+ const opportunities = response.OpportunitySummaries || [];
87
+ console.log(`šŸ“¦ Received ${opportunities.length} opportunities from page ${pageNumber}`);
88
+ allOpportunities.push(...opportunities);
89
+ nextToken = response.NextToken;
90
+ pageNumber++;
91
+ // Stop if we've reached the desired number of results
92
+ if (allOpportunities.length >= maxResults) {
93
+ console.log(`šŸŽÆ Reached maxResults limit (${maxResults}), stopping pagination`);
94
+ break;
95
+ }
96
+ } while (nextToken && allOpportunities.length < maxResults);
97
+ console.log(`āœ… Completed listAllOpportunities: ${allOpportunities.length} total opportunities collected`);
98
+ return allOpportunities;
99
+ }
100
+ async getAllOpportunitiesDetailed(filters) {
101
+ const summaries = await this.listAllOpportunities(filters);
102
+ const detailPromises = summaries.map(async (summary, i) => {
103
+ const opportunityId = summary.Id;
104
+ console.log(`šŸ“‹ Queuing ${i + 1}/${summaries.length}: ${opportunityId}`);
105
+ return await this.getOpportunity(opportunityId);
106
+ });
107
+ const detailedOpportunities = await Promise.all(detailPromises);
108
+ console.log(`āœ… Completed fetching details for all ${summaries.length} opportunities`);
109
+ return detailedOpportunities;
110
+ }
111
+ streamOpportunities(options) {
112
+ const withOpportunityDetails = async (opportunity) => {
113
+ const detail = await this.getOpportunity(opportunity.Id);
114
+ return { ...opportunity, ...detail };
115
+ };
116
+ const withAwsOpportunity = async (opportunity) => {
117
+ const awsOpportunity = await this.getAwsOpportunity(opportunity.Id);
118
+ return { ...opportunity, AwsOpportunity: awsOpportunity };
119
+ };
120
+ const { maxResults = 10, lastModifiedAfter, pageSize, includeDetails = false, includeAwsOpportunity = false } = options;
121
+ const request = {
122
+ Catalog: 'AWS',
123
+ LastModifiedDate: lastModifiedAfter ? { AfterLastModifiedDate: lastModifiedAfter } : undefined,
124
+ MaxResults: pageSize
125
+ };
126
+ const fn = async (options) => {
127
+ const command = new ListOpportunitiesCommand({ ...request, NextToken: options.nextPageToken, MaxResults: options.pageSize });
128
+ const response = await this.executor.executeCommand(command, 'list opportunities');
129
+ return { items: response.OpportunitySummaries || [], nextPageToken: response.NextToken };
130
+ };
131
+ return createPaginatedStream(fn, { pageSize }).pipe(take(maxResults))
132
+ .pipe((includeAwsOpportunity ? mergeMap(withAwsOpportunity) : tap()), (includeDetails ? mergeMap(withOpportunityDetails) : tap()));
133
+ }
134
+ }
135
+ //# sourceMappingURL=partner-central-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"partner-central-client.js","sourceRoot":"","sources":["../../../src/aws/apn/partner-central-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,2BAA2B,EAK3B,+BAA+B,EAC/B,yBAAyB,EAE1B,MAAM,wCAAwC,CAAA;AAE/C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,QAAQ,EAAc,IAAI,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AACtD,OAAO,EAAE,qBAAqB,EAAsC,MAAM,8BAA8B,CAAA;AAmBxG,MAAM,OAAO,oBAAoB;IACvB,MAAM,CAA6B;IACnC,QAAQ,CAAiB;IAEjC,YAAY,MAA4B;QACtC,OAAO,CAAC,GAAG,CAAC,sCAA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E,qBAAqB,GAAG,KAAK,EAAE,GAAG,OAAO,CAAA;QAEvH,MAAM,OAAO,GAA6B;YACxC,OAAO,EAAE,KAAK;YACd,gBAAgB,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,CAAC,CAAC,CAAC,SAAS;YAC9F,UAAU,EAAE,QAAQ;SACrB,CAAA;QAED,MAAM,EAAE,GAAG,KAAK,EAAE,OAA0B,EAAgD,EAAE;YAC5F,MAAM,OAAO,GAAG,IAAI,wBAAwB,CAAC,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,aAAa,EAAE,UAAU,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAA;YAC5H,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,cAAc,CAA4B,OAAO,EAAE,oBAAoB,CAAC,CAAA;YAC7G,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,oBAAoB,IAAI,EAAE,EAAE,aAAa,EAAE,QAAQ,CAAC,SAAS,EAAE,CAAA;QAC1F,CAAC,CAAA;QAED,OAAO,qBAAqB,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;aAClE,IAAI,CACH,CAAC,qBAAqB,CAAC,CAAC,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,EAC9D,CAAC,cAAc,CAAC,CAAC,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAC5D,CAAA;IACL,CAAC;CACF"}
@@ -0,0 +1,20 @@
1
+ import type { AwsCredentialIdentity } from '@aws-sdk/types';
2
+ export interface SyncAPNOpportunitiesToZohoOptions {
3
+ apn: {
4
+ mainCredentials: AwsCredentialIdentity;
5
+ accountId: string;
6
+ roleName: string;
7
+ };
8
+ zoho: {
9
+ accessToken: string;
10
+ apiDomain: string;
11
+ };
12
+ syncedDays: number;
13
+ maxRecords: number;
14
+ }
15
+ export declare const syncAPNOpportunitiesToZoho: (props: SyncAPNOpportunitiesToZohoOptions) => Promise<{
16
+ success: boolean;
17
+ message: string;
18
+ result: import("@ingeno/pipedream-services").SyncResult;
19
+ }>;
20
+ //# sourceMappingURL=apn-opportunities-sync-step.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apn-opportunities-sync-step.d.ts","sourceRoot":"","sources":["../../../../src/aws/apn/zoho-crm/apn-opportunities-sync-step.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AAE3D,MAAM,WAAW,iCAAiC;IAChD,GAAG,EAAE;QACH,eAAe,EAAE,qBAAqB,CAAC;QACvC,SAAS,EAAE,MAAM,CAAA;QACjB,QAAQ,EAAE,MAAM,CAAA;KACjB,CAAA;IACD,IAAI,EAAE;QACJ,WAAW,EAAE,MAAM,CAAC;QACpB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AACD,eAAO,MAAM,0BAA0B,GAAU,OAAO,iCAAiC;;;;EA0DxF,CAAA"}
@@ -0,0 +1,51 @@
1
+ import { ApnOpportunitiesSync, assumeRoleCredentialsProvider } from '@ingeno/pipedream-services';
2
+ import dayjs from 'dayjs';
3
+ export const syncAPNOpportunitiesToZoho = async (props) => {
4
+ const { syncedDays: syncDays = 7, maxRecords = 100 } = props;
5
+ const { accountId, roleName, mainCredentials } = props.apn;
6
+ const { accessToken, apiDomain } = props.zoho;
7
+ // Get APN credentials by assuming role
8
+ console.log(`Assuming role ${roleName} in account ${accountId}...`);
9
+ const credentialsProvider = assumeRoleCredentialsProvider({
10
+ accountId,
11
+ roleName,
12
+ mainCredentials,
13
+ });
14
+ const apnCredentials = await credentialsProvider();
15
+ console.log('Successfully assumed role');
16
+ // Initialize the sync client
17
+ const config = {
18
+ awsConfig: {
19
+ credentials: apnCredentials,
20
+ region: 'us-east-1'
21
+ },
22
+ zohoConfig: {
23
+ accessToken,
24
+ apiDomain
25
+ }
26
+ };
27
+ const apnSync = new ApnOpportunitiesSync(config);
28
+ const sinceDate = dayjs().subtract(syncDays, 'day').toDate();
29
+ const syncOptions = {
30
+ sinceDate,
31
+ maxRecords,
32
+ };
33
+ console.log(`Starting sync of APN opportunities...`);
34
+ console.log(`Looking back ${syncDays} days (since ${sinceDate.toISOString()})`);
35
+ console.log(`Max records: ${maxRecords}`);
36
+ // Execute the sync
37
+ const result = await apnSync.syncOpportunities(syncOptions);
38
+ // Log results
39
+ console.log('āœ… Sync completed successfully!');
40
+ console.log(`šŸ“Š Summary:`);
41
+ console.log(` - Total processed: ${result.totalProcessed}`);
42
+ console.log(` - Created: ${result.created}`);
43
+ console.log(` - Updated: ${result.updated}`);
44
+ console.log(` - Errors: ${result.errors}`);
45
+ return {
46
+ success: true,
47
+ message: `Synced ${result.totalProcessed} opportunities (${result.created} created, ${result.updated} updated, ${result.errors} errors)`,
48
+ result
49
+ };
50
+ };
51
+ //# sourceMappingURL=apn-opportunities-sync-step.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apn-opportunities-sync-step.js","sourceRoot":"","sources":["../../../../src/aws/apn/zoho-crm/apn-opportunities-sync-step.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,6BAA6B,EAE9B,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,MAAM,OAAO,CAAC;AAiB1B,MAAM,CAAC,MAAM,0BAA0B,GAAG,KAAK,EAAE,KAAwC,EAAE,EAAE;IAC3F,MAAM,EAAE,UAAU,EAAE,QAAQ,GAAG,CAAC,EAAE,UAAU,GAAG,GAAG,EAAE,GAAG,KAAK,CAAA;IAC5D,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,eAAe,EAAE,GAAG,KAAK,CAAC,GAAG,CAAA;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,CAAA;IAC5D,OAAO,CAAC,GAAG,CAAC,gBAAgB,MAAM,CAAC,OAAO,EAAE,CAAC,CAAA;IAC7C,OAAO,CAAC,GAAG,CAAC,gBAAgB,MAAM,CAAC,OAAO,EAAE,CAAC,CAAA;IAC7C,OAAO,CAAC,GAAG,CAAC,eAAe,MAAM,CAAC,MAAM,EAAE,CAAC,CAAA;IAE3C,OAAO;QACL,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,UAAU,MAAM,CAAC,cAAc,mBAAmB,MAAM,CAAC,OAAO,aAAa,MAAM,CAAC,OAAO,aAAa,MAAM,CAAC,MAAM,UAAU;QACxI,MAAM;KACP,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,42 @@
1
+ import { SyncOptions, SyncResult, ApnOpportunitiesSyncConfig } from './types.js';
2
+ export declare class ApnOpportunitiesSync {
3
+ private readonly partnerCentralClient;
4
+ private readonly transformer;
5
+ private readonly matcher;
6
+ private readonly orchestrator;
7
+ constructor(config: ApnOpportunitiesSyncConfig);
8
+ /**
9
+ * Main sync method - coordinates the entire sync process
10
+ * Uses streaming with buffering to avoid Zoho 414 URL length errors
11
+ */
12
+ syncOpportunities(options?: SyncOptions): Promise<SyncResult>;
13
+ /**
14
+ * Process a page of opportunities (find existing + sync)
15
+ */
16
+ private processOpportunityPage;
17
+ /**
18
+ * Process all opportunities and return aggregate results
19
+ */
20
+ private processOpportunities;
21
+ /**
22
+ * Create an empty sync result
23
+ */
24
+ private createEmptyResult;
25
+ /**
26
+ * Add an error to the result
27
+ */
28
+ private addError;
29
+ /**
30
+ * Merge individual sync results into aggregate
31
+ */
32
+ private mergeResults;
33
+ /**
34
+ * Log sync options for debugging
35
+ */
36
+ private logSyncOptions;
37
+ /**
38
+ * Log sync results
39
+ */
40
+ private logSyncResults;
41
+ }
42
+ //# sourceMappingURL=apn-opportunities-sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apn-opportunities-sync.d.ts","sourceRoot":"","sources":["../../../../src/aws/apn/zoho-crm/apn-opportunities-sync.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAA;AAGhF,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAsB;IAC3D,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAwB;IACpD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;IAC5C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAkB;gBAEnC,MAAM,EAAE,0BAA0B;IAe9C;;;OAGG;IACG,iBAAiB,CAAC,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,UAAU,CAAC;IAuDvE;;OAEG;YACW,sBAAsB;IAqBpC;;OAEG;YACW,oBAAoB;IA2BlC;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAWzB;;OAEG;IACH,OAAO,CAAC,QAAQ;IAKhB;;OAEG;IACH,OAAO,CAAC,YAAY;IAQpB;;OAEG;IACH,OAAO,CAAC,cAAc;IAQtB;;OAEG;IACH,OAAO,CAAC,cAAc;CAIvB"}
@@ -0,0 +1,147 @@
1
+ import { PartnerCentralClient } from '../partner-central-client.js';
2
+ import { ZohoCRMClient } from '../../../zoho-crm/zoho-crm-client.js';
3
+ import { OpportunityTransformer } from './opportunity-transformer.js';
4
+ import { OpportunityMatcher } from './opportunity-matcher.js';
5
+ import { SyncOrchestrator } from './sync-orchestrator.js';
6
+ import { lastValueFrom, tap, toArray, bufferCount, mergeMap } from 'rxjs';
7
+ export class ApnOpportunitiesSync {
8
+ partnerCentralClient;
9
+ transformer;
10
+ matcher;
11
+ orchestrator;
12
+ constructor(config) {
13
+ console.log('šŸ”§ Initializing ApnOpportunitiesSync');
14
+ // Initialize AWS client
15
+ this.partnerCentralClient = new PartnerCentralClient(config.awsConfig);
16
+ // Initialize Zoho client
17
+ const zohoCrmClient = new ZohoCRMClient(config.zohoConfig);
18
+ // Initialize components following dependency injection
19
+ this.transformer = new OpportunityTransformer();
20
+ this.matcher = new OpportunityMatcher(zohoCrmClient, this.transformer);
21
+ this.orchestrator = new SyncOrchestrator(zohoCrmClient, this.transformer);
22
+ }
23
+ /**
24
+ * Main sync method - coordinates the entire sync process
25
+ * Uses streaming with buffering to avoid Zoho 414 URL length errors
26
+ */
27
+ async syncOpportunities(options = {}) {
28
+ const { sinceDate, maxRecords = 1000, dryRun = false } = options;
29
+ const pageSize = 50;
30
+ console.log('šŸš€ Starting APN opportunities sync');
31
+ this.logSyncOptions(options);
32
+ try {
33
+ const aggregateResult = this.createEmptyResult();
34
+ let processedCount = 0;
35
+ let pageNumber = 1;
36
+ const stream = this.partnerCentralClient.streamOpportunities({
37
+ maxResults: maxRecords,
38
+ lastModifiedAfter: sinceDate,
39
+ pageSize,
40
+ includeDetails: true,
41
+ includeAwsOpportunity: true
42
+ }).pipe(tap(() => processedCount++), bufferCount(pageSize), mergeMap(async (opportunities) => {
43
+ console.log(`\nšŸ“„ Processing page ${pageNumber}...`);
44
+ console.log(`šŸ“„ Page ${pageNumber}: Processing ${opportunities.length} opportunities`);
45
+ // Process this page immediately
46
+ const pageResult = await this.processOpportunityPage(opportunities, pageNumber, dryRun);
47
+ // Fail fast on errors (unless dry run)
48
+ if (!dryRun && pageResult.errors > 0) {
49
+ throw new Error(`Page ${pageNumber} failed with ${pageResult.errors} errors out of ${pageResult.totalProcessed} opportunities. Total progress: ${processedCount} opportunities processed. See error details for specifics.`);
50
+ }
51
+ console.log(`šŸ“Š Page ${pageNumber} complete: Created ${pageResult.created}, Updated ${pageResult.updated}, Errors ${pageResult.errors}`);
52
+ console.log(`šŸŽÆ Total progress: ${processedCount}/${maxRecords} opportunities processed`);
53
+ pageNumber++;
54
+ return pageResult;
55
+ }), tap(pageResult => this.mergeResults(aggregateResult, pageResult)));
56
+ await lastValueFrom(stream.pipe(toArray()));
57
+ console.log(`\nšŸŽ‰ Sync completed successfully! Processed ${processedCount} opportunities across ${pageNumber - 1} pages.`);
58
+ this.logSyncResults(aggregateResult);
59
+ return aggregateResult;
60
+ }
61
+ catch (error) {
62
+ console.error('āŒ Fatal error during sync:', error);
63
+ throw new Error(`Sync failed: ${error instanceof Error ? error.message : String(error)}`);
64
+ }
65
+ }
66
+ /**
67
+ * Process a page of opportunities (find existing + sync)
68
+ */
69
+ async processOpportunityPage(opportunities, pageNumber, dryRun) {
70
+ console.log(`šŸ” Page ${pageNumber}: Searching for existing opportunities in Zoho for ${opportunities.length} AWS opportunities...`);
71
+ // Find existing opportunities in Zoho for this page (max 50, avoids 414 error)
72
+ const existingOpportunities = await this.matcher.findExistingOpportunities(opportunities);
73
+ console.log(`āœ… Page ${pageNumber}: Found ${existingOpportunities.size} existing opportunities in Zoho`);
74
+ if (existingOpportunities.size > 0) {
75
+ console.log(`šŸ“‹ Page ${pageNumber}: Existing opportunity IDs found:`, Array.from(existingOpportunities.keys()));
76
+ }
77
+ // Process each opportunity in this page
78
+ const pageResult = await this.processOpportunities(opportunities, existingOpportunities, dryRun);
79
+ return pageResult;
80
+ }
81
+ /**
82
+ * Process all opportunities and return aggregate results
83
+ */
84
+ async processOpportunities(awsOpportunities, existingOpportunities, dryRun) {
85
+ console.log('šŸ”„ Processing opportunities');
86
+ const aggregateResult = this.createEmptyResult();
87
+ for (const awsOpp of awsOpportunities) {
88
+ const opportunityId = this.transformer.extractOpportunityId(awsOpp);
89
+ if (!opportunityId) {
90
+ this.addError(aggregateResult, 'unknown', 'No opportunity ID found in AWS data');
91
+ continue;
92
+ }
93
+ const existingOpp = existingOpportunities.get(opportunityId) || null;
94
+ const result = await this.orchestrator.syncOpportunity(awsOpp, existingOpp, dryRun);
95
+ this.mergeResults(aggregateResult, result);
96
+ }
97
+ this.logSyncResults(aggregateResult);
98
+ return aggregateResult;
99
+ }
100
+ /**
101
+ * Create an empty sync result
102
+ */
103
+ createEmptyResult() {
104
+ return {
105
+ totalProcessed: 0,
106
+ created: 0,
107
+ updated: 0,
108
+ errors: 0,
109
+ errorDetails: []
110
+ };
111
+ }
112
+ /**
113
+ * Add an error to the result
114
+ */
115
+ addError(result, opportunityId, error) {
116
+ result.errors++;
117
+ result.errorDetails.push({ opportunityId, error });
118
+ }
119
+ /**
120
+ * Merge individual sync results into aggregate
121
+ */
122
+ mergeResults(aggregate, individual) {
123
+ aggregate.totalProcessed += individual.totalProcessed;
124
+ aggregate.created += individual.created;
125
+ aggregate.updated += individual.updated;
126
+ aggregate.errors += individual.errors;
127
+ aggregate.errorDetails.push(...individual.errorDetails);
128
+ }
129
+ /**
130
+ * Log sync options for debugging
131
+ */
132
+ logSyncOptions(options) {
133
+ console.log(`Options: ${JSON.stringify({
134
+ sinceDate: options.sinceDate?.toISOString() || null,
135
+ maxRecords: options.maxRecords,
136
+ dryRun: options.dryRun
137
+ })}`);
138
+ }
139
+ /**
140
+ * Log sync results
141
+ */
142
+ logSyncResults(result) {
143
+ console.log('āœ… Sync completed');
144
+ console.log(`Results: ${JSON.stringify(result, null, 2)}`);
145
+ }
146
+ }
147
+ //# sourceMappingURL=apn-opportunities-sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apn-opportunities-sync.js","sourceRoot":"","sources":["../../../../src/aws/apn/zoho-crm/apn-opportunities-sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAA;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAA;AAEpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAEzD,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAA;AAEzE,MAAM,OAAO,oBAAoB;IACd,oBAAoB,CAAsB;IAC1C,WAAW,CAAwB;IACnC,OAAO,CAAoB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AY,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,YAAY,CAAC,CAAA;IACzD,CAAC;IAED;;OAEG;IACK,cAAc,CAAC,OAAoB;QACzC,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,CAAC,SAAS,CAAC;YACrC,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,WAAW,EAAE,IAAI,IAAI;YACnD,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC,EAAE,CAAC,CAAA;IACP,CAAC;IAED;;OAEG;IACK,cAAc,CAAC,MAAkB;QACvC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAA;QAC/B,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAA;IAC5D,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ export * from './apn-opportunities-sync.js';
2
+ export * from './apn-opportunities-sync-step.js';
3
+ export * from './types.js';
4
+ export * from './opportunity-transformer.js';
5
+ export * from './opportunity-matcher.js';
6
+ export * from './sync-orchestrator.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/aws/apn/zoho-crm/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAA;AAC3C,cAAc,kCAAkC,CAAA;AAChD,cAAc,YAAY,CAAA;AAC1B,cAAc,8BAA8B,CAAA;AAC5C,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAAwB,CAAA"}
@@ -0,0 +1,7 @@
1
+ export * from './apn-opportunities-sync.js';
2
+ export * from './apn-opportunities-sync-step.js';
3
+ export * from './types.js';
4
+ export * from './opportunity-transformer.js';
5
+ export * from './opportunity-matcher.js';
6
+ export * from './sync-orchestrator.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/aws/apn/zoho-crm/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAA;AAC3C,cAAc,kCAAkC,CAAA;AAChD,cAAc,YAAY,CAAA;AAC1B,cAAc,8BAA8B,CAAA;AAC5C,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAAwB,CAAA"}