@nlabs/lex 1.48.6 → 1.49.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.
Files changed (107) hide show
  1. package/.storybook/main.ts +9 -2
  2. package/.vscode/settings.json +1 -6
  3. package/README.md +276 -4
  4. package/eslint.config.mjs +24 -0
  5. package/examples/lex.config.js +18 -8
  6. package/examples/serverless-example/README.md +109 -0
  7. package/examples/serverless-example/dist/handlers/echo.js +15 -0
  8. package/examples/serverless-example/dist/handlers/graphql.js +137 -0
  9. package/examples/serverless-example/dist/handlers/hello.js +15 -0
  10. package/examples/serverless-example/dist/handlers/test.js +17 -0
  11. package/examples/serverless-example/dist/handlers/websocket.js +14 -0
  12. package/examples/serverless-example/lex.config.mjs +74 -0
  13. package/jest.config.mjs +13 -12
  14. package/{dist → lib}/LexConfig.d.ts +14 -6
  15. package/lib/LexConfig.js +268 -0
  16. package/lib/commands/ai/ai.js +303 -0
  17. package/{dist → lib}/commands/build/build.d.ts +3 -0
  18. package/lib/commands/build/build.js +494 -0
  19. package/{dist → lib}/commands/clean/clean.js +1 -1
  20. package/lib/commands/compile/compile.js +241 -0
  21. package/lib/commands/copy/copy.js +38 -0
  22. package/{dist → lib}/commands/create/create.js +1 -1
  23. package/{dist → lib}/commands/dev/dev.d.ts +2 -0
  24. package/lib/commands/dev/dev.js +286 -0
  25. package/{dist → lib}/commands/init/init.js +1 -1
  26. package/{dist → lib}/commands/lint/lint.d.ts +4 -1
  27. package/lib/commands/lint/lint.js +993 -0
  28. package/{dist → lib}/commands/migrate/migrate.js +1 -1
  29. package/lib/commands/publish/publish.js +104 -0
  30. package/lib/commands/serverless/serverless.d.ts +17 -0
  31. package/lib/commands/serverless/serverless.js +662 -0
  32. package/lib/commands/storybook/storybook.js +249 -0
  33. package/lib/commands/test/test.js +428 -0
  34. package/lib/commands/update/update.js +128 -0
  35. package/lib/commands/versions/versions.js +41 -0
  36. package/{dist → lib}/create/changelog.js +1 -1
  37. package/{dist → lib}/index.d.ts +2 -0
  38. package/{dist → lib}/index.js +3 -1
  39. package/lib/lex.js +73 -0
  40. package/lib/storybook/index.d.ts +5 -0
  41. package/lib/types.js +1 -0
  42. package/lib/utils/aiService.d.ts +9 -0
  43. package/lib/utils/aiService.js +299 -0
  44. package/{dist → lib}/utils/app.d.ts +3 -0
  45. package/lib/utils/app.js +296 -0
  46. package/lib/utils/deepMerge.js +26 -0
  47. package/{dist → lib}/utils/file.d.ts +7 -3
  48. package/lib/utils/file.js +229 -0
  49. package/lib/utils/translations.d.ts +1 -0
  50. package/lib/utils/translations.js +74 -0
  51. package/package.json +62 -50
  52. package/postcss.config.js +5 -3
  53. package/tsconfig.build.json +2 -2
  54. package/webpack.config.js +229 -39
  55. package/dist/LexConfig.js +0 -286
  56. package/dist/commands/ai/ai.js +0 -303
  57. package/dist/commands/build/build.js +0 -404
  58. package/dist/commands/compile/compile.js +0 -234
  59. package/dist/commands/copy/copy.js +0 -38
  60. package/dist/commands/dev/dev.js +0 -74
  61. package/dist/commands/lint/lint.js +0 -811
  62. package/dist/commands/publish/publish.js +0 -104
  63. package/dist/commands/storybook/storybook.js +0 -249
  64. package/dist/commands/test/test.js +0 -429
  65. package/dist/commands/update/update.js +0 -132
  66. package/dist/commands/versions/versions.js +0 -41
  67. package/dist/lex.js +0 -70
  68. package/dist/utils/aiService.d.ts +0 -9
  69. package/dist/utils/aiService.js +0 -299
  70. package/dist/utils/app.js +0 -267
  71. package/dist/utils/deepMerge.js +0 -24
  72. package/dist/utils/file.js +0 -185
  73. package/emptyModule.js +0 -0
  74. package/eslint.config.js +0 -7
  75. /package/{dist → lib}/Button.stories.d.ts +0 -0
  76. /package/{dist → lib}/commands/ai/ai.d.ts +0 -0
  77. /package/{dist → lib}/commands/ai/index.d.ts +0 -0
  78. /package/{dist → lib}/commands/ai/index.js +0 -0
  79. /package/{dist → lib}/commands/clean/clean.d.ts +0 -0
  80. /package/{dist → lib}/commands/compile/compile.d.ts +0 -0
  81. /package/{dist → lib}/commands/config/config.d.ts +0 -0
  82. /package/{dist → lib}/commands/config/config.js +0 -0
  83. /package/{dist → lib}/commands/copy/copy.d.ts +0 -0
  84. /package/{dist → lib}/commands/create/create.d.ts +0 -0
  85. /package/{dist → lib}/commands/init/init.d.ts +0 -0
  86. /package/{dist → lib}/commands/link/link.d.ts +0 -0
  87. /package/{dist → lib}/commands/link/link.js +0 -0
  88. /package/{dist → lib}/commands/lint/autofix.d.ts +0 -0
  89. /package/{dist → lib}/commands/migrate/migrate.d.ts +0 -0
  90. /package/{dist → lib}/commands/publish/publish.d.ts +0 -0
  91. /package/{dist → lib}/commands/storybook/storybook.d.ts +0 -0
  92. /package/{dist → lib}/commands/test/test.d.ts +0 -0
  93. /package/{dist → lib}/commands/update/update.d.ts +0 -0
  94. /package/{dist → lib}/commands/upgrade/upgrade.d.ts +0 -0
  95. /package/{dist → lib}/commands/upgrade/upgrade.js +0 -0
  96. /package/{dist → lib}/commands/versions/versions.d.ts +0 -0
  97. /package/{dist → lib}/create/changelog.d.ts +0 -0
  98. /package/{dist → lib}/lex.d.ts +0 -0
  99. /package/{dist/types.js → lib/storybook/index.js} +0 -0
  100. /package/{dist → lib}/test-react/index.d.ts +0 -0
  101. /package/{dist → lib}/test-react/index.js +0 -0
  102. /package/{dist → lib}/types.d.ts +0 -0
  103. /package/{dist → lib}/utils/deepMerge.d.ts +0 -0
  104. /package/{dist → lib}/utils/log.d.ts +0 -0
  105. /package/{dist → lib}/utils/log.js +0 -0
  106. /package/{dist → lib}/utils/reactShim.d.ts +0 -0
  107. /package/{dist → lib}/utils/reactShim.js +0 -0
