@trayio/cdk-build 4.12.0 → 4.14.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"ConnectorBuilder.d.ts","sourceRoot":"","sources":["../../src/connector/ConnectorBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AASvC,qBAAa,gBAAgB;IAC5B,OAAO,CAAC,wBAAwB,CAA2C;IAE3E,cAAc,CAAC,cAAc,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;IAOvE,eAAe,CAAC,cAAc,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;IAcxE,aAAa,CAAC,cAAc,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAYpD,OAAO,CAAC,eAAe;IAgEvB,OAAO,CAAC,sBAAsB;IAuC9B,OAAO,CAAC,kCAAkC;IAkB1C,OAAO,CAAC,gBAAgB;CAcxB"}
1
+ {"version":3,"file":"ConnectorBuilder.d.ts","sourceRoot":"","sources":["../../src/connector/ConnectorBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAYvC,qBAAa,gBAAgB;IAC5B,OAAO,CAAC,wBAAwB,CAA2C;IAE3E,cAAc,CAAC,cAAc,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;IAOvE,eAAe,CAAC,cAAc,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;IAcxE,aAAa,CAAC,cAAc,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAYpD,OAAO,CAAC,eAAe;IA6EvB,OAAO,CAAC,sBAAsB;IAuC9B,OAAO,CAAC,kCAAkC;IAkB1C,OAAO,CAAC,gBAAgB;CAcxB"}
@@ -32,9 +32,12 @@ const function_1 = require("fp-ts/function");
32
32
  const Array_1 = require("fp-ts/Array");
33
33
  const pathLib = __importStar(require("path"));
34
34
  const fse = __importStar(require("fs-extra"));
35
+ const E = __importStar(require("fp-ts/Either"));
35
36
  const adm_zip_1 = __importDefault(require("adm-zip"));
36
37
  const lodash_1 = require("lodash");
38
+ const ZodSchemaParser_1 = require("@trayio/commons/zod/ZodSchemaParser");
37
39
  const ConnectorOperationSchemaGenerator_1 = require("./operation/ConnectorOperationSchemaGenerator");
40
+ const ConnectorJson_1 = require("./schemas/ConnectorJson");
38
41
  class ConnectorBuilder {
39
42
  operationSchemaGenerator = new ConnectorOperationSchemaGenerator_1.ConnectorOperationSchemaGenerator();
40
43
  buildConnector(cdkProjectPath) {
@@ -57,31 +60,34 @@ class ConnectorBuilder {
57
60
  }
58
61
  // TODO: better error handling
59
62
  generatePackage(cdkProjectPath) {
63
+ const connectorJsonParser = ZodSchemaParser_1.ZodSchemaParser.fromSchema(ConnectorJson_1.ConnectorJsonSchema);
60
64
  const connectorPackagePath = pathLib.join(cdkProjectPath, 'dist', 'connector.zip');
61
65
  const connectorJsonPath = pathLib.join(cdkProjectPath, 'connector.json');
62
66
  const connectorJson = fse.readJsonSync(connectorJsonPath);
63
- // add rawHttpConfig to connectorJson if it's missing
64
67
  const connectorJsonWithRawHttpConfig = this.addRawHttpConfig(connectorJson);
65
68
  fse.writeJsonSync(connectorJsonPath, connectorJsonWithRawHttpConfig);
66
- const connectorPackage = new adm_zip_1.default();
67
- connectorPackage.addLocalFolder(pathLib.join(cdkProjectPath, 'src'), pathLib.join(connectorJson.name, 'src'));
68
- if (connectorJsonWithRawHttpConfig.rawHttp.enabled &&
69
- !connectorJsonWithRawHttpConfig.isTrigger) {
70
- this.injectRawHttpOperation(connectorPackage, connectorJson.name, cdkProjectPath);
71
- }
72
- const entries = connectorPackage.getEntries();
73
- // exclude all the ctx.json files from the zip as it can contain sensitive information
74
- for (const entry of entries) {
75
- if (entry.entryName.endsWith('.ctx.json')) {
76
- connectorPackage.deleteFile(entry.entryName);
69
+ const connectorJsonResult = connectorJsonParser.parse(connectorJsonWithRawHttpConfig);
70
+ return (0, function_1.pipe)(connectorJsonResult, E.fold((error) => TE.left(error), (connectorJsonParsed) => {
71
+ const connectorPackage = new adm_zip_1.default();
72
+ connectorPackage.addLocalFolder(pathLib.join(cdkProjectPath, 'src'), pathLib.join(connectorJsonParsed.name, 'src'));
73
+ if (connectorJsonParsed.rawHttp.enabled &&
74
+ !connectorJsonParsed.isTrigger) {
75
+ this.injectRawHttpOperation(connectorPackage, connectorJsonParsed.name, cdkProjectPath);
77
76
  }
78
- }
79
- connectorPackage.addLocalFile(pathLib.join(cdkProjectPath, 'package.json'), connectorJson.name);
80
- connectorPackage.addLocalFile(pathLib.join(cdkProjectPath, 'tsconfig.json'), connectorJson.name);
81
- connectorPackage.addLocalFile(pathLib.join(cdkProjectPath, 'jest.config.js'), connectorJson.name);
82
- connectorPackage.addLocalFile(pathLib.join(cdkProjectPath, 'connector.json'), connectorJson.name);
83
- connectorPackage.writeZip(connectorPackagePath);
84
- return TE.right(undefined);
77
+ const entries = connectorPackage.getEntries();
78
+ // exclude all the ctx.json files from the zip as it can contain sensitive information
79
+ for (const entry of entries) {
80
+ if (entry.entryName.endsWith('.ctx.json')) {
81
+ connectorPackage.deleteFile(entry.entryName);
82
+ }
83
+ }
84
+ connectorPackage.addLocalFile(pathLib.join(cdkProjectPath, 'package.json'), connectorJsonParsed.name);
85
+ connectorPackage.addLocalFile(pathLib.join(cdkProjectPath, 'tsconfig.json'), connectorJsonParsed.name);
86
+ connectorPackage.addLocalFile(pathLib.join(cdkProjectPath, 'jest.config.js'), connectorJsonParsed.name);
87
+ connectorPackage.addLocalFile(pathLib.join(cdkProjectPath, 'connector.json'), connectorJsonParsed.name);
88
+ connectorPackage.writeZip(connectorPackagePath);
89
+ return TE.right(undefined);
90
+ }));
85
91
  }
86
92
  injectRawHttpOperation(connectorPackage, connectorName, cdkProjectPath) {
87
93
  const executionDir = __dirname;
@@ -0,0 +1,56 @@
1
+ import { z } from 'zod';
2
+ export declare const ConnectorJsonSchema: z.ZodObject<{
3
+ name: z.ZodString;
4
+ version: z.ZodString;
5
+ title: z.ZodString;
6
+ description: z.ZodString;
7
+ service: z.ZodObject<{
8
+ name: z.ZodString;
9
+ version: z.ZodString;
10
+ }, "strip", z.ZodTypeAny, {
11
+ name: string;
12
+ version: string;
13
+ }, {
14
+ name: string;
15
+ version: string;
16
+ }>;
17
+ tags: z.ZodArray<z.ZodString, "many">;
18
+ isTrigger: z.ZodBoolean;
19
+ rawHttp: z.ZodObject<{
20
+ enabled: z.ZodBoolean;
21
+ }, "strip", z.ZodTypeAny, {
22
+ enabled: boolean;
23
+ }, {
24
+ enabled: boolean;
25
+ }>;
26
+ }, "strip", z.ZodTypeAny, {
27
+ name: string;
28
+ version: string;
29
+ title: string;
30
+ description: string;
31
+ service: {
32
+ name: string;
33
+ version: string;
34
+ };
35
+ tags: string[];
36
+ isTrigger: boolean;
37
+ rawHttp: {
38
+ enabled: boolean;
39
+ };
40
+ }, {
41
+ name: string;
42
+ version: string;
43
+ title: string;
44
+ description: string;
45
+ service: {
46
+ name: string;
47
+ version: string;
48
+ };
49
+ tags: string[];
50
+ isTrigger: boolean;
51
+ rawHttp: {
52
+ enabled: boolean;
53
+ };
54
+ }>;
55
+ export type ConnectorJson = z.infer<typeof ConnectorJsonSchema>;
56
+ //# sourceMappingURL=ConnectorJson.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConnectorJson.d.ts","sourceRoot":"","sources":["../../../src/connector/schemas/ConnectorJson.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAW9B,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConnectorJsonSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.ConnectorJsonSchema = zod_1.z.object({
6
+ name: zod_1.z.string(),
7
+ version: zod_1.z.string(),
8
+ title: zod_1.z.string(),
9
+ description: zod_1.z.string(),
10
+ service: zod_1.z.object({ name: zod_1.z.string(), version: zod_1.z.string() }),
11
+ tags: zod_1.z.array(zod_1.z.string()),
12
+ isTrigger: zod_1.z.boolean(),
13
+ rawHttp: zod_1.z.object({
14
+ enabled: zod_1.z.boolean(),
15
+ }),
16
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../../src/connector/test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const E = __importStar(require("fp-ts/lib/Either"));
30
+ const chalk_1 = __importDefault(require("chalk"));
31
+ const ConnectorBuilder_1 = require("./ConnectorBuilder");
32
+ const connectorBuilder = new ConnectorBuilder_1.ConnectorBuilder();
33
+ const result = connectorBuilder.buildConnector('/Users/gnyani/projects/CDK-examples-public/name-change-test');
34
+ (async () => {
35
+ E.getOrElse((error) => {
36
+ console.log(chalk_1.default.bold(chalk_1.default.bgRed(error.message)));
37
+ })(await result());
38
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trayio/cdk-build",
3
- "version": "4.12.0",
3
+ "version": "4.14.0",
4
4
  "description": "Build utilities for CDK projects",
5
5
  "exports": {
6
6
  "./*": "./dist/*.js"
@@ -14,9 +14,10 @@
14
14
  "access": "public"
15
15
  },
16
16
  "dependencies": {
17
- "@trayio/commons": "4.12.0",
18
- "@trayio/tray-schema": "4.12.0",
19
- "adm-zip": "0.5.10"
17
+ "@trayio/commons": "4.14.0",
18
+ "@trayio/tray-schema": "4.14.0",
19
+ "adm-zip": "0.5.10",
20
+ "zod": "3.23.5"
20
21
  },
21
22
  "typesVersions": {
22
23
  "*": {