Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve sdk #18

Merged
merged 110 commits into from
Jan 19, 2024
Merged

Improve sdk #18

merged 110 commits into from
Jan 19, 2024

Conversation

corbadoman
Copy link
Contributor

No description provided.

@corbadoman corbadoman linked an issue Dec 17, 2023 that may be closed by this pull request
34 tasks
@corbadoman corbadoman changed the title 17 improve sdk Improve sdk Dec 17, 2023
src/sdk.ts Outdated Show resolved Hide resolved
src/sdk.ts Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/config.ts Outdated Show resolved Hide resolved
src/sdk.ts Show resolved Hide resolved
src/sdk.ts Show resolved Hide resolved
sam-corbado and others added 9 commits January 18, 2024 09:40
…hToken.test.ts

🐛 fix(emailLink.test.ts): remove unnecessary import of axios from emailLink.test.ts
🐛 fix(emailOtp.test.ts): remove unnecessary import of axios from emailOtp.test.ts
🐛 fix(smsOtp.test.ts): remove unnecessary import of axios from smsOtp.test.ts
🐛 fix(user.test.ts): remove unnecessary import of axios from user.test.ts
🐛 fix(utils.ts): add missing import of AxiosMockAdapter in utils.ts
✨ feat(utils.ts): add utility functions MockAxiosInstance and restoreMock to simplify mocking axios in tests
🐛 fix(assert.ts): add validation for URL in the assert class to ensure it is valid and meets certain criteria
… instead of relying on environment variable for consistency and reliability

✨ feat(config.ts): add methods setFrontendAPI and setBackendAPI to allow dynamic configuration of frontend and backend APIs
…uppercase PORT to improve semantics

✨ feat(server.ts): add support for process.env.PORT environment variable to be able to run app on a configurable port
📦 deps(package.json): add memory-cache-node package as a dependency
🔧 chore(config.ts): import MemoryCache from memory-cache-node and axios from axios
🔧 chore(config.ts): add JWKSCache property to ConfigInterface and set it to DefaultJwksCache
🔧 chore(config.ts): add DefaultClient property to ConfigInterface and set it to DefaultClient
🔧 chore(config.ts): add setHttpClient method to Config class to set the http client
🔧 chore(config.ts): add setJwksCache method to Config class to set the JWKS cache
🔧 chore(config.ts): add setShortSessionCookieName method to Config class to set the short session cookie name
🔧 chore(index.ts): remove export of DefaultBackendAPI, DefaultFrontendAPI, DefaultShortSessionCookieName, and DefaultCacheMaxAge
🔧 chore(index.ts): remove import of DefaultBackendAPI, DefaultFrontendAPI, DefaultShortSessionCookieName, and DefaultCacheMaxAge
🔧 chore(index.ts): remove export of DefaultBackendAPI, DefaultFrontendAPI, DefaultShortSessionCookieName, and DefaultCacheMaxAge
🔧 chore(index.ts): remove import of DefaultBackendAPI, DefaultFrontendAPI, DefaultShortSessionCookieName, and DefaultCacheMaxAge
🔧 chore(sdk.ts): add jwksCache parameter to Session constructor and assign it to this.JWKSCache
🔧 chore(sdk.ts): add axiosClient parameter to Session constructor and assign it to this.Client
🔧 chore(sessionService.ts): add client parameter to Session constructor and assign it to this.client
🔧 chore(sessionService.ts): add jwksCache parameter to Session constructor and assign it to this.jwksCache
🔧 chore(sessionService.ts): add cacheMaxAge parameter to Session constructor and assign it to this.cacheMaxAge
🔧 chore(sessionService.ts): add jwksCache property to Session class and assign it to DefaultJwksCache
🔧 chore(sessionService.ts): add cacheMaxAge property to Session class and assign it to DefaultCacheMaxAge
🔧 chore(session
… the correct SDK usage and services

🔧 chore(sdk.ts): rename emailOtp() method to emailOtps() for consistency with other service methods

🔧 chore(emailOtp.test.ts): update method calls from sdk.emailOtp() to sdk.emailOtps()

🔧 chore(smsOtp.test.ts): update method calls from sdk.smsOtp() to sdk.smsOtps()

🔧 chore(config.test.ts): add unit tests for the Config class to ensure proper instantiation and default values

🔧 chore(sdk.test.ts): add unit tests for the SDK class to ensure proper instantiation and creation of service objects
corbadoman and others added 10 commits January 18, 2024 21:06
…face and related methods

🔒 chore(sessionService.ts): change validateShortSessionValue and getCurrentUser methods to accept token as a string parameter instead of RequestWithCookies object
…o optimize package size and improve maintainability

🔧 chore(config.ts): remove unused import of 'memory-cache-node' to improve code readability and maintainability
🔧 chore(sdk.ts): update jwks URI concatenation to use template literals for better code readability
🔧 chore(sessionService.ts): remove unused import of 'memory-cache-node' to improve code readability and maintainability
🔧 chore(config.test.ts): remove unused import of 'DefaultJwksCache' to improve code readability and maintainability
🔧 chore(session.test.ts): remove unused import of 'MemoryCache' to improve code readability and maintainability
…ile extension to avoid potential import errors
…o ensure correct instantiation and default values

🔧 chore(sdk.test.ts): add unit tests for the SDK class to ensure correct instantiation and creation of various objects
🔧 chore(user.test.ts): remove unit tests for the User entity as they are no longer needed
🔧 chore(authToken.test.ts): remove unit tests for the AuthToken service as they are no longer needed
🔧 chore(emailLink.test.ts): remove unit tests for the EmailLink service as they are no longer needed
🔧 chore(emailOtp.test.ts): remove unit tests for the EmailOTP service as they are no longer needed
🔧 chore(session.test.ts): remove unit tests for the Session service as they are no longer needed
🔧 chore(smsOtp.test.ts): remove unit tests for the SmsOTP service as they are no longer needed
🔧 chore(user.test.ts): remove unit tests for the User service as they are no longer needed
…ies and authentication

This commit adds a new file `sessionExample.ts` which contains example code for handling session cookies and authentication in an Express.js application. The code sets up an Express server, configures cookie parsing, and initializes the Corbado SDK with the necessary credentials.

The code includes three routes:
- The root route ("/") simply returns a "Hello world!" message.
- The "/setCookie" route sets a short session cookie with a predefined value. The cookie is set with a maximum age of 15 minutes and is marked as HTTP-only.
- The "/logged-in" route demonstrates how to handle authentication using the Corbado SDK. It retrieves the short session cookie from the request, verifies the user's authentication status, and displays user information if authenticated. If the user is not authenticated, it redirects to a login page.

The server is set to listen on port 8080.

This code serves as an example for developers who want to implement session cookies and authentication using the Corbado SDK in their Express.js applications.
@corbadoman corbadoman merged commit 4c00f5b into main Jan 19, 2024
4 checks passed
@corbadoman corbadoman deleted the 17-improve-sdk branch January 19, 2024 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve SDK
4 participants