@@ -0,0 +1,137 @@
1
+ export const handler = async (event, context) => {
2
+ console.log('GraphQL handler started');
3
+ console.log('Event:', JSON.stringify(event, null, 2));
4
+
5
+ // Simulate GraphQL resolver logic
6
+ const resolvers = {
7
+ Query: {
8
+ hello: () => {
9
+ console.log('Resolver: hello called');
10
+ return 'Hello from GraphQL!';
11
+ },
12
+ users: () => {
13
+ console.log('Resolver: users called');
14
+ return [
15
+ { id: 1, name: 'John Doe', email: 'john@example.com' },
16
+ { id: 2, name: 'Jane Smith', email: 'jane@example.com' }
17
+ ];
18
+ }
19
+ },
20
+ Mutation: {
21
+ signUp: (_, args) => {
22
+ const user = args.user;
23
+ console.log('Resolver: signUp called with user:', user);
24
+ console.log('Processing signup for:', user.email);
25
+
26
+ // Simulate some processing
27
+ const userId = Math.floor(Math.random() * 1000);
28
+ console.log('Generated user ID:', userId);
29
+
30
+ return {
31
+ userId,
32
+ username: user.username,
33
+ email: user.email
34
+ };
35
+ }
36
+ }
37
+ };
38
+
39
+ try {
40
+ // Parse the GraphQL request
41
+ const body = JSON.parse(event.body);
42
+ console.log('GraphQL Query:', body.query);
43
+ console.log('GraphQL Variables:', body.variables);
44
+
45
+ // Simulate GraphQL execution
46
+ if (body.query.includes('signUp')) {
47
+ console.log('Executing signUp mutation');
48
+ // Extract user data from the query since we're not using a real GraphQL parser
49
+ const userMatch = body.query.match(/signUp\(user:\s*{([^}]+)}\)/);
50
+ if (userMatch) {
51
+ const userData = userMatch[1];
52
+ const emailMatch = userData.match(/email:\s*"([^"]+)"/);
53
+ const passwordMatch = userData.match(/password:\s*"([^"]+)"/);
54
+ const usernameMatch = userData.match(/username:\s*"([^"]+)"/);
55
+ const confirmMatch = userData.match(/confirm:\s*"([^"]+)"/);
56
+
57
+ const user = {
58
+ email: emailMatch ? emailMatch[1] : '',
59
+ password: passwordMatch ? passwordMatch[1] : '',
60
+ username: usernameMatch ? usernameMatch[1] : '',
61
+ confirm: confirmMatch ? confirmMatch[1] : ''
62
+ };
63
+
64
+ const result = resolvers.Mutation.signUp(null, { user });
65
+ console.log('SignUp result:', result);
66
+
67
+ return {
68
+ statusCode: 200,
69
+ headers: {
70
+ 'Content-Type': 'application/json'
71
+ },
72
+ body: JSON.stringify({
73
+ data: {
74
+ users: {
75
+ signUp: result
76
+ }
77
+ }
78
+ })
79
+ };
80
+ }
81
+ } else if (body.query.includes('hello')) {
82
+ console.log('Executing hello query');
83
+ const result = resolvers.Query.hello();
84
+ console.log('Hello result:', result);
85
+
86
+ return {
87
+ statusCode: 200,
88
+ headers: {
89
+ 'Content-Type': 'application/json'
90
+ },
91
+ body: JSON.stringify({
92
+ data: {
93
+ hello: result
94
+ }
95
+ })
96
+ };
97
+ } else if (body.query.includes('users')) {
98
+ console.log('Executing users query');
99
+ const result = resolvers.Query.users();
100
+ console.log('Users result:', result);
101
+
102
+ return {
103
+ statusCode: 200,
104
+ headers: {
105
+ 'Content-Type': 'application/json'
106
+ },
107
+ body: JSON.stringify({
108
+ data: {
109
+ users: result
110
+ }
111
+ })
112
+ };
113
+ }
114
+
115
+ console.log('No matching query found');
116
+ return {
117
+ statusCode: 400,
118
+ headers: {
119
+ 'Content-Type': 'application/json'
120
+ },
121
+ body: JSON.stringify({
122
+ errors: [{ message: 'Query not supported' }]
123
+ })
124
+ };
125
+ } catch (error) {
126
+ console.error('GraphQL handler error:', error);
127
+ return {
128
+ statusCode: 500,
129
+ headers: {
130
+ 'Content-Type': 'application/json'
131
+ },
132
+ body: JSON.stringify({
133
+ errors: [{ message: error.message }]
134
+ })
135
+ };
136
+ }
137
+ };
@@ -0,0 +1,15 @@
1
+ export const handler = async (event, context) => {
2
+ return {
3
+ statusCode: 200,
4
+ headers: {
5
+ 'Content-Type': 'application/json'
6
+ },
7
+ body: JSON.stringify({
8
+ message: 'Hello from serverless!',
9
+ path: event.path,
10
+ method: event.httpMethod,
11
+ queryParams: event.queryStringParameters,
12
+ timestamp: new Date().toISOString()
13
+ })
14
+ };
15
+ };
@@ -0,0 +1,17 @@
1
+ export const handler = async (event, context) => {
2
+ console.log('Test handler called');
3
+ console.log('Event:', event);
4
+
5
+ return {
6
+ statusCode: 200,
7
+ headers: {
8
+ 'Content-Type': 'application/json'
9
+ },
10
+ body: JSON.stringify({
11
+ message: 'Hello from test handler!',
12
+ data: {
13
+ test: true
14
+ }
15
+ })
16
+ };
17
+ };
@@ -0,0 +1,14 @@
1
+ export const handler = async (event, context) => {
2
+ const {routeKey, connectionId} = event.requestContext;
3
+
4
+ return {
5
+ statusCode: 200,
6
+ body: JSON.stringify({
7
+ message: 'WebSocket message received',
8
+ route: routeKey,
9
+ connectionId,
10
+ receivedData: event.body,
11
+ timestamp: new Date().toISOString()
12
+ })
13
+ };
14
+ };
@@ -0,0 +1,74 @@
1
+ export default {
2
+ outputFullPath: './dist',
3
+ serverless: {
4
+ custom: {
5
+ 'serverless-offline': {
6
+ cors: true,
7
+ host: 'localhost',
8
+ httpPort: 3000,
9
+ httpsPort: 3001,
10
+ wsPort: 3002
11
+ }
12
+ },
13
+ functions: {
14
+ echo: {
15
+ events: [
16
+ {
17
+ http: {
18
+ cors: true,
19
+ method: 'POST',
20
+ path: '/echo'
21
+ }
22
+ }
23
+ ],
24
+ handler: 'handlers/echo.js'
25
+ },
26
+ graphql: {
27
+ events: [
28
+ {
29
+ http: {
30
+ cors: true,
31
+ method: 'POST',
32
+ path: '/public'
33
+ }
34
+ }
35
+ ],
36
+ handler: 'handlers/graphql.js'
37
+ },
38
+ hello: {
39
+ events: [
40
+ {
41
+ http: {
42
+ cors: true,
43
+ method: 'GET',
44
+ path: '/hello'
45
+ }
46
+ }
47
+ ],
48
+ handler: 'handlers/hello.js'
49
+ },
50
+ test: {
51
+ events: [
52
+ {
53
+ http: {
54
+ cors: true,
55
+ method: 'GET',
56
+ path: '/test'
57
+ }
58
+ }
59
+ ],
60
+ handler: 'handlers/test.js'
61
+ },
62
+ websocket: {
63
+ events: [
64
+ {
65
+ websocket: {
66
+ route: '$default'
67
+ }
68
+ }
69
+ ],
70
+ handler: 'handlers/websocket.js'
71
+ }
72
+ }
73
+ }
74
+ };
package/jest.config.mjs CHANGED
@@ -2,22 +2,23 @@
2
2
  * Copyright (c) 2018-Present, Nitrogen Labs, Inc.
