@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
@@ -0,0 +1,38 @@
1
+ import { ZohoCRMClient, ZohoCRMRecord } from '../../../zoho-crm/zoho-crm-client.js';
2
+ import { GetOpportunityCommandOutput } from '@aws-sdk/client-partnercentral-selling';
3
+ import { OpportunityTransformer } from './opportunity-transformer.js';
4
+ export declare class OpportunityMatcher {
5
+ private readonly zohoCrmClient;
6
+ private readonly transformer;
7
+ constructor(zohoCrmClient: ZohoCRMClient, transformer: OpportunityTransformer);
8
+ /**
9
+ * Find existing opportunities in Zoho CRM for the given AWS opportunities
10
+ */
11
+ findExistingOpportunities(awsOpportunities: GetOpportunityCommandOutput[]): Promise<Map<string, ZohoCRMRecord>>;
12
+ /**
13
+ * Find a single opportunity by ID
14
+ */
15
+ findSingleOpportunity(opportunityId: string): Promise<ZohoCRMRecord | null>;
16
+ /**
17
+ * Extract opportunity IDs from AWS opportunities
18
+ */
19
+ private extractOpportunityIds;
20
+ /**
21
+ * Search for opportunities by IDs in Zoho CRM
22
+ */
23
+ private searchByIds;
24
+ /**
25
+ * Build search criteria for multiple opportunity IDs
26
+ * Zoho CRM search syntax: (Opportunity_Id:equals:ID1)OR(Opportunity_Id:equals:ID2)...
27
+ */
28
+ private buildMultiIdCriteria;
29
+ /**
30
+ * Build search criteria for a single opportunity ID
31
+ */
32
+ private buildSingleIdCriteria;
33
+ /**
34
+ * Create a map of opportunity ID to Zoho record
35
+ */
36
+ private createOpportunityMap;
37
+ }
38
+ //# sourceMappingURL=opportunity-matcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opportunity-matcher.d.ts","sourceRoot":"","sources":["../../../../src/aws/apn/zoho-crm/opportunity-matcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAA;AACnF,OAAO,EAAE,2BAA2B,EAAE,MAAM,wCAAwC,CAAA;AACpF,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AAErE,qBAAa,kBAAkB;IAE3B,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,WAAW;gBADX,aAAa,EAAE,aAAa,EAC5B,WAAW,EAAE,sBAAsB;IAGtD;;OAEG;IACG,yBAAyB,CAC7B,gBAAgB,EAAE,2BAA2B,EAAE,GAC9C,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAyBtC;;OAEG;IACG,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAWjF;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAM7B;;OAEG;YACW,WAAW;IAkBzB;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IAM5B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAI7B;;OAEG;IACH,OAAO,CAAC,oBAAoB;CAW7B"}
@@ -0,0 +1,93 @@
1
+ export class OpportunityMatcher {
2
+ zohoCrmClient;
3
+ transformer;
4
+ constructor(zohoCrmClient, transformer) {
5
+ this.zohoCrmClient = zohoCrmClient;
6
+ this.transformer = transformer;
7
+ }
8
+ /**
9
+ * Find existing opportunities in Zoho CRM for the given AWS opportunities
10
+ */
11
+ async findExistingOpportunities(awsOpportunities) {
12
+ const opportunityIds = this.extractOpportunityIds(awsOpportunities);
13
+ console.log(`🔍 OpportunityMatcher: Extracted ${opportunityIds.length} opportunity IDs`);
14
+ console.log(`📋 First 10 IDs:`, opportunityIds.slice(0, 10));
15
+ if (opportunityIds.length === 0) {
16
+ console.log('⚠️ No opportunity IDs found to search for');
17
+ return new Map();
18
+ }
19
+ console.log(`🔎 Searching Zoho for ${opportunityIds.length} opportunity IDs...`);
20
+ const existingRecords = await this.searchByIds(opportunityIds);
21
+ console.log(`📊 Search returned ${existingRecords.length} records from Zoho`);
22
+ if (existingRecords.length > 0) {
23
+ console.log(`📋 First few found records:`, existingRecords.slice(0, 3).map(r => ({ id: r.id, Opportunity_Id: r.Opportunity_Id })));
24
+ }
25
+ const opportunityMap = this.createOpportunityMap(existingRecords);
26
+ console.log(`🗺️ Created map with ${opportunityMap.size} opportunities`);
27
+ return opportunityMap;
28
+ }
29
+ /**
30
+ * Find a single opportunity by ID
31
+ */
32
+ async findSingleOpportunity(opportunityId) {
33
+ const criteria = this.buildSingleIdCriteria(opportunityId);
34
+ const records = await this.zohoCrmClient.getAllRecords('APN_Opportunities', {
35
+ criteria,
36
+ fields: ['id', 'Opportunity_Id'], // id = Zoho internal ID, Opportunity_Id = AWS opportunity ID
37
+ maxRecords: 1
38
+ });
39
+ return records.length > 0 ? records[0] : null;
40
+ }
41
+ /**
42
+ * Extract opportunity IDs from AWS opportunities
43
+ */
44
+ extractOpportunityIds(awsOpportunities) {
45
+ return awsOpportunities
46
+ .map(opp => this.transformer.extractOpportunityId(opp))
47
+ .filter((id) => id !== null);
48
+ }
49
+ /**
50
+ * Search for opportunities by IDs in Zoho CRM
51
+ */
52
+ async searchByIds(opportunityIds) {
53
+ const criteria = this.buildMultiIdCriteria(opportunityIds);
54
+ console.log(`🔍 Search criteria (first 500 chars): ${criteria.substring(0, 500)}...`);
55
+ console.log(`📏 Full criteria length: ${criteria.length} characters`);
56
+ // Use getAllRecords to handle pagination automatically
57
+ const allRecords = await this.zohoCrmClient.getAllRecords('APN_Opportunities', {
58
+ criteria,
59
+ fields: ['id', 'Opportunity_Id'], // id = Zoho internal ID, Opportunity_Id = AWS opportunity ID
60
+ per_page: 200
61
+ });
62
+ console.log(`📊 getAllRecords returned ${allRecords.length} records`);
63
+ return allRecords;
64
+ }
65
+ /**
66
+ * Build search criteria for multiple opportunity IDs
67
+ * Zoho CRM search syntax: (Opportunity_Id:equals:ID1)OR(Opportunity_Id:equals:ID2)...
68
+ */
69
+ buildMultiIdCriteria(opportunityIds) {
70
+ return opportunityIds
71
+ .map(id => `(Opportunity_Id:equals:${id})`)
72
+ .join('OR');
73
+ }
74
+ /**
75
+ * Build search criteria for a single opportunity ID
76
+ */
77
+ buildSingleIdCriteria(opportunityId) {
78
+ return `Opportunity_Id:equals:${opportunityId}`;
79
+ }
80
+ /**
81
+ * Create a map of opportunity ID to Zoho record
82
+ */
83
+ createOpportunityMap(records) {
84
+ const opportunityMap = new Map();
85
+ records.forEach((record) => {
86
+ if (record.Opportunity_Id) {
87
+ opportunityMap.set(record.Opportunity_Id, record);
88
+ }
89
+ });
90
+ return opportunityMap;
91
+ }
92
+ }
93
+ //# sourceMappingURL=opportunity-matcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opportunity-matcher.js","sourceRoot":"","sources":["../../../../src/aws/apn/zoho-crm/opportunity-matcher.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,kBAAkB;IAEV;IACA;IAFnB,YACmB,aAA4B,EAC5B,WAAmC;QADnC,kBAAa,GAAb,aAAa,CAAe;QAC5B,gBAAW,GAAX,WAAW,CAAwB;IAClD,CAAC;IAEL;;OAEG;IACH,KAAK,CAAC,yBAAyB,CAC7B,gBAA+C;QAE/C,MAAM,cAAc,GAAG,IAAI,CAAC,qBAAqB,CAAC,gBAAgB,CAAC,CAAA;QAEnE,OAAO,CAAC,GAAG,CAAC,oCAAoC,cAAc,CAAC,MAAM,kBAAkB,CAAC,CAAA;QACxF,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;QAE5D,IAAI,cAAc,CAAC,M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oB,CAAC,OAAwB;QACnD,MAAM,cAAc,GAAG,IAAI,GAAG,EAAyB,CAAA;QAEvD,OAAO,CAAC,OAAO,CAAC,CAAC,MAAqB,EAAE,EAAE;YACxC,IAAI,MAAM,CAAC,cAAc,EAAE,CAAC;gBAC1B,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,CAAA;YACnD,CAAC;QACH,CAAC,CAAC,CAAA;QAEF,OAAO,cAAc,CAAA;IACvB,CAAC;CACF"}
@@ -0,0 +1,35 @@
1
+ import { GetOpportunityResponse } from '@aws-sdk/client-partnercentral-selling';
2
+ import { ZohoCRMRecord } from '../../../zoho-crm/zoho-crm-client.js';
3
+ import { AwsAugmentedOpportunity } from '../partner-central-client.js';
4
+ export declare class OpportunityTransformer {
5
+ /**
6
+ * Transform AWS opportunity to Zoho CRM format
7
+ */
8
+ transformToZohoFormat(awsOpp: GetOpportunityResponse & AwsAugmentedOpportunity): Partial<ZohoCRMRecord>;
9
+ /**
10
+ * Extract opportunity ID from AWS response
11
+ */
12
+ extractOpportunityId(awsOpp: GetOpportunityResponse): string | null;
13
+ /**
14
+ * Extract last modified date from AWS response
15
+ */
16
+ extractLastModifiedDate(awsOpp: GetOpportunityResponse): string | null;
17
+ private formatDatetime;
18
+ private formatDate;
19
+ private formatAddress;
20
+ private formatNextStepsHistory;
21
+ private calculateMRR;
22
+ /**
23
+ * Format array fields for Zoho CRM
24
+ */
25
+ private formatMultiLineText;
26
+ /**
27
+ * Remove empty fields from the record
28
+ */
29
+ private removeEmptyFields;
30
+ /**
31
+ * Get default status mapping
32
+ */
33
+ private getDefaultStatusMapping;
34
+ }
35
+ //# sourceMappingURL=opportunity-transformer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opportunity-transformer.d.ts","sourceRoot":"","sources":["../../../../src/aws/apn/zoho-crm/opportunity-transformer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,sBAAsB,EAAE,MAAM,wCAAwC,CAAA;AACtG,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAA;AAEpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAA;AAEtE,qBAAa,sBAAsB;IAEjC;;OAEG;IACH,qBAAqB,CAAC,MAAM,EAAE,sBAAsB,GAAG,uBAAuB,GAAG,OAAO,CAAC,aAAa,CAAC;IA+DvG;;OAEG;IACH,oBAAoB,CAAC,MAAM,EAAE,sBAAsB,GAAG,MAAM,GAAG,IAAI;IAInE;;OAEG;IACH,uBAAuB,CAAC,MAAM,EAAE,sBAAsB,GAAG,MAAM,GAAG,IAAI;IAItE,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,UAAU;IAKlB,OAAO,CAAC,aAAa;IAUrB,OAAO,CAAC,sBAAsB;IAS9B,OAAO,CAAC,YAAY;IAWpB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAK3B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAYzB;;OAEG;IACH,OAAO,CAAC,uBAAuB;CAYhC"}
@@ -0,0 +1,139 @@
1
+ import dayjs from 'dayjs-with-plugins';
2
+ export class OpportunityTransformer {
3
+ /**
4
+ * Transform AWS opportunity to Zoho CRM format
5
+ */
6
+ transformToZohoFormat(awsOpp) {
7
+ const zohoData = {
8
+ // Core Opportunity fields - using Zoho field names
9
+ Opportunity_Id: this.extractOpportunityId(awsOpp) || '',
10
+ Name: awsOpp.Project?.Title || 'Untitled Opportunity',
11
+ // Customer information - mapped to Zoho fields
12
+ Company_Name: awsOpp.Customer?.Account?.CompanyName || '',
13
+ AWS_Account_Id: awsOpp.Customer?.Account?.AwsAccountId || '',
14
+ Industry: awsOpp.Customer?.Account?.Industry || '',
15
+ Other_Industry: awsOpp.Customer?.Account?.OtherIndustry || '',
16
+ Website_URL: awsOpp.Customer?.Account?.WebsiteUrl || '',
17
+ Address: this.formatAddress(awsOpp.Customer?.Account?.Address),
18
+ // Contact information - mapped to Zoho fields
19
+ First_Name: awsOpp.Customer?.Contacts?.[0]?.FirstName || '',
20
+ Last_Name: awsOpp.Customer?.Contacts?.[0]?.LastName || '',
21
+ Email: awsOpp.Customer?.Contacts?.[0]?.Email || '',
22
+ Phone: awsOpp.Customer?.Contacts?.[0]?.Phone || '',
23
+ Business_Title: awsOpp.Customer?.Contacts?.[0]?.BusinessTitle || '',
24
+ // Stage and status - mapped to Zoho fields
25
+ Stage: awsOpp.LifeCycle?.Stage || '',
26
+ Target_Close_Date: this.formatDate(awsOpp.LifeCycle?.TargetCloseDate),
27
+ Close_Lost_Reason: awsOpp.LifeCycle?.ClosedLostReason || '',
28
+ AWS_Stage: awsOpp.AwsOpportunity?.LifeCycle?.Stage || '',
29
+ Origin: awsOpp.AwsOpportunity?.Origin || '',
30
+ Status: awsOpp.LifeCycle?.ReviewStatus || '',
31
+ // Opportunity details - mapped to Zoho fields
32
+ Opportunity_Type: awsOpp.OpportunityType || '',
33
+ Customer_Business_Problem: awsOpp.Project?.CustomerBusinessProblem || '',
34
+ Additional_Comments: awsOpp.Project?.AdditionalComments || '',
35
+ // Competition - mapped to Zoho fields
36
+ Competitor_Name: awsOpp.Project?.CompetitorName || '',
37
+ // Next steps and history - mapped to Zoho fields
38
+ Next_Steps: awsOpp.LifeCycle?.NextSteps || '',
39
+ Next_Steps_History: this.formatNextStepsHistory(awsOpp.LifeCycle?.NextStepsHistory),
40
+ // Financial information - mapped to Zoho fields
41
+ Expected_MRR: this.calculateMRR(awsOpp),
42
+ // Marketing - mapped to Zoho fields
43
+ Campaign_Name: awsOpp.Marketing?.CampaignName || '',
44
+ MDF_Used: awsOpp.Marketing?.AwsFundingUsed === 'Yes',
45
+ // AWS Programs and Products - mapped to Zoho fields
46
+ APN_Programs: this.formatMultiLineText(awsOpp.Project?.ApnPrograms),
47
+ AWS_Products: this.formatMultiLineText(awsOpp.RelatedEntityIdentifiers?.AwsProducts),
48
+ Solutions: this.formatMultiLineText(awsOpp.RelatedEntityIdentifiers?.Solutions),
49
+ Marketplace_Offers: this.formatMultiLineText(awsOpp.RelatedEntityIdentifiers?.AwsMarketplaceOffers),
50
+ // Timestamps - mapped to Zoho fields
51
+ APN_Created_Time: this.formatDatetime(awsOpp.CreatedDate),
52
+ APN_Last_Modified_Time: this.formatDatetime(awsOpp.LastModifiedDate),
53
+ };
54
+ // Remove empty fields
55
+ return this.removeEmptyFields(zohoData);
56
+ }
57
+ /**
58
+ * Extract opportunity ID from AWS response
59
+ */
60
+ extractOpportunityId(awsOpp) {
61
+ return awsOpp.Id || null;
62
+ }
63
+ /**
64
+ * Extract last modified date from AWS response
65
+ */
66
+ extractLastModifiedDate(awsOpp) {
67
+ return awsOpp.LastModifiedDate ? dayjs(awsOpp.LastModifiedDate).toISOString() : null;
68
+ }
69
+ formatDatetime(date) {
70
+ if (!date)
71
+ return '';
72
+ return dayjs(date).utc().format('YYYY-MM-DDTHH:mm:ss[Z]');
73
+ }
74
+ formatDate(date) {
75
+ if (!date)
76
+ return '';
77
+ return dayjs(date).format('YYYY-MM-DD');
78
+ }
79
+ formatAddress(address) {
80
+ return this.formatMultiLineText([
81
+ address.StreetAddress,
82
+ address.City,
83
+ address.StateOrRegion,
84
+ address.PostalCode,
85
+ address.CountryCode
86
+ ].filter(Boolean));
87
+ }
88
+ formatNextStepsHistory(history) {
89
+ if (!history || history.length === 0)
90
+ return '';
91
+ return history.map(h => {
92
+ const time = h.Time ? dayjs(h.Time).format('YYYY-MM-DD') : 'Unknown date';
93
+ const value = h.Value || 'No value';
94
+ return `${time}: ${value}`;
95
+ }).join('\n');
96
+ }
97
+ calculateMRR(awsOpp) {
98
+ const customerSpend = awsOpp.Project?.ExpectedCustomerSpend || [];
99
+ const amountAsString = customerSpend[0]?.Amount ?? '0';
100
+ const amount = parseFloat(amountAsString);
101
+ return amount;
102
+ }
103
+ /**
104
+ * Format array fields for Zoho CRM
105
+ */
106
+ formatMultiLineText(arr) {
107
+ if (!arr || arr.length === 0)
108
+ return '';
109
+ return arr.join(',\n');
110
+ }
111
+ /**
112
+ * Remove empty fields from the record
113
+ */
114
+ removeEmptyFields(record) {
115
+ const cleaned = {};
116
+ Object.entries(record).forEach(([key, value]) => {
117
+ if (value !== '' && value !== null && value !== undefined && value !== false) {
118
+ cleaned[key] = value;
119
+ }
120
+ });
121
+ return cleaned;
122
+ }
123
+ /**
124
+ * Get default status mapping
125
+ */
126
+ getDefaultStatusMapping() {
127
+ return {
128
+ 'Prospecting': 'New',
129
+ 'Qualification': 'Qualifying',
130
+ 'Needs Analysis': 'Needs Analysis',
131
+ 'Proposal': 'Proposal Submitted',
132
+ 'Negotiation': 'Negotiation',
133
+ 'Closed Won': 'Closed Won',
134
+ 'Closed Lost': 'Closed Lost',
135
+ 'On Hold': 'On Hold',
136
+ };
137
+ }
138
+ }
139
+ //# sourceMappingURL=opportunity-transformer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opportunity-transformer.js","sourceRoot":"","sources":["../../../../src/aws/apn/zoho-crm/opportunity-transformer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,oBAAoB,CAAA;AAGtC,MAAM,OAAO,sBAAsB;IAEjC;;OAEG;IACH,qBAAqB,CAAC,MAAwD;QAC5E,MAAM,QAAQ,GAA2B;YACvC,mDAAmD;YACnD,cAAc,EAAE,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,IAAI,EAAE;YACvD,IAAI,EAAE,MAAM,CAAC,OAAO,EAAE,KAAK,IAAI,sBAAsB;YAErD,+CAA+C;YAC/C,YAAY,EAAE,MAAM,CAAC,QAAQ,EAAE,OAAO,EAAE,WAAW,IAAI,EAAE;YACzD,cAAc,EAAE,MAAM,CAAC,QAAQ,EAAE,OAAO,EAAE,YAAY,IAAI,EAAE;YAC5D,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,IAAI,EAAE;YAClD,cAAc,EAAE,MAAM,CAAC,QAAQ,EAAE,OAAO,EAAE,aAAa,IAAI,EAAE;YAC7D,WAAW,EAAE,M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Client, ZohoCRMRecord } from '../../../zoho-crm/zoho-crm-client.js';
3
+ import { OpportunityTransformer } from './opportunity-transformer.js';
4
+ import { SyncResult } from './types.js';
5
+ /**
6
+ * Interface for orchestrating the sync process
7
+ */
8
+ export interface ISyncOrchestrator {
9
+ syncOpportunity(awsOpportunity: GetOpportunityCommandOutput, existingOpportunity: ZohoCRMRecord | null, dryRun: boolean): Promise<SyncResult>;
10
+ createOpportunity(awsOpportunity: GetOpportunityCommandOutput, dryRun: boolean): Promise<void>;
11
+ updateOpportunity(awsOpportunity: GetOpportunityCommandOutput, existingOpportunity: ZohoCRMRecord, dryRun: boolean): Promise<void>;
12
+ }
13
+ /**
14
+ * Orchestrates the sync process for individual opportunities
15
+ * Single Responsibility: Coordinating create/update operations
16
+ */
17
+ export declare class SyncOrchestrator implements ISyncOrchestrator {
18
+ private readonly zohoCrmClient;
19
+ private readonly transformer;
20
+ constructor(zohoCrmClient: ZohoCRMClient, transformer: OpportunityTransformer);
21
+ /**
22
+ * Sync a single opportunity (create or update)
23
+ */
24
+ syncOpportunity(awsOpportunity: GetOpportunityCommandOutput, existingOpportunity: ZohoCRMRecord | null, dryRun: boolean): Promise<SyncResult>;
25
+ /**
26
+ * Create a new opportunity in Zoho CRM
27
+ */
28
+ createOpportunity(awsOpportunity: GetOpportunityCommandOutput, dryRun: boolean): Promise<void>;
29
+ /**
30
+ * Update an existing opportunity in Zoho CRM
31
+ */
32
+ updateOpportunity(awsOpportunity: GetOpportunityCommandOutput, existingOpportunity: ZohoCRMRecord, dryRun: boolean): Promise<void>;
33
+ }
34
+ //# sourceMappingURL=sync-orchestrator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-orchestrator.d.ts","sourceRoot":"","sources":["../../../../src/aws/apn/zoho-crm/sync-orchestrator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,wCAAwC,CAAA;AACpF,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAA;AACnF,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvC;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,eAAe,CACb,cAAc,EAAE,2BAA2B,EAC3C,mBAAmB,EAAE,aAAa,GAAG,IAAI,EACzC,MAAM,EAAE,OAAO,GACd,OAAO,CAAC,UAAU,CAAC,CAAA;IAEtB,iBAAiB,CACf,cAAc,EAAE,2BAA2B,EAC3C,MAAM,EAAE,OAAO,GACd,OAAO,CAAC,IAAI,CAAC,CAAA;IAEhB,iBAAiB,CACf,cAAc,EAAE,2BAA2B,EAC3C,mBAAmB,EAAE,aAAa,EAClC,MAAM,EAAE,OAAO,GACd,OAAO,CAAC,IAAI,CAAC,CAAA;CACjB;AAED;;;GAGG;AACH,qBAAa,gBAAiB,YAAW,iBAAiB;IAEtD,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,WAAW;gBADX,aAAa,EAAE,aAAa,EAC5B,WAAW,EAAE,sBAAsB;IAGtD;;OAEG;IACG,eAAe,CACnB,cAAc,EAAE,2BAA2B,EAC3C,mBAAmB,EAAE,aAAa,GAAG,IAAI,EACzC,MAAM,EAAE,OAAO,GACd,OAAO,CAAC,UAAU,CAAC;IAgEtB;;OAEG;IACG,iBAAiB,CACrB,cAAc,EAAE,2BAA2B,EAC3C,MAAM,EAAE,OAAO,GACd,OAAO,CAAC,IAAI,CAAC;IAchB;;OAEG;IACG,iBAAiB,CACrB,cAAc,EAAE,2BAA2B,EAC3C,mBAAmB,EAAE,aAAa,EAClC,MAAM,EAAE,OAAO,GACd,OAAO,CAAC,IAAI,CAAC;CAajB"}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Orchestrates the sync process for individual opportunities
3
+ * Single Responsibility: Coordinating create/update operations
4
+ */
5
+ export class SyncOrchestrator {
6
+ zohoCrmClient;
7
+ transformer;
8
+ constructor(zohoCrmClient, transformer) {
9
+ this.zohoCrmClient = zohoCrmClient;
10
+ this.transformer = transformer;
11
+ }
12
+ /**
13
+ * Sync a single opportunity (create or update)
14
+ */
15
+ async syncOpportunity(awsOpportunity, existingOpportunity, dryRun) {
16
+ const result = {
17
+ totalProcessed: 1,
18
+ created: 0,
19
+ updated: 0,
20
+ errors: 0,
21
+ errorDetails: []
22
+ };
23
+ const opportunityId = this.transformer.extractOpportunityId(awsOpportunity);
24
+ if (!opportunityId) {
25
+ result.errors = 1;
26
+ result.errorDetails.push({
27
+ opportunityId: 'unknown',
28
+ error: 'No opportunity ID found in AWS data'
29
+ });
30
+ return result;
31
+ }
32
+ try {
33
+ if (existingOpportunity) {
34
+ await this.updateOpportunity(awsOpportunity, existingOpportunity, dryRun);
35
+ result.updated = 1;
36
+ }
37
+ else {
38
+ await this.createOpportunity(awsOpportunity, dryRun);
39
+ result.created = 1;
40
+ }
41
+ }
42
+ catch (error) {
43
+ result.errors = 1;
44
+ // Extract detailed error information
45
+ let errorMessage = error instanceof Error ? error.message : String(error);
46
+ // Check if this is an AbortError wrapping the original error with response data
47
+ if (error.error?.response?.data) {
48
+ try {
49
+ const zohoError = JSON.stringify(error.error.response.data, null, 2);
50
+ errorMessage = `${errorMessage}\nZoho Response: ${zohoError}`;
51
+ }
52
+ catch (e) {
53
+ // Fallback if JSON.stringify fails
54
+ errorMessage = `${errorMessage}\nZoho Response: ${error.error.response.data}`;
55
+ }
56
+ }
57
+ // Also check if error has response data directly
58
+ else if (error.response?.data) {
59
+ try {
60
+ const zohoError = JSON.stringify(error.response.data, null, 2);
61
+ errorMessage = `${errorMessage}\nZoho Response: ${zohoError}`;
62
+ }
63
+ catch (e) {
64
+ // Fallback if JSON.stringify fails
65
+ errorMessage = `${errorMessage}\nZoho Response: ${error.response.data}`;
66
+ }
67
+ }
68
+ result.errorDetails.push({
69
+ opportunityId,
70
+ error: errorMessage
71
+ });
72
+ }
73
+ return result;
74
+ }
75
+ /**
76
+ * Create a new opportunity in Zoho CRM
77
+ */
78
+ async createOpportunity(awsOpportunity, dryRun) {
79
+ const opportunityId = this.transformer.extractOpportunityId(awsOpportunity) || 'unknown';
80
+ const zohoData = this.transformer.transformToZohoFormat(awsOpportunity);
81
+ if (dryRun) {
82
+ console.log(`[DRY RUN] Would create opportunity ${opportunityId}`);
83
+ console.log(`[DRY RUN] Zoho data: ${JSON.stringify(zohoData, null, 2)}`);
84
+ return;
85
+ }
86
+ console.log(`➕ Creating opportunity ${opportunityId}`);
87
+ await this.zohoCrmClient.createAPNOpportunity(zohoData);
88
+ }
89
+ /**
90
+ * Update an existing opportunity in Zoho CRM
91
+ */
92
+ async updateOpportunity(awsOpportunity, existingOpportunity, dryRun) {
93
+ const opportunityId = this.transformer.extractOpportunityId(awsOpportunity) || 'unknown';
94
+ const zohoData = this.transformer.transformToZohoFormat(awsOpportunity);
95
+ if (dryRun) {
96
+ console.log(`[DRY RUN] Would update opportunity ${opportunityId}`);
97
+ console.log(`[DRY RUN] Zoho data: ${JSON.stringify(zohoData, null, 2)}`);
98
+ return;
99
+ }
100
+ console.log(`📝 Updating opportunity ${opportunityId}`);
101
+ await this.zohoCrmClient.updateAPNOpportunity(existingOpportunity.id, zohoData);
102
+ }
103
+ }
104
+ //# sourceMappingURL=sync-orchestrator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-orchestrator.js","sourceRoot":"","sources":["../../../../src/aws/apn/zoho-crm/sync-orchestrator.ts"],"names":[],"mappings":"AA2BA;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IAER;IACA;IAFnB,YACmB,aAA4B,EAC5B,WAAmC;QADnC,kBAAa,GAAb,aAAa,CAAe;QAC5B,gBAAW,GAAX,WAAW,CAAwB;IAClD,CAAC;IAEL;;OAEG;IACH,KAAK,CAAC,eAAe,CACnB,cAA2C,EAC3C,mBAAyC,EACzC,MAAe;QAEf,MAAM,MAAM,GAAe;YACzB,cAAc,EAAE,CAAC;YACjB,OAA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C;QAED,OAAO,CAAC,GAAG,CAAC,0BAA0B,aAAa,EAAE,CAAC,CAAA;QACtD,MAAM,IAAI,CAAC,aAAa,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAA;IACzD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,iBAAiB,CACrB,cAA2C,EAC3C,mBAAkC,EAClC,MAAe;QAEf,MAAM,aAAa,GAAG,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,cAAc,CAAC,IAAI,SAAS,CAAA;QACxF,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,qBAAqB,CAAC,cAAc,CAAC,CAAA;QAEvE,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,CAAC,GAAG,CAAC,sCAAsC,aAAa,EAAE,CAAC,CAAA;YAClE,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAA;YACxE,OAAM;QACR,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,2BAA2B,aAAa,EAAE,CAAC,CAAA;QACvD,MAAM,IAAI,CAAC,aAAa,CAAC,oBAAoB,CAAC,mBAAmB,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAA;IACjF,CAAC;CACF"}
@@ -0,0 +1,22 @@
1
+ import { PartnerCentralConfig } from '../partner-central-client.js';
2
+ import { ZohoCRMConfig } from '../../../zoho-crm/zoho-crm-client.js';
3
+ export interface SyncOptions {
4
+ sinceDate?: Date;
5
+ maxRecords?: number;
6
+ dryRun?: boolean;
7
+ }
8
+ export interface SyncResult {
9
+ totalProcessed: number;
10
+ created: number;
11
+ updated: number;
12
+ errors: number;
13
+ errorDetails: Array<{
14
+ opportunityId: string;
15
+ error: string;
16
+ }>;
17
+ }
18
+ export interface ApnOpportunitiesSyncConfig {
19
+ awsConfig: PartnerCentralConfig;
20
+ zohoConfig: ZohoCRMConfig;
21
+ }
22
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/aws/apn/zoho-crm/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAA;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAA;AAEpE,MAAM,WAAW,WAAW;IAC1B,SAAS,CAAC,EAAE,IAAI,CAAA;IAChB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAED,MAAM,WAAW,UAAU;IACzB,cAAc,EAAE,MAAM,CAAA;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,KAAK,CAAC;QAClB,aAAa,EAAE,MAAM,CAAA;QACrB,KAAK,EAAE,MAAM,CAAA;KACd,CAAC,CAAA;CACH;AAED,MAAM,WAAW,0BAA0B;IACzC,SAAS,EAAE,oBAAoB,CAAA;IAC/B,UAAU,EAAE,aAAa,CAAA;CAC1B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/aws/apn/zoho-crm/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,33 @@
1
+ import { DateRange } from '../date/date-range.js';
2
+ export interface AwsCostData {
3
+ date: string;
4
+ account_id: string;
5
+ service: string;
6
+ BlendedCost: string;
7
+ UnblendedCost: string;
8
+ UsageQuantity: string;
9
+ NormalizedUsageAmount: string;
10
+ AmortizedCost: string;
11
+ NetUnblendedCost: string;
12
+ NetAmortizedCost: string;
13
+ }
14
+ export interface AwsAccount {
15
+ Id: string;
16
+ Arn: string;
17
+ Name: string;
18
+ Status: string;
19
+ JoinedMethod: string;
20
+ JoinedTimestamp: string;
21
+ }
22
+ export interface AwsCostCollectionResult {
23
+ costsAndUsages: AwsCostData[];
24
+ accounts: AwsAccount[];
25
+ }
26
+ export declare class AwsCostService {
27
+ private readonly costMetrics;
28
+ getDateRange(): DateRange;
29
+ getCollections(credentials: any): Promise<AwsCostCollectionResult>;
30
+ private listAWSAccounts;
31
+ private getAwsCosts;
32
+ }
33
+ //# sourceMappingURL=aws-cost.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aws-cost.d.ts","sourceRoot":"","sources":["../../src/aws/aws-cost.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAa,MAAM,uBAAuB,CAAA;AAE5D,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,EAAE,MAAM,CAAA;IACnB,aAAa,EAAE,MAAM,CAAA;IACrB,aAAa,EAAE,MAAM,CAAA;IACrB,qBAAqB,EAAE,MAAM,CAAA;IAC7B,aAAa,EAAE,MAAM,CAAA;IACrB,gBAAgB,EAAE,MAAM,CAAA;IACxB,gBAAgB,EAAE,MAAM,CAAA;CACzB;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAA;IACV,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,MAAM,CAAA;IACpB,eAAe,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,uBAAuB;IACtC,cAAc,EAAE,WAAW,EAAE,CAAA;IAC7B,QAAQ,EAAE,UAAU,EAAE,CAAA;CACvB;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAsI;IAE3J,YAAY,IAAI,SAAS;IAInB,cAAc,CAAC,WAAW,EAAE,GAAG,GAAG,OAAO,CAAC,uBAAuB,CAAC;YAoCjE,eAAe;YAmBf,WAAW;CAuC1B"}
@@ -0,0 +1,88 @@
1
+ import { CostExplorerClient, GetCostAndUsageCommand } from '@aws-sdk/client-cost-explorer';
2
+ import { OrganizationsClient, ListAccountsCommand } from '@aws-sdk/client-organizations';
3
+ import { monthsAgo } from '../date/date-range.js';
4
+ export class AwsCostService {
5
+ costMetrics = ['BlendedCost', 'UnblendedCost', 'UsageQuantity', 'NormalizedUsageAmount', 'AmortizedCost', 'NetUnblendedCost', 'NetAmortizedCost'];
6
+ getDateRange() {
7
+ return monthsAgo(1);
8
+ }
9
+ async getCollections(credentials) {
10
+ const costExplorer = new CostExplorerClient({
11
+ credentials,
12
+ region: 'us-east-1'
13
+ });
14
+ const organizations = new OrganizationsClient({
15
+ credentials,
16
+ region: 'us-east-1'
17
+ });
18
+ const dateRange = this.getDateRange();
19
+ const accounts = await this.listAWSAccounts(organizations);
20
+ const costs = await this.getAwsCosts(costExplorer, dateRange);
21
+ const costsAndUsages = costs.map(month => month.Groups?.map((group) => {
22
+ const date = month.TimePeriod?.Start || '';
23
+ const account_id = group.Keys?.[0] || '';
24
+ const service = group.Keys?.[1] || '';
25
+ return {
26
+ date,
27
+ account_id,
28
+ service,
29
+ ...this.costMetrics.reduce((acc, metric) => ({
30
+ ...acc,
31
+ [metric]: group.Metrics?.[metric]?.Amount || '0'
32
+ }), {})
33
+ };
34
+ }) || []).flat();
35
+ return { costsAndUsages, accounts };
36
+ }
37
+ async listAWSAccounts(organizations) {
38
+ try {
39
+ let accounts = [];
40
+ let nextToken;
41
+ do {
42
+ const command = new ListAccountsCommand({ NextToken: nextToken });
43
+ const data = await organizations.send(command);
44
+ accounts = accounts.concat(data.Accounts || []);
45
+ nextToken = data.NextToken;
46
+ } while (nextToken);
47
+ return accounts;
48
+ }
49
+ catch (error) {
50
+ console.error('Error listing AWS accounts:', error);
51
+ throw error;
52
+ }
53
+ }
54
+ async getAwsCosts(costExplorer, dateRange) {
55
+ const paramMetrics = this.costMetrics.map(metric => metric.replace(/([a-z])([A-Z])/g, '$1_$2').toUpperCase());
56
+ const input = {
57
+ TimePeriod: {
58
+ Start: dateRange.startDate,
59
+ End: dateRange.endDate
60
+ },
61
+ Granularity: 'DAILY',
62
+ Metrics: paramMetrics,
63
+ GroupBy: [
64
+ {
65
+ Type: 'DIMENSION',
66
+ Key: 'LINKED_ACCOUNT'
67
+ },
68
+ {
69
+ Type: 'DIMENSION',
70
+ Key: 'SERVICE'
71
+ }
72
+ ]
73
+ };
74
+ let allResults = [];
75
+ let nextPageToken;
76
+ do {
77
+ const command = new GetCostAndUsageCommand({
78
+ ...input,
79
+ NextPageToken: nextPageToken
80
+ });
81
+ const data = await costExplorer.send(command);
82
+ allResults = allResults.concat(data.ResultsByTime || []);
83
+ nextPageToken = data.NextPageToken;
84
+ } while (nextPageToken);
85
+ return allResults;
86
+ }
87
+ }
88
+ //# sourceMappingURL=aws-cost.js.map