@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.
- package/LICENSE +21 -0
- package/README.md +102 -0
- package/dist/aws/apn/index.d.ts +3 -0
- package/dist/aws/apn/index.d.ts.map +1 -0
- package/dist/aws/apn/index.js +3 -0
- package/dist/aws/apn/index.js.map +1 -0
- package/dist/aws/apn/partner-central-client.d.ts +39 -0
- package/dist/aws/apn/partner-central-client.d.ts.map +1 -0
- package/dist/aws/apn/partner-central-client.js +135 -0
- package/dist/aws/apn/partner-central-client.js.map +1 -0
- package/dist/aws/apn/zoho-crm/apn-opportunities-sync-step.d.ts +20 -0
- package/dist/aws/apn/zoho-crm/apn-opportunities-sync-step.d.ts.map +1 -0
- package/dist/aws/apn/zoho-crm/apn-opportunities-sync-step.js +51 -0
- package/dist/aws/apn/zoho-crm/apn-opportunities-sync-step.js.map +1 -0
- package/dist/aws/apn/zoho-crm/apn-opportunities-sync.d.ts +42 -0
- package/dist/aws/apn/zoho-crm/apn-opportunities-sync.d.ts.map +1 -0
- package/dist/aws/apn/zoho-crm/apn-opportunities-sync.js +147 -0
- package/dist/aws/apn/zoho-crm/apn-opportunities-sync.js.map +1 -0
- package/dist/aws/apn/zoho-crm/index.d.ts +7 -0
- package/dist/aws/apn/zoho-crm/index.d.ts.map +1 -0
- package/dist/aws/apn/zoho-crm/index.js +7 -0
- package/dist/aws/apn/zoho-crm/index.js.map +1 -0
- package/dist/aws/apn/zoho-crm/opportunity-matcher.d.ts +38 -0
- package/dist/aws/apn/zoho-crm/opportunity-matcher.d.ts.map +1 -0
- package/dist/aws/apn/zoho-crm/opportunity-matcher.js +93 -0
- package/dist/aws/apn/zoho-crm/opportunity-matcher.js.map +1 -0
- package/dist/aws/apn/zoho-crm/opportunity-transformer.d.ts +35 -0
- package/dist/aws/apn/zoho-crm/opportunity-transformer.d.ts.map +1 -0
- package/dist/aws/apn/zoho-crm/opportunity-transformer.js +139 -0
- package/dist/aws/apn/zoho-crm/opportunity-transformer.js.map +1 -0
- package/dist/aws/apn/zoho-crm/sync-orchestrator.d.ts +34 -0
- package/dist/aws/apn/zoho-crm/sync-orchestrator.d.ts.map +1 -0
- package/dist/aws/apn/zoho-crm/sync-orchestrator.js +104 -0
- package/dist/aws/apn/zoho-crm/sync-orchestrator.js.map +1 -0
- package/dist/aws/apn/zoho-crm/types.d.ts +22 -0
- package/dist/aws/apn/zoho-crm/types.d.ts.map +1 -0
- package/dist/aws/apn/zoho-crm/types.js +2 -0
- package/dist/aws/apn/zoho-crm/types.js.map +1 -0
- package/dist/aws/aws-cost.d.ts +33 -0
- package/dist/aws/aws-cost.d.ts.map +1 -0
- package/dist/aws/aws-cost.js +88 -0
- package/dist/aws/aws-cost.js.map +1 -0
- package/dist/aws/commands.d.ts +12 -0
- package/dist/aws/commands.d.ts.map +1 -0
- package/dist/aws/commands.js +52 -0
- package/dist/aws/commands.js.map +1 -0
- package/dist/aws/execute-as.d.ts +42 -0
- package/dist/aws/execute-as.d.ts.map +1 -0
- package/dist/aws/execute-as.js +85 -0
- package/dist/aws/execute-as.js.map +1 -0
- package/dist/aws/index.d.ts +4 -0
- package/dist/aws/index.d.ts.map +1 -0
- package/dist/aws/index.js +4 -0
- package/dist/aws/index.js.map +1 -0
- package/dist/collections/collections-summary.d.ts +3 -0
- package/dist/collections/collections-summary.d.ts.map +1 -0
- package/dist/collections/collections-summary.js +7 -0
- package/dist/collections/collections-summary.js.map +1 -0
- package/dist/collections/collections-to-table.d.ts +6 -0
- package/dist/collections/collections-to-table.d.ts.map +1 -0
- package/dist/collections/collections-to-table.js +80 -0
- package/dist/collections/collections-to-table.js.map +1 -0
- package/dist/collections/index.d.ts +4 -0
- package/dist/collections/index.d.ts.map +1 -0
- package/dist/collections/index.js +4 -0
- package/dist/collections/index.js.map +1 -0
- package/dist/collections/types.d.ts +23 -0
- package/dist/collections/types.d.ts.map +1 -0
- package/dist/collections/types.js +2 -0
- package/dist/collections/types.js.map +1 -0
- package/dist/date/date-range.d.ts +7 -0
- package/dist/date/date-range.d.ts.map +1 -0
- package/dist/date/date-range.js +16 -0
- package/dist/date/date-range.js.map +1 -0
- package/dist/date/index.d.ts +2 -0
- package/dist/date/index.d.ts.map +1 -0
- package/dist/date/index.js +2 -0
- package/dist/date/index.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/postgres/index.d.ts +2 -0
- package/dist/postgres/index.d.ts.map +1 -0
- package/dist/postgres/index.js +2 -0
- package/dist/postgres/index.js.map +1 -0
- package/dist/postgres/postgres.d.ts +15 -0
- package/dist/postgres/postgres.d.ts.map +1 -0
- package/dist/postgres/postgres.js +92 -0
- package/dist/postgres/postgres.js.map +1 -0
- package/dist/streams/list-stream.d.ts +12 -0
- package/dist/streams/list-stream.d.ts.map +1 -0
- package/dist/streams/list-stream.js +14 -0
- package/dist/streams/list-stream.js.map +1 -0
- package/dist/temporary-files.d.ts +3 -0
- package/dist/temporary-files.d.ts.map +1 -0
- package/dist/temporary-files.js +14 -0
- package/dist/temporary-files.js.map +1 -0
- package/dist/zoho-crm/index.d.ts +7 -0
- package/dist/zoho-crm/index.d.ts.map +1 -0
- package/dist/zoho-crm/index.js +7 -0
- package/dist/zoho-crm/index.js.map +1 -0
- package/dist/zoho-crm/module-processor.d.ts +8 -0
- package/dist/zoho-crm/module-processor.d.ts.map +1 -0
- package/dist/zoho-crm/module-processor.js +118 -0
- package/dist/zoho-crm/module-processor.js.map +1 -0
- package/dist/zoho-crm/zoho-auth.d.ts +22 -0
- package/dist/zoho-crm/zoho-auth.d.ts.map +1 -0
- package/dist/zoho-crm/zoho-auth.js +92 -0
- package/dist/zoho-crm/zoho-auth.js.map +1 -0
- package/dist/zoho-crm/zoho-crm-client.d.ts +76 -0
- package/dist/zoho-crm/zoho-crm-client.d.ts.map +1 -0
- package/dist/zoho-crm/zoho-crm-client.js +303 -0
- package/dist/zoho-crm/zoho-crm-client.js.map +1 -0
- package/package.json +85 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aws-cost.js","sourceRoot":"","sources":["../../src/aws/aws-cost.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAA;AAC1F,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAA;AACxF,OAAO,EAAa,SAAS,EAAE,MAAM,uBAAuB,CAAA;AA6B5D,MAAM,OAAO,cAAc;IACR,WAAW,GAAG,CAAC,aAAa,EAAE,eAAe,EAAE,eAAe,EAAE,uBAAuB,EAAE,eAAe,EAAE,kBAAkB,EAAE,kBAAkB,CAAC,CAAA;IAE3J,YAAY;QACjB,OAAO,SAAS,CAAC,CAAC,CAAC,CAAA;IACrB,CAAC;IAEM,KAAK,CAAC,cAAc,CAAC,WAAgB;QAC1C,MAAM,YAAY,GAAG,IAAI,kBAAkB,CAAC;YAC1C,WAAW;YACX,MAAM,EAAE,WAAW;SACpB,CAAC,CAAA;QACF,MAAM,aAAa,GAAG,IAAI,mBAAmB,CAAC;YAC5C,WAAW;YACX,MAAM,EAAE,WAAW;SACpB,CAAC,CAAA;QAEF,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE,CAAA;QAErC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,CAAA;QAC1D,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,SAAS,CAAC,CAAA;QAE7D,MAAM,cAAc,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CACvC,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,KAAU,EAAE,EAAE;YAC/B,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,EAAE,KAAK,IAAI,EAAE,CAAA;YAC1C,MAAM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CAAC,WAAW,CAAC,YAAgC,EAAE,SAAoB;QAC9E,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CACjD,MAAM,CAAC,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC,WAAW,EAAE,CACzD,CAAA;QAED,MAAM,KAAK,GAAG;YACZ,UAAU,EAAE;gBACV,KAAK,EAAE,SAAS,CAAC,SAAS;gBAC1B,GAAG,EAAE,SAAS,CAAC,OAAO;aACvB;YACD,WAAW,EAAE,OAAgB;YAC7B,OAAO,EAAE,YAAY;YACrB,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,WAAoB;oBAC1B,GAAG,EAAE,gBAAgB;iBACtB;gBACD;oBACE,IAAI,EAAE,WAAoB;oBAC1B,GAAG,EAAE,SAAS;iBACf;aACF;SACF,CAAA;QAED,IAAI,UAAU,GAAU,EAAE,CAAA;QAC1B,IAAI,aAAiC,CAAA;QAErC,GAAG,CAAC;YACF,MAAM,OAAO,GAAG,IAAI,sBAAsB,CAAC;gBACzC,GAAG,KAAK;gBACR,aAAa,EAAE,aAAa;aAC7B,CAAC,CAAA;YACF,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;YAC7C,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,IAAI,EAAE,CAAC,CAAA;YACxD,aAAa,GAAG,IAAI,CAAC,aAAa,CAAA;QACpC,CAAC,QAAQ,aAAa,EAAC;QAEvB,OAAO,UAAU,CAAA;IACnB,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface CommandExecutorOptions {
|
|
2
|
+
client: any;
|
|
3
|
+
maxConcurrency?: number;
|
|
4
|
+
}
|
|
5
|
+
export declare const isThrottlingError: (error: any) => boolean;
|
|
6
|
+
export declare class CommandExecutor {
|
|
7
|
+
private client;
|
|
8
|
+
private limiter;
|
|
9
|
+
constructor(options: CommandExecutorOptions);
|
|
10
|
+
executeCommand<T>(command: any, operationName: string): Promise<T>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/aws/commands.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,GAAG,CAAC;IACZ,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAGD,eAAO,MAAM,iBAAiB,GAAI,OAAO,GAAG,KAAG,OAS9C,CAAA;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAM;IACpB,OAAO,CAAC,OAAO,CAAM;gBAET,OAAO,EAAE,sBAAsB;IAO9B,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;CAqChF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import pRetry from 'p-retry';
|
|
2
|
+
import pLimiter from 'p-limit';
|
|
3
|
+
import { AbortError } from 'p-retry';
|
|
4
|
+
// Helper function to detect throttling errors
|
|
5
|
+
export const isThrottlingError = (error) => {
|
|
6
|
+
return (error.name === 'ThrottlingException' ||
|
|
7
|
+
error.name === 'TooManyRequestsException' ||
|
|
8
|
+
error.message?.includes('throttl') ||
|
|
9
|
+
error.message?.includes('rate limit') ||
|
|
10
|
+
error.message?.includes('Too Many Requests') ||
|
|
11
|
+
error.$metadata?.httpStatusCode === 429);
|
|
12
|
+
};
|
|
13
|
+
export class CommandExecutor {
|
|
14
|
+
client;
|
|
15
|
+
limiter;
|
|
16
|
+
constructor(options) {
|
|
17
|
+
const { client, maxConcurrency = 10 } = options;
|
|
18
|
+
this.client = client;
|
|
19
|
+
this.limiter = pLimiter(maxConcurrency);
|
|
20
|
+
}
|
|
21
|
+
async executeCommand(command, operationName) {
|
|
22
|
+
return this.limiter(async () => {
|
|
23
|
+
return pRetry(async (attemptNumber) => {
|
|
24
|
+
try {
|
|
25
|
+
if (attemptNumber > 1) {
|
|
26
|
+
console.log(`🔄 Retrying ${operationName} (attempt ${attemptNumber})`);
|
|
27
|
+
}
|
|
28
|
+
const response = await this.client.send(command);
|
|
29
|
+
return response;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (isThrottlingError(error)) {
|
|
33
|
+
console.log(`🕐 Throttling detected for ${operationName} (attempt ${attemptNumber}), will retry with backoff`);
|
|
34
|
+
throw error; // Let p-retry handle the backoff
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
throw new AbortError(error);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}, {
|
|
41
|
+
retries: 5,
|
|
42
|
+
factor: 2,
|
|
43
|
+
minTimeout: 1000,
|
|
44
|
+
maxTimeout: 30000,
|
|
45
|
+
onFailedAttempt: (error) => {
|
|
46
|
+
console.log(`⏳ Retry ${error.attemptNumber}/${error.retriesLeft + error.attemptNumber} for ${operationName} failed, retrying in ${error.timeout}ms`);
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../../src/aws/commands.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,SAAS,CAAC;AAC7B,OAAO,QAAQ,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAOrC,8CAA8C;AAC9C,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAU,EAAW,EAAE;IACvD,OAAO,CACL,KAAK,CAAC,IAAI,KAAK,qBAAqB;QACpC,KAAK,CAAC,IAAI,KAAK,0BAA0B;QACzC,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,SAAS,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AC;gBACV,MAAM,EAAE,CAAC;gBACT,UAAU,EAAE,IAAI;gBAChB,UAAU,EAAE,KAAK;gBACjB,eAAe,EAAE,CAAC,KAAK,EAAE,EAAE;oBACzB,OAAO,CAAC,GAAG,CACT,WAAW,KAAK,CAAC,aAAa,IAAI,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC,aAC5D,QAAQ,aAAa,wBAAyB,KAAa,CAAC,OAAO,IAAI,CACxE,CAAA;gBACH,CAAC;aACF,CACF,CAAA;QACH,CAAC,CACA,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { AwsCredentialIdentity, AwsCredentialIdentityProvider } from '@aws-sdk/types';
|
|
2
|
+
export interface ExecutionContext {
|
|
3
|
+
accountId: string | (() => Promise<string>);
|
|
4
|
+
credentials: AwsCredentialIdentity | (() => Promise<AwsCredentialIdentity>);
|
|
5
|
+
}
|
|
6
|
+
export interface AssumeRoleOptions {
|
|
7
|
+
accountId: string;
|
|
8
|
+
roleName: string;
|
|
9
|
+
mainCredentials: AwsCredentialIdentity;
|
|
10
|
+
region?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const assumeRoleCredentialsProvider: (options: AssumeRoleOptions) => AwsCredentialIdentityProvider;
|
|
13
|
+
export declare const assumeRoleExecutionContext: (options: AssumeRoleOptions) => ExecutionContext;
|
|
14
|
+
export interface AllExecutionContextsOptions {
|
|
15
|
+
mainAccountId: string;
|
|
16
|
+
mainCredentials: AwsCredentialIdentity;
|
|
17
|
+
includeMainAccountExecutionContext?: boolean;
|
|
18
|
+
accountIds: string[];
|
|
19
|
+
roleNameToAssume: string;
|
|
20
|
+
}
|
|
21
|
+
export declare const allExecutionContexts: (options: AllExecutionContextsOptions) => ExecutionContext[];
|
|
22
|
+
/**
|
|
23
|
+
* Execute a function with assumed AWS role credentials
|
|
24
|
+
*
|
|
25
|
+
* @param options - Configuration for role assumption
|
|
26
|
+
* @param fn - Function to execute with the assumed role credentials
|
|
27
|
+
* @returns Promise that resolves with the function result
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const result = await executeAs(
|
|
32
|
+
* { accountId: '123456789012' },
|
|
33
|
+
* async (accountId, credentials) => {
|
|
34
|
+
* const s3Client = new S3Client({ credentials });
|
|
35
|
+
* return s3Client.send(new ListBucketsCommand({}));
|
|
36
|
+
* }
|
|
37
|
+
* );
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function executeAs<T>(options: ExecutionContext, fn: (accountId: string, credentials: AwsCredentialIdentity) => Promise<T>): Promise<T>;
|
|
41
|
+
export declare const executeAllAs: <T>(options: ExecutionContext[], fn: (accountId: string, credentials: AwsCredentialIdentity) => Promise<T>) => Promise<T[]>;
|
|
42
|
+
//# sourceMappingURL=execute-as.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute-as.d.ts","sourceRoot":"","sources":["../../src/aws/execute-as.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAA;AAE1F,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,GAAG,CAAC,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,CAAA;IAC3C,WAAW,EAAE,qBAAqB,GAAG,CAAC,MAAM,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAA;CAC5E;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,eAAe,EAAE,qBAAqB,CAAA;IACtC,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,eAAO,MAAM,6BAA6B,GAAI,SAAS,iBAAiB,KAAG,6BAc1E,CAAA;AAED,eAAO,MAAM,0BAA0B,GACrC,SAAS,iBAAiB,KACzB,gBAUF,CAAA;AAED,MAAM,WAAW,2BAA2B;IAC1C,aAAa,EAAE,MAAM,CAAA;IACrB,eAAe,EAAE,qBAAqB,CAAA;IACtC,kCAAkC,CAAC,EAAE,OAAO,CAAA;IAC5C,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,gBAAgB,EAAE,MAAM,CAAA;CACzB;AAED,eAAO,MAAM,oBAAoB,GAAI,SAAS,2BAA2B,KAAG,gBAAgB,EA2B3F,CAAA;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,OAAO,EAAE,gBAAgB,EACzB,EAAE,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,qBAAqB,KAAK,OAAO,CAAC,CAAC,CAAC,GACxE,OAAO,CAAC,CAAC,CAAC,CAgBZ;AAED,eAAO,MAAM,YAAY,GAAU,CAAC,EAClC,SAAS,gBAAgB,EAAE,EAC3B,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,qBAAqB,KAAK,OAAO,CAAC,CAAC,CAAC,KACxE,OAAO,CAAC,CAAC,EAAE,CAA0D,CAAA"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { fromTemporaryCredentials } from '@aws-sdk/credential-providers';
|
|
2
|
+
export const assumeRoleCredentialsProvider = (options) => {
|
|
3
|
+
const { accountId, roleName, mainCredentials, region = 'us-east-1' } = options;
|
|
4
|
+
const tempCredentialsProvider = fromTemporaryCredentials({
|
|
5
|
+
masterCredentials: mainCredentials,
|
|
6
|
+
params: {
|
|
7
|
+
RoleArn: `arn:aws:iam::${accountId}:role/${roleName}`,
|
|
8
|
+
RoleSessionName: 'AccountRoleSession',
|
|
9
|
+
},
|
|
10
|
+
clientConfig: {
|
|
11
|
+
region,
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
return tempCredentialsProvider;
|
|
15
|
+
};
|
|
16
|
+
export const assumeRoleExecutionContext = (options) => {
|
|
17
|
+
const { accountId } = options;
|
|
18
|
+
const tempCredentialsProvider = assumeRoleCredentialsProvider(options);
|
|
19
|
+
return {
|
|
20
|
+
accountId: accountId,
|
|
21
|
+
credentials: async () => {
|
|
22
|
+
return await tempCredentialsProvider();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export const allExecutionContexts = (options) => {
|
|
27
|
+
const { mainAccountId, mainCredentials, includeMainAccountExecutionContext = true, accountIds, roleNameToAssume } = options;
|
|
28
|
+
const mainExecutionContext = {
|
|
29
|
+
accountId: mainAccountId,
|
|
30
|
+
credentials: mainCredentials
|
|
31
|
+
};
|
|
32
|
+
const assumedExecutionContexts = accountIds.map((accountId) => ({
|
|
33
|
+
accountId: mainAccountId,
|
|
34
|
+
credentials: async () => {
|
|
35
|
+
const tempCredentialsProvider = fromTemporaryCredentials({
|
|
36
|
+
params: {
|
|
37
|
+
RoleArn: `arn:aws:iam::${accountId}:role/${roleNameToAssume}`,
|
|
38
|
+
RoleSessionName: 'AccountRoleSession',
|
|
39
|
+
},
|
|
40
|
+
clientConfig: { credentials: mainCredentials },
|
|
41
|
+
});
|
|
42
|
+
return await tempCredentialsProvider();
|
|
43
|
+
}
|
|
44
|
+
}));
|
|
45
|
+
const result = [
|
|
46
|
+
...(includeMainAccountExecutionContext ? [mainExecutionContext] : []),
|
|
47
|
+
...assumedExecutionContexts,
|
|
48
|
+
];
|
|
49
|
+
return result;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Execute a function with assumed AWS role credentials
|
|
53
|
+
*
|
|
54
|
+
* @param options - Configuration for role assumption
|
|
55
|
+
* @param fn - Function to execute with the assumed role credentials
|
|
56
|
+
* @returns Promise that resolves with the function result
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const result = await executeAs(
|
|
61
|
+
* { accountId: '123456789012' },
|
|
62
|
+
* async (accountId, credentials) => {
|
|
63
|
+
* const s3Client = new S3Client({ credentials });
|
|
64
|
+
* return s3Client.send(new ListBucketsCommand({}));
|
|
65
|
+
* }
|
|
66
|
+
* );
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export async function executeAs(options, fn) {
|
|
70
|
+
try {
|
|
71
|
+
const accountId = typeof options.accountId === 'function'
|
|
72
|
+
? await options.accountId()
|
|
73
|
+
: options.accountId;
|
|
74
|
+
const credentials = typeof options.credentials === 'function'
|
|
75
|
+
? await options.credentials()
|
|
76
|
+
: options.credentials;
|
|
77
|
+
return await fn(accountId, credentials);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
console.log('Error assuming role', error);
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export const executeAllAs = async (options, fn) => Promise.all(options.map((opt) => executeAs(opt, fn)));
|
|
85
|
+
//# sourceMappingURL=execute-as.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute-as.js","sourceRoot":"","sources":["../../src/aws/execute-as.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAA;AAexE,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,OAA0B,EAAiC,EAAE;IACzG,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,GAAG,WAAW,EAAE,GAAG,OAAO,CAAA;IAE9E,MAAM,uBAAuB,GAAG,wBAAwB,CAAC;QACvD,iBAAiB,EAAE,eAAe;QAClC,MAAM,EAAE;YACN,OAAO,EAAE,gBAAgB,SAAS,SAAS,QAAQ,EAAE;YACrD,eAAe,EAAE,oBAAoB;SACtC;QACD,YAAY,EAAE;YACZ,MAAM;SACP;KACF,CAAC,CAAA;IACF,OAAO,uBAAuB,CAAA;AAChC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACxC,OAA0B,EACR,EAAE;IACpB,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAA;IAE7B,MAAM,uBAAuB,GAAG,6BAA6B,C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KAAK,UAAU;YACvD,CAAC,CAAC,MAAM,OAAO,CAAC,SAAS,EAAE;YAC3B,CAAC,CAAC,OAAO,CAAC,SAAS,CAAA;QAErB,MAAM,WAAW,GAAG,OAAO,OAAO,CAAC,WAAW,KAAK,UAAU;YAC3D,CAAC,CAAC,MAAM,OAAO,CAAC,WAAW,EAAE;YAC7B,CAAC,CAAC,OAAO,CAAC,WAAW,CAAA;QAEvB,OAAO,MAAM,EAAE,CAAC,SAAS,EAAE,WAAW,CAAC,CAAA;IACzC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAA;QACzC,MAAM,KAAK,CAAA;IACb,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAC/B,OAA2B,EAC3B,EAAyE,EAC3D,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/aws/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/aws/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections-summary.d.ts","sourceRoot":"","sources":["../../src/collections/collections-summary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,eAAO,MAAM,iBAAiB,GAAI,aAAa,KAAK,CAAC,UAAU,CAAC,SAK/D,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const collectionSummary = (collections) => {
|
|
2
|
+
collections.forEach(collection => {
|
|
3
|
+
console.log(`${collection.schema.name} - ${collection.objects.length} objects`);
|
|
4
|
+
console.log(`${collection.schema.name} - sample object: ${JSON.stringify(collection.objects[0], null, 2)}`);
|
|
5
|
+
});
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=collections-summary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections-summary.js","sourceRoot":"","sources":["../../src/collections/collections-summary.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,WAA8B,EAAE,EAAE;IAClE,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;QAC/B,OAAO,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,MAAM,CAAC,IAAI,MAAM,UAAU,CAAC,OAAO,CAAC,MAAM,UAAU,CAAC,CAAA;QAC/E,OAAO,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,MAAM,CAAC,IAAI,qBAAqB,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAA;IAC7G,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections-to-table.d.ts","sourceRoot":"","sources":["../../src/collections/collections-to-table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAU,MAAM,YAAY,CAAA;AAE/C,eAAO,MAAM,mBAAmB,GAAI,aAAa,UAAU,EAAE;;;GAgF5D,CAAA"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export const collectionsToTables = (collections) => {
|
|
2
|
+
const isString = (value) => typeof value === 'string' || value instanceof String;
|
|
3
|
+
const convert = (column, value) => {
|
|
4
|
+
const type = column.type || 'string';
|
|
5
|
+
let result = value;
|
|
6
|
+
try {
|
|
7
|
+
// Handle JSON type specifically - serialize for PostgreSQL
|
|
8
|
+
if (type === 'json') {
|
|
9
|
+
if (value === undefined || value === null) {
|
|
10
|
+
result = null;
|
|
11
|
+
}
|
|
12
|
+
else if (isString(value)) {
|
|
13
|
+
// If it's a string, validate it's valid JSON
|
|
14
|
+
try {
|
|
15
|
+
JSON.parse(String(value));
|
|
16
|
+
result = String(value); // Keep as valid JSON string
|
|
17
|
+
}
|
|
18
|
+
catch (jsonError) {
|
|
19
|
+
console.error(`Invalid JSON string for column "${column.name}": ${value}`);
|
|
20
|
+
result = null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
// If it's an object/array, serialize to JSON string for PostgreSQL
|
|
25
|
+
try {
|
|
26
|
+
result = JSON.stringify(value);
|
|
27
|
+
}
|
|
28
|
+
catch (jsonError) {
|
|
29
|
+
console.error(`Failed to serialize value to JSON for column "${column.name}": ${value}`);
|
|
30
|
+
result = null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else if (isString(value) && type !== 'string') {
|
|
35
|
+
result = value.trim();
|
|
36
|
+
result = result === '' ? undefined : result;
|
|
37
|
+
if (['datetime', 'date'].includes(type)) {
|
|
38
|
+
result = new Date(result);
|
|
39
|
+
}
|
|
40
|
+
else if (['number', 'currency'].includes(type)) {
|
|
41
|
+
result = parseFloat(result);
|
|
42
|
+
}
|
|
43
|
+
else if ('bool' === type) {
|
|
44
|
+
result = ['true', 'yes'].includes(result);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
console.error(`Error while converting "${value}" to typed value for column "${column.name}" with type ${type}: ${error}`);
|
|
50
|
+
result = undefined;
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
};
|
|
54
|
+
const deepFind = (obj, path) => {
|
|
55
|
+
var paths = path.split('.'), current = obj, i;
|
|
56
|
+
for (i = 0; i < paths.length; ++i) {
|
|
57
|
+
if (current[paths[i]] == undefined) {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
current = current[paths[i]];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return current;
|
|
65
|
+
};
|
|
66
|
+
const objectsToTable = (objects, columns) => {
|
|
67
|
+
const rows = objects.map((element, index) => columns.map(column => {
|
|
68
|
+
const value = deepFind(element, column.path || column.name);
|
|
69
|
+
return convert(column, value);
|
|
70
|
+
}));
|
|
71
|
+
return rows;
|
|
72
|
+
};
|
|
73
|
+
const result = collections.map(collection => {
|
|
74
|
+
const { objects, schema } = collection;
|
|
75
|
+
const rows = objectsToTable(objects, schema.columns);
|
|
76
|
+
return { schema, rows };
|
|
77
|
+
});
|
|
78
|
+
return result;
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=collections-to-table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections-to-table.js","sourceRoot":"","sources":["../../src/collections/collections-to-table.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,WAAyB,EAAE,EAAE;IAE/D,MAAM,QAAQ,GAAG,CAAC,KAAU,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,YAAY,MAAM,CAAA;IAErF,MAAM,OAAO,GAAG,CAAC,MAAc,EAAE,KAAU,EAAE,EAAE;QAC7C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,QAAQ,CAAA;QACpC,IAAI,MAAM,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC;YACH,2DAA2D;YAC3D,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;gBACpB,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;oBAC1C,MAAM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,CAAC,CAAA;YAC3D,OAAO,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;QAC/B,CAAC,CAAC,CAAC,CAAA;QAEH,OAAO,IAAI,CAAA;IACb,CAAC,CAAA;IAED,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;QAC1C,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,UAAU,CAAA;QACtC,MAAM,IAAI,GAAG,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;QACpD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAA;IACzB,CAAC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/collections/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,2BAA2B,CAAA;AACzC,cAAc,YAAY,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/collections/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,2BAA2B,CAAA;AACzC,cAAc,YAAY,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type PrepareMode = 'drop' | 'deleteAll' | 'none';
|
|
2
|
+
export type ColumnType = 'id' | 'string' | 'number' | 'bool' | 'date' | 'datetime' | 'json' | 'currency' | 'text';
|
|
3
|
+
export interface Column {
|
|
4
|
+
name: string;
|
|
5
|
+
type?: ColumnType;
|
|
6
|
+
path?: string;
|
|
7
|
+
transform?: (record: any) => any;
|
|
8
|
+
}
|
|
9
|
+
export interface CollectionSchema {
|
|
10
|
+
name: string;
|
|
11
|
+
prepareMode: PrepareMode;
|
|
12
|
+
columns: Array<Column>;
|
|
13
|
+
}
|
|
14
|
+
export type CollectionObjects = Array<any>;
|
|
15
|
+
export interface Collection {
|
|
16
|
+
schema: CollectionSchema;
|
|
17
|
+
objects: Array<any>;
|
|
18
|
+
}
|
|
19
|
+
export interface TableRows {
|
|
20
|
+
schema: CollectionSchema;
|
|
21
|
+
rows: Array<Array<any>>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/collections/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;AACxD,MAAM,MAAM,UAAU,GAAG,IAAI,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,CAAC;AAElH,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;CAClC;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,WAAW,CAAA;IACxB,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACxB;AAED,MAAM,MAAM,iBAAiB,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;AAE3C,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,gBAAgB,CAAC;IACzB,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;CACrB;AAED,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,gBAAgB,CAAC;IACzB,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;CACzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/collections/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-range.d.ts","sourceRoot":"","sources":["../../src/date/date-range.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,eAAO,MAAM,WAAW,GAAI,WAAW,GAAG,EAAE,SAAS,GAAG,KAAG,SAQ1D,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,QAAQ,MAAM,KAAG,SAK1C,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
export const asDateRange = (startDate, endDate) => {
|
|
3
|
+
if (!startDate || !endDate) {
|
|
4
|
+
throw new Error('Both startDate and endDate must be provided');
|
|
5
|
+
}
|
|
6
|
+
return {
|
|
7
|
+
startDate: dayjs(startDate).format('YYYY-MM-DD'),
|
|
8
|
+
endDate: dayjs(endDate).format('YYYY-MM-DD')
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export const monthsAgo = (months) => {
|
|
12
|
+
const startDate = dayjs().subtract(months, 'months').startOf('month');
|
|
13
|
+
const endDate = dayjs();
|
|
14
|
+
return asDateRange(startDate, endDate);
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=date-range.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-range.js","sourceRoot":"","sources":["../../src/date/date-range.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAOzB,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,SAAc,EAAE,OAAY,EAAa,EAAE;IACrE,IAAI,CAAC,SAAS,IAAI,CAAC,OAAO,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;IAChE,CAAC;IACD,OAAO;QACL,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;QAChD,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;KAC7C,CAAC;AACJ,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,MAAc,EAAa,EAAE;IACrD,MAAM,SAAS,GAAG,KAAK,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACtE,MAAM,OAAO,GAAG,KAAK,EAAE,CAAA;IAEvB,OAAO,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/date/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/date/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const packageName = "@ingeno/pipedream-services";
|
|
2
|
+
export * from './aws/index.js';
|
|
3
|
+
export * from './date/index.js';
|
|
4
|
+
export * from './collections/index.js';
|
|
5
|
+
export * from './postgres/index.js';
|
|
6
|
+
export * from './zoho-crm/index.js';
|
|
7
|
+
export * from './temporary-files.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,+BAA+B,CAAA;AAEvD,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA;AACtC,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const packageName = '@ingeno/pipedream-services';
|
|
2
|
+
export * from './aws/index.js';
|
|
3
|
+
export * from './date/index.js';
|
|
4
|
+
export * from './collections/index.js';
|
|
5
|
+
export * from './postgres/index.js';
|
|
6
|
+
export * from './zoho-crm/index.js';
|
|
7
|
+
export * from './temporary-files.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,4BAA4B,CAAA;AAEvD,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA;AACtC,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/postgres/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/postgres/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TableRows } from '../collections/types.js';
|
|
2
|
+
export interface PostgresAuth {
|
|
3
|
+
host: string;
|
|
4
|
+
user: string;
|
|
5
|
+
password: string;
|
|
6
|
+
port: number;
|
|
7
|
+
database: string;
|
|
8
|
+
}
|
|
9
|
+
export interface FillTableOptions {
|
|
10
|
+
auth: PostgresAuth;
|
|
11
|
+
tablesRows: TableRows[];
|
|
12
|
+
tablesPrefix: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const fillTables: (options: FillTableOptions) => Promise<void>;
|
|
15
|
+
//# sourceMappingURL=postgres.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../src/postgres/postgres.ts"],"names":[],"mappings":"AAIA,OAAO,EAAc,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAI/D,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,YAAY,CAAC;IACnB,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,UAAU,GAAU,SAAS,gBAAgB,kBAiHzD,CAAA"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import pg from 'pg';
|
|
3
|
+
const { Client } = pg;
|
|
4
|
+
export const fillTables = async (options) => {
|
|
5
|
+
const { auth, tablesRows, tablesPrefix } = options;
|
|
6
|
+
const client = new Client(auth);
|
|
7
|
+
const sqlTableName = ({ name }) => `${tablesPrefix}${name.toLowerCase()}`;
|
|
8
|
+
const sqlColumnName = (column) => column.name.toLowerCase().replace(/[^A-Za-z0-9]+/g, '_');
|
|
9
|
+
const sqlTypeName = (column) => {
|
|
10
|
+
const sqlTypes = {
|
|
11
|
+
id: 'NUMERIC(20,0)',
|
|
12
|
+
string: 'TEXT',
|
|
13
|
+
number: 'NUMERIC(25,5)',
|
|
14
|
+
currency: 'NUMERIC(22, 2)',
|
|
15
|
+
date: 'date',
|
|
16
|
+
datetime: 'timestamp',
|
|
17
|
+
bool: 'boolean',
|
|
18
|
+
json: 'jsonb',
|
|
19
|
+
};
|
|
20
|
+
return sqlTypes[column.type || 'string'] || 'TEXT';
|
|
21
|
+
};
|
|
22
|
+
const runQuery = async (query, values) => {
|
|
23
|
+
try {
|
|
24
|
+
await client.query(query, values);
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
console.error(err);
|
|
28
|
+
console.log(`query in error: ${query}`);
|
|
29
|
+
if (values) {
|
|
30
|
+
console.log(`values in error: ${values}`);
|
|
31
|
+
}
|
|
32
|
+
throw err;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const possiblyCreateTableQuery = ({ name, columns }) => {
|
|
36
|
+
let query = `create table if not exists ${sqlTableName({ name })} (\n`;
|
|
37
|
+
const fields = columns.map((column) => {
|
|
38
|
+
let sqlType = sqlTypeName(column);
|
|
39
|
+
if (column.name === 'id') {
|
|
40
|
+
sqlType += ' UNIQUE';
|
|
41
|
+
}
|
|
42
|
+
return ` "${sqlColumnName(column)}" ${sqlType}`;
|
|
43
|
+
});
|
|
44
|
+
query += fields.join(',\n');
|
|
45
|
+
query += `\n);\n`;
|
|
46
|
+
return query;
|
|
47
|
+
};
|
|
48
|
+
const prepareTable = async ({ name, prepareMode = 'deleteAll', columns }) => {
|
|
49
|
+
const tableName = sqlTableName({ name });
|
|
50
|
+
const createTableIfNotExists = possiblyCreateTableQuery({ name, columns });
|
|
51
|
+
const statementsFnForPrepareMode = {
|
|
52
|
+
drop: () => [`drop table if exists ${tableName}`, createTableIfNotExists],
|
|
53
|
+
deleteAll: () => [createTableIfNotExists, `delete from ${tableName}`],
|
|
54
|
+
none: () => [createTableIfNotExists],
|
|
55
|
+
};
|
|
56
|
+
const deleteWhere = () => [createTableIfNotExists, `delete from ${tableName} where ${prepareMode}`];
|
|
57
|
+
const statements = (statementsFnForPrepareMode[prepareMode] || deleteWhere)();
|
|
58
|
+
console.log(statements.join(', '));
|
|
59
|
+
return await Promise.all(statements.map((statement) => {
|
|
60
|
+
console.log(`prepare query: ${statement}`);
|
|
61
|
+
return runQuery(statement);
|
|
62
|
+
}));
|
|
63
|
+
};
|
|
64
|
+
const insertTableData = async ({ schema, rows }) => {
|
|
65
|
+
const columnsNames = `${schema.columns.map((column) => `"${sqlColumnName(column)}"`).join(', ')}`;
|
|
66
|
+
const tableName = sqlTableName(schema);
|
|
67
|
+
console.log(`Inserting ${rows.length} rows in table '${tableName}'`);
|
|
68
|
+
const params = `${schema.columns.map((_, index) => `$${index + 1}`).join(', ')}`;
|
|
69
|
+
const query = `INSERT INTO ${tableName} (${columnsNames})\n VALUES (${params})\n ON CONFLICT (ID) DO UPDATE SET (${columnsNames}) = (${params});`;
|
|
70
|
+
console.log(`insert query: ${query}`);
|
|
71
|
+
const result = await Promise.all(rows.map((row) => runQuery(query, row)));
|
|
72
|
+
console.log(`Done ${rows.length} rows in table '${tableName}'`);
|
|
73
|
+
return result;
|
|
74
|
+
};
|
|
75
|
+
const fillTables = () => Promise.all(tablesRows.map(async ({ schema, rows }) => {
|
|
76
|
+
console.log(`Filling table ${schema.name}`);
|
|
77
|
+
await prepareTable(schema);
|
|
78
|
+
await insertTableData({ schema, rows });
|
|
79
|
+
console.log(`Completed table ${schema.name}`);
|
|
80
|
+
}));
|
|
81
|
+
tablesRows.forEach(table => {
|
|
82
|
+
console.log(`${table?.schema?.name} : ${table?.rows?.length} objects`);
|
|
83
|
+
});
|
|
84
|
+
await client.connect();
|
|
85
|
+
try {
|
|
86
|
+
await fillTables();
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
await client.end();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
//# sourceMappingURL=postgres.js.map
|