3
3
  * Copyrights licensed under the MIT License. See the accompanying LICENSE file for terms.
4
4
  */
5
- import {fileURLToPath} from 'url';
6
- import {dirname, resolve} from 'path';
7
- import {deepMerge} from './dist/utils/deepMerge.js';
8
-
9
5
  import {readFileSync} from 'fs';
6
+ import merge from 'lodash/merge.js';
7
+ import {dirname, resolve} from 'path';
8
+ import {fileURLToPath} from 'url';
10
9
 
11
- const __filename = fileURLToPath(import.meta.url);
12
- const __dirname = dirname(__filename);
13
- const pack = JSON.parse(readFileSync(resolve(__dirname, 'package.json'), 'utf8'));
10
+ const filename = fileURLToPath(import.meta.url);
11
+ const dirnamePath = dirname(filename);
12
+ const pack = JSON.parse(readFileSync(resolve(dirnamePath, 'package.json'), 'utf8'));
14
13
 
15
14
  let projectJestConfig = null;
15
+
16
16
  if(process.env.LEX_CONFIG) {
17
17
  try {
18
18
  const lexConfig = JSON.parse(process.env.LEX_CONFIG);
19
19
  projectJestConfig = lexConfig.jest;
20
- } catch(error) {
20
+ } catch (error) {
21
+ // eslint-disable-next-line no-console
21
22
  console.warn('Failed to parse LEX_CONFIG:', error.message);
22
23
  }
23
24
  }
