@twotaps/site-utils-base 0.1.18 → 0.1.20

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,10 +1,35 @@
1
1
  import type { CommandModule } from 'yargs';
2
- export declare class GenerateSDL implements CommandModule {
2
+ interface GenerateSDLArgs {
3
+ schemaWrapperId?: string;
4
+ orgName?: string;
5
+ schemaWrapperName?: string;
6
+ SchemaBuilderURI: string;
7
+ }
8
+ export declare class GenerateSDL implements CommandModule<object, GenerateSDLArgs> {
3
9
  command: string;
4
10
  describe: string;
5
- /**
6
- * @inheritDoc
7
- */
11
+ builder: {
12
+ schemaWrapperId: {
13
+ type: "string";
14
+ demandOption: boolean;
15
+ describe: string;
16
+ };
17
+ orgName: {
18
+ type: "string";
19
+ demandOption: boolean;
20
+ describe: string;
21
+ };
22
+ schemaWrapperName: {
23
+ type: "string";
24
+ demandOption: boolean;
25
+ describe: string;
26
+ };
27
+ twoTapsHost: {
28
+ type: "string";
29
+ demandOption: boolean;
30
+ describe: string;
31
+ };
32
+ };
8
33
  handler(args: {
9
34
  [argName: string]: unknown;
10
35
  _: (string | number)[];
@@ -1,28 +1,78 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- import axios from 'axios';
3
1
  import * as fs from 'fs';
4
- import * as path from 'path';
5
- import yaml from 'yml';
6
2
  export class GenerateSDL {
7
3
  constructor() {
8
4
  this.command = 'generate:sdl';
9
- this.describe = 'Get schema from API';
5
+ this.describe = 'TwoTaps: Generate typescript schema for the given schema-wrapper. \n' +
6
+ 'usage: twotaps generate:sdl --twoTapsHost https://api-lb-prod.twotaps.io --schemaWrapperId <id>\n' +
7
+ 'OR: twotaps generate:sdl --twoTapsHost https://api-lb-prod.twotaps.io --orgName <name> --schemaWrapperName <name>';
8
+ this.builder = {
9
+ schemaWrapperId: {
10
+ type: 'string',
11
+ demandOption: false,
12
+ describe: 'TT Schema Wrapper ID',
13
+ },
14
+ orgName: {
15
+ type: 'string',
16
+ demandOption: false,
17
+ describe: 'Organization Name',
18
+ },
19
+ schemaWrapperName: {
20
+ type: 'string',
21
+ demandOption: false,
22
+ describe: 'Schema Wrapper Name',
23
+ },
24
+ twoTapsHost: {
25
+ type: 'string',
26
+ demandOption: true,
27
+ describe: 'Schema Builder URI',
28
+ },
29
+ };
10
30
  }
11
- /**
12
- * @inheritDoc
13
- */
14
- // eslint-disable-next-line class-methods-use-this
15
31
  async handler(args) {
16
32
  try {
17
- const configPath = path.resolve(process.cwd(), 'config.yml');
18
- const configContent = fs.readFileSync(configPath, {
19
- encoding: 'utf-8',
33
+ const ttSchemaWrapperId = args.schemaWrapperId;
34
+ const orgName = args.orgName;
35
+ const schemaWrapperName = args.schemaWrapperName;
36
+ const twoTapsHost = args.twoTapsHost;
37
+ const apiToken = process.env.TWO_TAPS_API_TOKEN;
38
+ if (!apiToken) {
39
+ throw new Error('TWO_TAPS_API_TOKEN environment variable is not set');
40
+ }
41
+ // Validate that either ttSchemaWrapperId OR both orgName and schemaWrapperName are provided
42
+ const hasSchemaWrapperId = typeof ttSchemaWrapperId === 'string';
43
+ const hasOrgAndWrapper = typeof orgName === 'string' && typeof schemaWrapperName === 'string';
44
+ if (!hasSchemaWrapperId && !hasOrgAndWrapper) {
45
+ throw new Error('Either ttSchemaWrapperId OR both orgName and schemaWrapperName must be provided');
46
+ }
47
+ if (hasSchemaWrapperId && hasOrgAndWrapper) {
48
+ throw new Error('Provide either ttSchemaWrapperId OR orgName/schemaWrapperName, not both');
49
+ }
50
+ if (typeof twoTapsHost !== 'string') {
51
+ throw new Error('Invalid twoTapsHost argument');
52
+ }
53
+ // Build query parameters based on what was provided
54
+ let queryParams;
55
+ if (hasSchemaWrapperId) {
56
+ queryParams = `ttschemaWrapperId=${ttSchemaWrapperId}`;
57
+ }
58
+ else {
59
+ queryParams = `orgName=${orgName}&schemaWrapperName=${schemaWrapperName}`;
60
+ }
61
+ const response = await fetch(`${twoTapsHost}/product-api/schema-builder?${queryParams}`, {
62
+ method: 'GET',
63
+ headers: {
64
+ Authorization: `Bearer ${apiToken}`,
65
+ },
20
66
  });
21
- const config = yaml.parse(configContent);
22
- const response = await axios.get(config.SchemaBuilderURI);
23
- fs.writeFile('schema.gql', response.data, (err) => {
24
- if (err)
67
+ if (!response.ok) {
68
+ throw new Error(`Failed to fetch schema: ${response.status} ${response.statusText}`);
69
+ }
70
+ const data = await response.text();
71
+ fs.writeFile('schema.ts', data, (err) => {
72
+ if (err) {
25
73
  throw err;
74
+ }
75
+ console.info('Successfully wrote schema to schema.ts in the current directory');
26
76
  });
27
77
  }
28
78
  catch (err) {
@@ -1 +1 @@
1
- {"version":3,"file":"generate-sdl.js","sourceRoot":"","sources":["../../src/cli/generate-sdl.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,IAAI,MAAM,KAAK,CAAC;AAQvB,MAAM,OAAO,WAAW;IAAxB;QACE,YAAO,GAAG,cAAc,CAAC;QAEzB,aAAQ,GAAG,qBAAqB,CAAC;IAsBnC,CAAC;IApBC;;OAEG;IACH,kDAAkD;IAClD,KAAK,CAAC,OAAO,CAAC,IAAwE;QACpF,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,YAAY,CAAC,CAAC;YAC7D,MAAM,aAAa,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE;gBAChD,QAAQ,EAAE,OAAO;aAClB,CAAC,CAAC;YACH,MAAM,MAAM,GAAiB,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;YACvD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;YAC1D,EAAE,CAAC,SAAS,CAAC,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IAAI,KAAK,CAAC,2BAA2B,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;YACvF,CAAC;YAED,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnC,EAAE,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE;gBACtC,IAAI,GAAG,EAAE,CAAC;oBACR,MAAM,GAAG,CAAC;gBACZ,CAAC;gBACD,OAAO,CAAC,IAAI,CAAC,iEAAiE,CAAC,CAAC;YAClF,CAAC,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAG,GAAa,CAAC,OAAO,CAAC,CAAC;YACrE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,yDAAyD;QAC5E,CAAC;IACH,CAAC;CACF;AAED,eAAe,WAAW,CAAC"}
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env node
2
+ import yargs from 'yargs';
3
+ import { GenerateSDL } from './generate-sdl.js';
4
+ import { hideBin } from 'yargs/helpers';
5
+ const cli = yargs(hideBin(process.argv))
6
+ .scriptName('twotaps')
7
+ .usage('usage: twotaps generate:sdl --twoTapsHost https://api-lb-prod.twotaps.io --schemaWrapperId <id>\n' +
8
+ 'OR: twotaps generate:sdl --twoTapsHost https://api-lb-prod.twotaps.io --orgName <name> --schemaWrapperName <name>')
9
+ .command(new GenerateSDL())
10
+ .demandCommand(1, 'You need to specify a command. ex: generate:sdl')
11
+ .strict()
12
+ .help()
13
+ .alias('help', 'h');
14
+ cli.parse();
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;KACrC,UAAU,CAAC,SAAS,CAAC;KACrB,KAAK,CACJ,mGAAmG;IACjG,mHAAmH,CACtH;KACA,OAAO,CAAC,IAAI,WAAW,EAAE,CAAC;KAC1B,aAAa,CAAC,CAAC,EAAE,iDAAiD,CAAC;KACnE,MAAM,EAAE;KACR,IAAI,EAAE;KACN,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEtB,GAAG,CAAC,KAAK,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twotaps/site-utils-base",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "description": "This package provides a base for the other Two Taps framework specific packages",
5
5
  "type": "module",
6
6
  "files": [
@@ -12,7 +12,9 @@
12
12
  },
13
13
  "author": "LT Network <support@ltnetwork.com.au>",
14
14
  "license": "MIT",
15
- "bin": "./dist/cli/cli.js",
15
+ "bin": {
16
+ "twotaps": "./dist/cli/index.js"
17
+ },
16
18
  "scripts": {
17
19
  "pre:build": "yarn generate-schema",
18
20
  "prepack": "yarn clean && yarn build",
@@ -24,13 +26,14 @@
24
26
  "check-types": "tsc --noEmit --incremental --pretty false"
25
27
  },
26
28
  "dependencies": {
27
- "@twotaps/template-editor-bridge": "^0.0.12",
29
+ "@twotaps/template-editor-bridge": "^0.0.13",
28
30
  "@urql/core": "^4.0.10",
29
31
  "@urql/exchange-persisted": "^4.0.0",
30
32
  "@urql/exchange-retry": "^1.2.0",
31
33
  "axios": "^0.24.0",
32
34
  "graphql": "^16.6.0",
33
- "typescript": "^5.7.2",
35
+ "typescript": "^5.9.2",
36
+ "yargs": "^18.0.0",
34
37
  "yml": "^1.0.0"
35
38
  },
36
39
  "devDependencies": {
@@ -44,7 +47,6 @@
44
47
  "@types/node": "^20.3.1",
45
48
  "axios": "^0.24.0",
46
49
  "chalk": "^5.0.0",
47
- "eslint": "^9.8.0",
48
50
  "prettier": "^2.8.8",
49
51
  "ts-node": "^10.9.2",
50
52
  "tslib": "^2.3.1"