@xube/kit-aws-auth 0.0.61

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.
@@ -0,0 +1,2 @@
1
+ import { XubeLog } from "@xube/kit-log";
2
+ export declare const getClientId: (clientIdName: string, log?: XubeLog) => Promise<string | undefined>;
package/dist/client.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getClientId = void 0;
4
+ const kit_aws_1 = require("@xube/kit-aws");
5
+ const kit_log_1 = require("@xube/kit-log");
6
+ const getClientId = async (clientIdName, log = kit_log_1.XubeLog.getInstance()) => {
7
+ const getParamResponse = await (0, kit_aws_1.getParameter)(clientIdName);
8
+ try {
9
+ if (getParamResponse.hasFailed() || !getParamResponse.data) {
10
+ log.error("Error when attempting to get client id from parameter store.");
11
+ log.info(JSON.stringify(getParamResponse));
12
+ return;
13
+ }
14
+ return getParamResponse.data;
15
+ }
16
+ catch (e) {
17
+ log.error("Error when attempting to get client id from parameter store.");
18
+ log.info(JSON.stringify(e));
19
+ }
20
+ return;
21
+ };
22
+ exports.getClientId = getClientId;
@@ -0,0 +1 @@
1
+ export declare const DEFAULT_USER_POOL_CLIENT_ID_NAME = "xube-user-pool-client-id";
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_USER_POOL_CLIENT_ID_NAME = void 0;
4
+ exports.DEFAULT_USER_POOL_CLIENT_ID_NAME = "xube-user-pool-client-id";
@@ -0,0 +1,3 @@
1
+ export * from "./schema/login-request";
2
+ export * from "./schema/signup-request";
3
+ export * from "./constants";
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./schema/login-request"), exports);
18
+ __exportStar(require("./schema/signup-request"), exports);
19
+ __exportStar(require("./constants"), exports);
@@ -0,0 +1,4 @@
1
+ import { XubeLog } from "@xube/kit-log";
2
+ import { LoginRequest, LoginResponse } from "./schema/login-request";
3
+ import { XubeResponse } from "@xube/kit-request";
4
+ export declare const logIn: (request: LoginRequest, log?: XubeLog) => Promise<XubeResponse<LoginResponse>>;
package/dist/login.js ADDED
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logIn = void 0;
4
+ const kit_log_1 = require("@xube/kit-log");
5
+ const kit_request_1 = require("@xube/kit-request");
6
+ const client_1 = require("./client");
7
+ const constants_1 = require("./constants");
8
+ const kit_constants_1 = require("@xube/kit-constants");
9
+ const kit_aws_1 = require("@xube/kit-aws");
10
+ const logIn = async (request, log = kit_log_1.XubeLog.getInstance()) => {
11
+ const clientId = await (0, client_1.getClientId)(constants_1.DEFAULT_USER_POOL_CLIENT_ID_NAME, log);
12
+ try {
13
+ if (!clientId) {
14
+ return new kit_request_1.XubeResponse({
15
+ statusCode: kit_constants_1.StatusCode.InternalError,
16
+ error: "Could not get client id",
17
+ });
18
+ }
19
+ const authResponse = await (0, kit_aws_1.authenticateUser)(request, kit_aws_1.AuthFlowType.USER_PASSWORD_AUTH, clientId, log);
20
+ if (authResponse.hasFailed() || !authResponse.data) {
21
+ log.warn("Could not log in");
22
+ return (0, kit_request_1.switchXubeResponseType)(authResponse);
23
+ }
24
+ const authInformation = authResponse.data;
25
+ log.info(`Log in was successful. Returning tokens for ${request.email}`);
26
+ return new kit_request_1.XubeResponse({
27
+ statusCode: kit_constants_1.StatusCode.OK,
28
+ data: authInformation,
29
+ });
30
+ }
31
+ catch (e) {
32
+ log.error("Error when attempting log in");
33
+ log.info(JSON.stringify(e));
34
+ }
35
+ return new kit_request_1.XubeResponse({
36
+ statusCode: kit_constants_1.StatusCode.InternalError,
37
+ error: "Error when attempting log in",
38
+ });
39
+ };
40
+ exports.logIn = logIn;
@@ -0,0 +1,36 @@
1
+ import { z } from "zod";
2
+ export declare const LoginRequestSchema: z.ZodObject<{
3
+ email: z.ZodString;
4
+ password: z.ZodString;
5
+ }, "strip", z.ZodTypeAny, {
6
+ email: string;
7
+ password: string;
8
+ }, {
9
+ email: string;
10
+ password: string;
11
+ }>;
12
+ export type LoginRequest = z.infer<typeof LoginRequestSchema>;
13
+ export declare const isLoginRequest: (object: unknown) => object is {
14
+ email: string;
15
+ password: string;
16
+ };
17
+ export declare const LoginResponseSchema: z.ZodObject<{
18
+ token: z.ZodString;
19
+ accessToken: z.ZodString;
20
+ refreshToken: z.ZodString;
21
+ expiry: z.ZodNumber;
22
+ deviceKey: z.ZodOptional<z.ZodString>;
23
+ }, "strip", z.ZodTypeAny, {
24
+ token: string;
25
+ accessToken: string;
26
+ refreshToken: string;
27
+ expiry: number;
28
+ deviceKey?: string | undefined;
29
+ }, {
30
+ token: string;
31
+ accessToken: string;
32
+ refreshToken: string;
33
+ expiry: number;
34
+ deviceKey?: string | undefined;
35
+ }>;
36
+ export type LoginResponse = z.infer<typeof LoginResponseSchema>;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LoginResponseSchema = exports.isLoginRequest = exports.LoginRequestSchema = void 0;
4
+ const kit_aws_schema_1 = require("@xube/kit-aws-schema");
5
+ exports.LoginRequestSchema = kit_aws_schema_1.AuthenticationRequestSchema;
6
+ const isLoginRequest = (object) => exports.LoginRequestSchema.passthrough().safeParse(object).success;
7
+ exports.isLoginRequest = isLoginRequest;
8
+ exports.LoginResponseSchema = kit_aws_schema_1.AuthenticationResponseSchema;
@@ -0,0 +1,36 @@
1
+ import { z } from "zod";
2
+ export declare const SignupRequestSchema: z.ZodObject<{
3
+ email: z.ZodString;
4
+ password: z.ZodString;
5
+ }, "strip", z.ZodTypeAny, {
6
+ email: string;
7
+ password: string;
8
+ }, {
9
+ email: string;
10
+ password: string;
11
+ }>;
12
+ export type SignupRequest = z.infer<typeof SignupRequestSchema>;
13
+ export declare const isSignupRequest: (object: unknown) => object is {
14
+ email: string;
15
+ password: string;
16
+ };
17
+ export declare const SignupResponseSchema: z.ZodObject<{
18
+ token: z.ZodString;
19
+ accessToken: z.ZodString;
20
+ refreshToken: z.ZodString;
21
+ expiry: z.ZodNumber;
22
+ deviceKey: z.ZodOptional<z.ZodString>;
23
+ }, "strip", z.ZodTypeAny, {
24
+ token: string;
25
+ accessToken: string;
26
+ refreshToken: string;
27
+ expiry: number;
28
+ deviceKey?: string | undefined;
29
+ }, {
30
+ token: string;
31
+ accessToken: string;
32
+ refreshToken: string;
33
+ expiry: number;
34
+ deviceKey?: string | undefined;
35
+ }>;
36
+ export type SignupResponse = z.infer<typeof SignupResponseSchema>;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SignupResponseSchema = exports.isSignupRequest = exports.SignupRequestSchema = void 0;
4
+ const kit_aws_schema_1 = require("@xube/kit-aws-schema");
5
+ exports.SignupRequestSchema = kit_aws_schema_1.AuthenticationRequestSchema;
6
+ const isSignupRequest = (object) => exports.SignupRequestSchema.passthrough().safeParse(object).success;
7
+ exports.isSignupRequest = isSignupRequest;
8
+ exports.SignupResponseSchema = kit_aws_schema_1.AuthenticationResponseSchema;
@@ -0,0 +1,4 @@
1
+ import { XubeLog } from "@xube/kit-log";
2
+ import { SignupRequest, SignupResponse } from "./schema/signup-request";
3
+ import { XubeResponse } from "@xube/kit-request";
4
+ export declare const createUser: (request: SignupRequest, log?: XubeLog) => Promise<XubeResponse<SignupResponse>>;
package/dist/signup.js ADDED
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createUser = void 0;
4
+ const kit_log_1 = require("@xube/kit-log");
5
+ const kit_request_1 = require("@xube/kit-request");
6
+ const client_1 = require("./client");
7
+ const constants_1 = require("./constants");
8
+ const kit_constants_1 = require("@xube/kit-constants");
9
+ const kit_aws_1 = require("@xube/kit-aws");
10
+ const createUser = async (request, log = kit_log_1.XubeLog.getInstance()) => {
11
+ log.info("Attempting to create user");
12
+ const lowercasedEmail = request.email.toLowerCase();
13
+ log.info(`New User Email: ${lowercasedEmail}`);
14
+ const clientId = await (0, client_1.getClientId)(constants_1.DEFAULT_USER_POOL_CLIENT_ID_NAME, log);
15
+ if (!clientId) {
16
+ log.error("Client ID could not be retrieved.");
17
+ return new kit_request_1.XubeResponse({
18
+ statusCode: kit_constants_1.StatusCode.InternalError,
19
+ error: "Client ID could not be retrieved.",
20
+ });
21
+ }
22
+ log.info("Client ID retrieved: " + clientId);
23
+ try {
24
+ log.info("Preparing sign up command");
25
+ const registerUserResponse = await (0, kit_aws_1.register)(request, clientId, log);
26
+ if (registerUserResponse.hasFailed() || !registerUserResponse.data) {
27
+ log.error("Error occurred when signing up user: " + lowercasedEmail);
28
+ log.info(JSON.stringify(registerUserResponse));
29
+ }
30
+ else {
31
+ log.info("User successfully created and authenticated");
32
+ }
33
+ return registerUserResponse;
34
+ }
35
+ catch (e) {
36
+ log.info("Error occurred when signing up user: " + request.email?.toLowerCase());
37
+ log.info(JSON.stringify(e));
38
+ throw e;
39
+ }
40
+ };
41
+ exports.createUser = createUser;
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@xube/kit-aws-auth",
3
+ "version": "0.0.61",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+ssh://git@github.com/XubeLtd/dev-kit.git"
12
+ },
13
+ "author": "Xube Pty Ltd",
14
+ "license": "MIT",
15
+ "bugs": {
16
+ "url": "https://github.com/XubeLtd/dev-kit/issues"
17
+ },
18
+ "homepage": "https://github.com/XubeLtd/dev-kit#readme",
19
+ "devDependencies": {
20
+ "@xube/kit-build": "^0.0.61"
21
+ },
22
+ "dependencies": {
23
+ "@xube/kit-aws": "^0.0.61",
24
+ "@xube/kit-aws-schema": "^0.0.61",
25
+ "@xube/kit-constants": "^0.0.61",
26
+ "@xube/kit-log": "^0.0.61",
27
+ "@xube/kit-request": "^0.0.61",
28
+ "@xube/kit-schema": "^0.0.61",
29
+ "zod": "^3.22.4"
30
+ }
31
+ }
package/src/client.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { getParameter } from "@xube/kit-aws";
2
+ import { XubeLog } from "@xube/kit-log";
3
+
4
+ export const getClientId = async (
5
+ clientIdName: string,
6
+ log: XubeLog = XubeLog.getInstance()
7
+ ): Promise<string | undefined> => {
8
+ const getParamResponse = await getParameter(clientIdName);
9
+
10
+ try {
11
+ if (getParamResponse.hasFailed() || !getParamResponse.data) {
12
+ log.error("Error when attempting to get client id from parameter store.");
13
+ log.info(JSON.stringify(getParamResponse));
14
+ return;
15
+ }
16
+ return getParamResponse.data;
17
+ } catch (e) {
18
+ log.error("Error when attempting to get client id from parameter store.");
19
+ log.info(JSON.stringify(e));
20
+ }
21
+
22
+ return;
23
+ };
24
+
@@ -0,0 +1 @@
1
+ export const DEFAULT_USER_POOL_CLIENT_ID_NAME = "xube-user-pool-client-id";
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./schema/login-request"
2
+ export * from "./schema/signup-request";
3
+ export * from "./constants";
package/src/login.ts ADDED
@@ -0,0 +1,55 @@
1
+ import { XubeLog } from "@xube/kit-log";
2
+ import { LoginRequest, LoginResponse } from "./schema/login-request";
3
+ import { XubeResponse, switchXubeResponseType } from "@xube/kit-request";
4
+ import { getClientId } from "./client";
5
+ import { DEFAULT_USER_POOL_CLIENT_ID_NAME } from "./constants";
6
+ import { StatusCode } from "@xube/kit-constants";
7
+ import { AuthFlowType, authenticateUser } from "@xube/kit-aws";
8
+
9
+ export const logIn = async (
10
+ request: LoginRequest,
11
+ log: XubeLog = XubeLog.getInstance()
12
+ ): Promise<XubeResponse<LoginResponse>> => {
13
+ const clientId: string | undefined = await getClientId(
14
+ DEFAULT_USER_POOL_CLIENT_ID_NAME,
15
+ log
16
+ );
17
+
18
+ try {
19
+ if (!clientId) {
20
+ return new XubeResponse({
21
+ statusCode: StatusCode.InternalError,
22
+ error: "Could not get client id",
23
+ });
24
+ }
25
+
26
+ const authResponse = await authenticateUser(
27
+ request,
28
+ AuthFlowType.USER_PASSWORD_AUTH,
29
+ clientId,
30
+ log
31
+ );
32
+
33
+ if (authResponse.hasFailed() || !authResponse.data) {
34
+ log.warn("Could not log in");
35
+ return switchXubeResponseType(authResponse);
36
+ }
37
+
38
+ const authInformation = authResponse.data;
39
+
40
+ log.info(`Log in was successful. Returning tokens for ${request.email}`);
41
+
42
+ return new XubeResponse({
43
+ statusCode: StatusCode.OK,
44
+ data: authInformation,
45
+ });
46
+ } catch (e) {
47
+ log.error("Error when attempting log in");
48
+ log.info(JSON.stringify(e));
49
+ }
50
+
51
+ return new XubeResponse({
52
+ statusCode: StatusCode.InternalError,
53
+ error: "Error when attempting log in",
54
+ });
55
+ };
@@ -0,0 +1,13 @@
1
+ import {
2
+ AuthenticationRequestSchema,
3
+ AuthenticationResponseSchema,
4
+ } from "@xube/kit-aws-schema";
5
+ import { z } from "zod";
6
+
7
+ export const LoginRequestSchema = AuthenticationRequestSchema;
8
+ export type LoginRequest = z.infer<typeof LoginRequestSchema>;
9
+ export const isLoginRequest = (object: unknown): object is LoginRequest =>
10
+ LoginRequestSchema.passthrough().safeParse(object).success;
11
+
12
+ export const LoginResponseSchema = AuthenticationResponseSchema;
13
+ export type LoginResponse = z.infer<typeof LoginResponseSchema>;
@@ -0,0 +1,13 @@
1
+ import {
2
+ AuthenticationRequestSchema,
3
+ AuthenticationResponseSchema,
4
+ } from "@xube/kit-aws-schema";
5
+ import { z } from "zod";
6
+
7
+ export const SignupRequestSchema = AuthenticationRequestSchema;
8
+ export type SignupRequest = z.infer<typeof SignupRequestSchema>;
9
+ export const isSignupRequest = (object: unknown): object is SignupRequest =>
10
+ SignupRequestSchema.passthrough().safeParse(object).success;
11
+
12
+ export const SignupResponseSchema = AuthenticationResponseSchema;
13
+ export type SignupResponse = z.infer<typeof SignupResponseSchema>;
package/src/signup.ts ADDED
@@ -0,0 +1,54 @@
1
+ import { XubeLog } from "@xube/kit-log";
2
+ import { SignupRequest, SignupResponse } from "./schema/signup-request";
3
+ import { XubeResponse } from "@xube/kit-request";
4
+ import { getClientId } from "./client";
5
+ import { DEFAULT_USER_POOL_CLIENT_ID_NAME } from "./constants";
6
+ import { StatusCode } from "@xube/kit-constants";
7
+ import { register } from "@xube/kit-aws";
8
+
9
+ export const createUser = async (
10
+ request: SignupRequest,
11
+ log: XubeLog = XubeLog.getInstance()
12
+ ): Promise<XubeResponse<SignupResponse>> => {
13
+ log.info("Attempting to create user");
14
+ const lowercasedEmail: string = request.email.toLowerCase();
15
+
16
+ log.info(`New User Email: ${lowercasedEmail}`);
17
+
18
+ const clientId = await getClientId(DEFAULT_USER_POOL_CLIENT_ID_NAME, log);
19
+
20
+ if (!clientId) {
21
+ log.error("Client ID could not be retrieved.");
22
+ return new XubeResponse({
23
+ statusCode: StatusCode.InternalError,
24
+ error: "Client ID could not be retrieved.",
25
+ });
26
+ }
27
+
28
+ log.info("Client ID retrieved: " + clientId);
29
+
30
+ try {
31
+ log.info("Preparing sign up command");
32
+
33
+ const registerUserResponse: XubeResponse<SignupResponse> = await register(
34
+ request,
35
+ clientId,
36
+ log
37
+ );
38
+
39
+ if (registerUserResponse.hasFailed() || !registerUserResponse.data) {
40
+ log.error("Error occurred when signing up user: " + lowercasedEmail);
41
+ log.info(JSON.stringify(registerUserResponse));
42
+ } else {
43
+ log.info("User successfully created and authenticated");
44
+ }
45
+
46
+ return registerUserResponse;
47
+ } catch (e) {
48
+ log.info(
49
+ "Error occurred when signing up user: " + request.email?.toLowerCase()
50
+ );
51
+ log.info(JSON.stringify(e));
52
+ throw e;
53
+ }
54
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "extends": "../kit-build/tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src",
5
+ "outDir": "./dist"
6
+ },
7
+ "exclude": ["**/*.test.ts", "**/*.mock.ts", "dist"],
8
+ "references": [
9
+ {
10
+ "path": "../kit-constants"
11
+ },
12
+ {
13
+ "path": "../kit-log"
14
+ },
15
+ {
16
+ "path": "../kit-schema"
17
+ },
18
+ {
19
+ "path": "../kit-aws-schema"
20
+ },
21
+ {
22
+ "path": "../kit-aws"
23
+ },
24
+ {
25
+ "path": "../kit-request"
26
+ }
27
+ ]
28
+ }