@@ -36,19 +37,19 @@ const baseConfig = {
36
37
  displayName: pack.name,
37
38
  moduleFileExtensions: ['ts', 'tsx', 'js', 'json', 'node'],
38
39
  moduleNameMapper: {
39
- '^(\\.{1,2}/.*)\\.js$': '$1',
40
+ '^(\\.{1,2}/.*)\\.js$': '$1'
40
41
  },
41
42
  rootDir: process.cwd(),
42
43
  testEnvironment: 'node',
43
44
  testRegex: '(/__tests__/.*|\\.(test|spec|integration))\\.(ts|tsx)?$',
44
45
  transform: {
45
- '^.+\.js$|^.+\.jsx$': ['babel-jest', {
46
+ '^.+\\.js$|^.+\\.jsx$': ['babel-jest', {
46
47
  presets: [
47
48
  ['@babel/preset-env', {targets: {node: 'current'}}],
48
49
  '@babel/preset-typescript'
49
50
  ]
50
51
  }],
51
- '^.+\.ts$|^.+\.tsx$': ['babel-jest', {
52
+ '^.+\\.ts$|^.+\\.tsx$': ['babel-jest', {
52
53
  presets: [
53
54
  ['@babel/preset-env', {targets: {node: 'current'}}],
54
55
  '@babel/preset-typescript',
@@ -60,7 +61,7 @@ const baseConfig = {
60
61
  };
61
62
 
62
63
  const finalConfig = projectJestConfig && Object.keys(projectJestConfig).length > 0
63
- ? deepMerge(baseConfig, projectJestConfig)
64
+ ? merge(baseConfig, projectJestConfig)
64
65
  : baseConfig;
65
66
 
66
67
  export default finalConfig;
@@ -1,4 +1,6 @@
1
+ import type { Linter } from 'eslint';
1
2
  export interface EsbuildConfig {
3
+ [key: string]: unknown;
2
4
  entryPoints?: string[];
3
5
  outdir?: string;
4
6
  platform?: 'node' | 'browser';
@@ -16,9 +18,9 @@ export interface EsbuildConfig {
16
18
  banner?: Record<string, string>;
17
19
  footer?: Record<string, string>;
18
20
  define?: Record<string, string>;
19
- [key: string]: unknown;
20
21
  }
21
22
  export interface JestConfig {
23
+ [key: string]: unknown;
22
24
  roots?: string[];
23
25
  testEnvironment?: string;
24
26
  transform?: Record<string, [string, Record<string, unknown>]>;
@@ -26,14 +28,14 @@ export interface JestConfig {
26
28
  moduleNameMapper?: Record<string, string>;
27
29
  extensionsToTreatAsEsm?: string[];
28
30
  preset?: string;
29
- [key: string]: unknown;
30
31
  }
31
32
  export interface WebpackConfig {
33
+ [key: string]: unknown;
32
34
  entry?: string | string[];
33
35
  output?: Record<string, unknown>;
34
36
  module?: Record<string, unknown>;
35
37
  plugins?: unknown[];
36
- [key: string]: unknown;
38
+ publicPath?: string;
37
39
  }
38
40
  export interface AIConfig {
39
41
  provider?: 'cursor' | 'copilot' | 'openai' | 'anthropic' | 'none';
@@ -42,14 +44,20 @@ export interface AIConfig {
42
44
  maxTokens?: number;
43
45
  temperature?: number;
44
46
  }
47
+ export interface ESLintConfig {
48
+ [key: string]: unknown;
49
+ extends?: string[];
50
+ rules?: Linter.RulesRecord;
51
+ }
45
52
  export interface LexConfigType {
46
53
  ai?: AIConfig;
47
54
  configFiles?: string[];
48
55
  copyFiles?: string[];
49
56
  entryHTML?: string;
50
57
  entryJs?: string;
51
- esbuild?: EsbuildConfig;
52
58
  env?: object;
59
+ esbuild?: EsbuildConfig;
60
+ eslint?: ESLintConfig;
53
61
  gitUrl?: string;
54
62
  jest?: JestConfig;
55
63
  libraryName?: string;
@@ -69,11 +77,11 @@ export interface LexConfigType {
69
77
  }
70
78
  export type Config = LexConfigType;
71
79
  export declare const defaultConfigValues: LexConfigType;
72
- export declare function getTypeScriptConfigPath(configName: string): string;
80
+ export declare const getTypeScriptConfigPath: (configName: string) => string;
73
81
  export declare class LexConfig {
74
82
  static config: LexConfigType;
75
- static getLexDir(): string;
76
83
  static set useTypescript(value: boolean);
84
+ static getLexDir(): string;
77
85
  static updateConfig(updatedConfig: LexConfigType): LexConfigType;
78
86
  static addConfigParams(cmd: any, params: LexConfigType): void;
79
87
  static parseConfig(cmd: any, isRoot?: boolean): Promise<void>;