@xube/kit-aws-auth-infrastructure 0.0.63 → 0.0.65

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/dist/api/login.js CHANGED
@@ -11,7 +11,7 @@ class LoginAPI extends constructs_1.Construct {
11
11
  constructor(scope, id, props) {
12
12
  super(scope, id);
13
13
  this.loginFunction = new aws_lambda_nodejs_1.NodejsFunction(scope, id + "-login", {
14
- entry: (0, path_1.join)(__dirname, "../functions/login.ts"),
14
+ entry: (0, path_1.join)(__dirname, "../functions/login.js"),
15
15
  runtime: aws_lambda_1.Runtime.NODEJS_18_X,
16
16
  functionName: props.name,
17
17
  });
@@ -11,7 +11,7 @@ class SignUpAPI extends constructs_1.Construct {
11
11
  constructor(scope, id, props) {
12
12
  super(scope, id);
13
13
  this.signupFunction = new aws_lambda_nodejs_1.NodejsFunction(scope, id + "-signup", {
14
- entry: (0, path_1.join)(__dirname, "../functions/signup.ts"),
14
+ entry: (0, path_1.join)(__dirname, "../functions/signup.js"),
15
15
  runtime: aws_lambda_1.Runtime.NODEJS_18_X,
16
16
  functionName: props.name,
17
17
  });
@@ -17,7 +17,7 @@ class AuthManagement extends constructs_1.Construct {
17
17
  constructor(scope, id, props) {
18
18
  super(scope, id);
19
19
  const presignup = new aws_lambda_nodejs_1.NodejsFunction(scope, id + "-pre-signup", {
20
- entry: (0, path_1.join)(__dirname, "functions/pre-signup.ts"),
20
+ entry: (0, path_1.join)(__dirname, "functions/pre-signup.js"),
21
21
  runtime: aws_lambda_1.Runtime.NODEJS_18_X,
22
22
  functionName: props.name + "-pre-signup",
23
23
  });
@@ -1 +1,2 @@
1
- export {};
1
+ import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from "aws-lambda";
2
+ export declare const handler: (event: APIGatewayProxyEvent, context: Context) => Promise<APIGatewayProxyResult>;
@@ -1,2 +1,42 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handler = void 0;
4
+ const kit_constants_1 = require("@xube/kit-constants");
5
+ const kit_aws_auth_1 = require("@xube/kit-aws-auth");
6
+ const kit_aws_auth_2 = require("@xube/kit-aws-auth");
7
+ const kit_log_1 = require("@xube/kit-log");
8
+ const handler = async (event, context) => {
9
+ const log = kit_log_1.XubeLog.getInstance();
10
+ if (!event.body) {
11
+ return {
12
+ statusCode: kit_constants_1.StatusCode.BadRequest,
13
+ body: "No body found",
14
+ };
15
+ }
16
+ try {
17
+ const body = JSON.parse(event.body);
18
+ if (!(0, kit_aws_auth_1.isLoginRequest)(body)) {
19
+ return {
20
+ statusCode: kit_constants_1.StatusCode.BadRequest,
21
+ body: "Invalid login request",
22
+ };
23
+ }
24
+ const loginResponse = await (0, kit_aws_auth_2.logIn)(body);
25
+ if (loginResponse.hasFailed()) {
26
+ log.info(`Login failed: ${JSON.stringify(loginResponse)}`);
27
+ }
28
+ return {
29
+ statusCode: loginResponse.statusCode,
30
+ body: JSON.stringify(loginResponse.data) ??
31
+ loginResponse.error ??
32
+ `Could not complete login request`,
33
+ };
34
+ }
35
+ catch (error) {
36
+ return {
37
+ statusCode: kit_constants_1.StatusCode.InternalError,
38
+ body: "An internal error occurred when logging in.",
39
+ };
40
+ }
41
+ };
42
+ exports.handler = handler;
@@ -0,0 +1,2 @@
1
+ import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from "aws-lambda";
2
+ export declare const handler: (event: APIGatewayProxyEvent, context: Context) => Promise<APIGatewayProxyResult>;
@@ -1 +1,41 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handler = void 0;
4
+ const kit_aws_auth_1 = require("@xube/kit-aws-auth");
5
+ const kit_constants_1 = require("@xube/kit-constants");
6
+ const kit_log_1 = require("@xube/kit-log");
7
+ const handler = async (event, context) => {
8
+ const log = kit_log_1.XubeLog.getInstance();
9
+ if (!event.body) {
10
+ return {
11
+ statusCode: kit_constants_1.StatusCode.BadRequest,
12
+ body: "No body found",
13
+ };
14
+ }
15
+ try {
16
+ const body = JSON.parse(event.body);
17
+ if (!(0, kit_aws_auth_1.isSignupRequest)(body)) {
18
+ return {
19
+ statusCode: kit_constants_1.StatusCode.BadRequest,
20
+ body: "Invalid signup request",
21
+ };
22
+ }
23
+ const createUserResponse = await (0, kit_aws_auth_1.createUser)(body, log);
24
+ if (createUserResponse.hasFailed()) {
25
+ log.info(`Signup failed: ${JSON.stringify(createUserResponse)}`);
26
+ }
27
+ return {
28
+ statusCode: createUserResponse.statusCode,
29
+ body: JSON.stringify(createUserResponse.data) ??
30
+ createUserResponse.error ??
31
+ `Could not complete signup request`,
32
+ };
33
+ }
34
+ catch (error) {
35
+ return {
36
+ statusCode: kit_constants_1.StatusCode.InternalError,
37
+ body: "An internal error occurred when signing up in.",
38
+ };
39
+ }
40
+ };
41
+ exports.handler = handler;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
- export * from "./auth-management";
2
1
  export * from "./api/auth-api";
2
+ export * from "./api/login";
3
+ export * from "./api/signup";
4
+ export * from "./auth-management";
package/dist/index.js CHANGED
@@ -14,5 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./auth-management"), exports);
18
17
  __exportStar(require("./api/auth-api"), exports);
18
+ __exportStar(require("./api/login"), exports);
19
+ __exportStar(require("./api/signup"), exports);
20
+ __exportStar(require("./auth-management"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xube/kit-aws-auth-infrastructure",
3
- "version": "0.0.63",
3
+ "version": "0.0.65",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -17,14 +17,15 @@
17
17
  },
18
18
  "homepage": "https://github.com/XubeLtd/dev-kit#readme",
19
19
  "devDependencies": {
20
- "@xube/kit-build": "^0.0.63"
20
+ "@xube/kit-build": "^0.0.65"
21
21
  },
22
22
  "dependencies": {
23
- "@xube/kit-aws": "^0.0.63",
24
- "@xube/kit-aws-hooks": "^0.0.63",
25
- "@xube/kit-aws-infrastructure": "^0.0.63",
26
- "@xube/kit-constants": "^0.0.63",
27
- "@xube/kit-log": "^0.0.63",
23
+ "@xube/kit-aws": "^0.0.65",
24
+ "@xube/kit-aws-auth": "^0.0.65",
25
+ "@xube/kit-aws-hooks": "^0.0.65",
26
+ "@xube/kit-aws-infrastructure": "^0.0.65",
27
+ "@xube/kit-constants": "^0.0.65",
28
+ "@xube/kit-log": "^0.0.65",
28
29
  "aws-cdk-lib": "^2.100.0",
29
30
  "aws-lambda": "^1.0.7",
30
31
  "constructs": "^10.3.0"
package/src/api/login.ts CHANGED
@@ -23,7 +23,7 @@ export class LoginAPI extends Construct {
23
23
  super(scope, id);
24
24
 
25
25
  this.loginFunction = new NodejsFunction(scope, id + "-login", {
26
- entry: join(__dirname, "../functions/login.ts"),
26
+ entry: join(__dirname, "../functions/login.js"),
27
27
  runtime: Runtime.NODEJS_18_X,
28
28
  functionName: props.name,
29
29
  });
package/src/api/signup.ts CHANGED
@@ -23,7 +23,7 @@ export class SignUpAPI extends Construct {
23
23
  super(scope, id);
24
24
 
25
25
  this.signupFunction = new NodejsFunction(scope, id + "-signup", {
26
- entry: join(__dirname, "../functions/signup.ts"),
26
+ entry: join(__dirname, "../functions/signup.js"),
27
27
  runtime: Runtime.NODEJS_18_X,
28
28
  functionName: props.name,
29
29
  });
@@ -34,7 +34,7 @@ export class AuthManagement extends Construct {
34
34
  scope,
35
35
  id + "-pre-signup",
36
36
  {
37
- entry: join(__dirname, "functions/pre-signup.ts"),
37
+ entry: join(__dirname, "functions/pre-signup.js"),
38
38
  runtime: Runtime.NODEJS_18_X,
39
39
  functionName: props.name + "-pre-signup",
40
40
  }
@@ -1,2 +1,51 @@
1
1
  import { StatusCode } from "@xube/kit-constants";
2
- import { XubeResponse } from "../../../kit-request/src";
2
+ import {
3
+ APIGatewayProxyEvent,
4
+ APIGatewayProxyResult,
5
+ Context,
6
+ } from "aws-lambda";
7
+ import { isLoginRequest } from "@xube/kit-aws-auth";
8
+ import { logIn } from "@xube/kit-aws-auth";
9
+ import { XubeLog } from "@xube/kit-log";
10
+
11
+ export const handler = async (
12
+ event: APIGatewayProxyEvent,
13
+ context: Context
14
+ ): Promise<APIGatewayProxyResult> => {
15
+ const log = XubeLog.getInstance();
16
+ if (!event.body) {
17
+ return {
18
+ statusCode: StatusCode.BadRequest,
19
+ body: "No body found",
20
+ };
21
+ }
22
+
23
+ try {
24
+ const body = JSON.parse(event.body);
25
+
26
+ if (!isLoginRequest(body)) {
27
+ return {
28
+ statusCode: StatusCode.BadRequest,
29
+ body: "Invalid login request",
30
+ };
31
+ }
32
+
33
+ const loginResponse = await logIn(body);
34
+
35
+ if (loginResponse.hasFailed()) {
36
+ log.info(`Login failed: ${JSON.stringify(loginResponse)}`);
37
+ }
38
+ return {
39
+ statusCode: loginResponse.statusCode,
40
+ body:
41
+ JSON.stringify(loginResponse.data) ??
42
+ loginResponse.error ??
43
+ `Could not complete login request`,
44
+ };
45
+ } catch (error) {
46
+ return {
47
+ statusCode: StatusCode.InternalError,
48
+ body: "An internal error occurred when logging in.",
49
+ };
50
+ }
51
+ };
@@ -0,0 +1,52 @@
1
+ import { createUser, isSignupRequest } from "@xube/kit-aws-auth";
2
+ import { StatusCode } from "@xube/kit-constants";
3
+ import { XubeLog } from "@xube/kit-log";
4
+ import {
5
+ APIGatewayProxyEvent,
6
+ APIGatewayProxyResult,
7
+ Context,
8
+ } from "aws-lambda";
9
+
10
+ export const handler = async (
11
+ event: APIGatewayProxyEvent,
12
+ context: Context
13
+ ): Promise<APIGatewayProxyResult> => {
14
+ const log = XubeLog.getInstance();
15
+
16
+ if (!event.body) {
17
+ return {
18
+ statusCode: StatusCode.BadRequest,
19
+ body: "No body found",
20
+ };
21
+ }
22
+
23
+ try {
24
+ const body = JSON.parse(event.body);
25
+
26
+ if (!isSignupRequest(body)) {
27
+ return {
28
+ statusCode: StatusCode.BadRequest,
29
+ body: "Invalid signup request",
30
+ };
31
+ }
32
+
33
+ const createUserResponse = await createUser(body, log);
34
+
35
+ if (createUserResponse.hasFailed()) {
36
+ log.info(`Signup failed: ${JSON.stringify(createUserResponse)}`);
37
+ }
38
+
39
+ return {
40
+ statusCode: createUserResponse.statusCode,
41
+ body:
42
+ JSON.stringify(createUserResponse.data) ??
43
+ createUserResponse.error ??
44
+ `Could not complete signup request`,
45
+ };
46
+ } catch (error) {
47
+ return {
48
+ statusCode: StatusCode.InternalError,
49
+ body: "An internal error occurred when signing up in.",
50
+ };
51
+ }
52
+ };
package/src/index.ts CHANGED
@@ -1,2 +1,4 @@
1
- export * from "./auth-management";
2
- export * from "./api/auth-api";
1
+ export * from "./api/auth-api";
2
+ export * from "./api/login";
3
+ export * from "./api/signup";
4
+ export * from "./auth-management";