cloud-ide-shared 0.0.2
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/README.md +63 -0
- package/fesm2022/cloud-ide-shared.mjs +54 -0
- package/fesm2022/cloud-ide-shared.mjs.map +1 -0
- package/index.d.ts +26 -0
- package/package.json +23 -0
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# CloudIdeShared
|
|
2
|
+
|
|
3
|
+
This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 20.1.0.
|
|
4
|
+
|
|
5
|
+
## Code scaffolding
|
|
6
|
+
|
|
7
|
+
Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
ng generate component component-name
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
ng generate --help
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Building
|
|
20
|
+
|
|
21
|
+
To build the library, run:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
ng build cloud-ide-shared
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
This command will compile your project, and the build artifacts will be placed in the `dist/` directory.
|
|
28
|
+
|
|
29
|
+
### Publishing the Library
|
|
30
|
+
|
|
31
|
+
Once the project is built, you can publish your library by following these steps:
|
|
32
|
+
|
|
33
|
+
1. Navigate to the `dist` directory:
|
|
34
|
+
```bash
|
|
35
|
+
cd dist/cloud-ide-shared
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
2. Run the `npm publish` command to publish your library to the npm registry:
|
|
39
|
+
```bash
|
|
40
|
+
npm publish
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Running unit tests
|
|
44
|
+
|
|
45
|
+
To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
ng test
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Running end-to-end tests
|
|
52
|
+
|
|
53
|
+
For end-to-end (e2e) testing, run:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
ng e2e
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
|
|
60
|
+
|
|
61
|
+
## Additional Resources
|
|
62
|
+
|
|
63
|
+
For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Component, InjectionToken, inject } from '@angular/core';
|
|
3
|
+
import { Router } from '@angular/router';
|
|
4
|
+
|
|
5
|
+
class CloudIdeShared {
|
|
6
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.7", ngImport: i0, type: CloudIdeShared, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
7
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.1.7", type: CloudIdeShared, isStandalone: true, selector: "lib-cloud-ide-shared", ngImport: i0, template: `
|
|
8
|
+
<p>
|
|
9
|
+
cloud-ide-shared works!
|
|
10
|
+
</p>
|
|
11
|
+
`, isInline: true, styles: [""] });
|
|
12
|
+
}
|
|
13
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.7", ngImport: i0, type: CloudIdeShared, decorators: [{
|
|
14
|
+
type: Component,
|
|
15
|
+
args: [{ selector: 'lib-cloud-ide-shared', imports: [], template: `
|
|
16
|
+
<p>
|
|
17
|
+
cloud-ide-shared works!
|
|
18
|
+
</p>
|
|
19
|
+
` }]
|
|
20
|
+
}] });
|
|
21
|
+
|
|
22
|
+
// Tokens for dependency injection
|
|
23
|
+
const AUTH_SERVICE_TOKEN = new InjectionToken('AuthService');
|
|
24
|
+
const APP_STATE_SERVICE_TOKEN = new InjectionToken('AppStateService');
|
|
25
|
+
|
|
26
|
+
const authGuard = (route, state) => {
|
|
27
|
+
const authService = inject(AUTH_SERVICE_TOKEN);
|
|
28
|
+
const appState = inject(APP_STATE_SERVICE_TOKEN);
|
|
29
|
+
const router = inject(Router);
|
|
30
|
+
// Refresh auth state to make sure it's current
|
|
31
|
+
authService.refreshAuthState();
|
|
32
|
+
// Refresh app state from localStorage to ensure synchronization
|
|
33
|
+
appState.refreshFromLocalStorage();
|
|
34
|
+
// Check if user is authenticated using app state (modern approach)
|
|
35
|
+
if (appState.isUserAuthenticated() && !authService.isTokenExpired()) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
// Redirect to login page with the intended destination
|
|
39
|
+
router.navigate(['/auth/sign-in'], {
|
|
40
|
+
queryParams: { returnUrl: state.url }
|
|
41
|
+
});
|
|
42
|
+
return false;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/*
|
|
46
|
+
* Public API Surface of cloud-ide-shared
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Generated bundle index. Do not edit.
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
export { APP_STATE_SERVICE_TOKEN, AUTH_SERVICE_TOKEN, CloudIdeShared, authGuard };
|
|
54
|
+
//# sourceMappingURL=cloud-ide-shared.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloud-ide-shared.mjs","sources":["../../../projects/cloud-ide-shared/src/lib/cloud-ide-shared.ts","../../../projects/cloud-ide-shared/src/lib/services/auth.service.interface.ts","../../../projects/cloud-ide-shared/src/lib/guards/auth.guard.ts","../../../projects/cloud-ide-shared/src/public-api.ts","../../../projects/cloud-ide-shared/src/cloud-ide-shared.ts"],"sourcesContent":["import { Component } from '@angular/core';\r\n\r\n@Component({\r\n selector: 'lib-cloud-ide-shared',\r\n imports: [],\r\n template: `\r\n <p>\r\n cloud-ide-shared works!\r\n </p>\r\n `,\r\n styles: ``\r\n})\r\nexport class CloudIdeShared {\r\n\r\n}\r\n","import { InjectionToken } from '@angular/core';\r\n\r\n// Interface for auth service to avoid circular dependency\r\nexport interface IAuthService {\r\n isAuthenticated(): boolean;\r\n isTokenExpired(): boolean;\r\n signOut(): void;\r\n refreshAuthState(): void;\r\n}\r\n\r\n// Interface for app state service to avoid circular dependency\r\nexport interface IAppStateService {\r\n isUserAuthenticated(): boolean;\r\n refreshFromLocalStorage(): void;\r\n}\r\n\r\n// Tokens for dependency injection\r\nexport const AUTH_SERVICE_TOKEN = new InjectionToken<IAuthService>('AuthService');\r\nexport const APP_STATE_SERVICE_TOKEN = new InjectionToken<IAppStateService>('AppStateService');\r\n","import { inject } from '@angular/core';\r\nimport { CanActivateFn, Router } from '@angular/router';\r\nimport { IAuthService, AUTH_SERVICE_TOKEN, IAppStateService, APP_STATE_SERVICE_TOKEN } from '../services/auth.service.interface';\r\n\r\nexport const authGuard: CanActivateFn = (route, state) => {\r\n const authService = inject(AUTH_SERVICE_TOKEN) as IAuthService;\r\n const appState = inject(APP_STATE_SERVICE_TOKEN) as IAppStateService;\r\n const router = inject(Router);\r\n \r\n // Refresh auth state to make sure it's current\r\n authService.refreshAuthState();\r\n \r\n // Refresh app state from localStorage to ensure synchronization\r\n appState.refreshFromLocalStorage();\r\n \r\n // Check if user is authenticated using app state (modern approach)\r\n if (appState.isUserAuthenticated() && !authService.isTokenExpired()) {\r\n return true;\r\n }\r\n \r\n // Redirect to login page with the intended destination\r\n router.navigate(['/auth/sign-in'], { \r\n queryParams: { returnUrl: state.url }\r\n });\r\n \r\n return false;\r\n};\r\n","/*\r\n * Public API Surface of cloud-ide-shared\r\n */\r\n\r\nexport * from './lib/cloud-ide-shared';\r\n\r\n// Guards\r\nexport * from './lib/guards/auth.guard';\r\n\r\n// Services\r\nexport * from './lib/services/auth.service.interface';","/**\n * Generated bundle index. Do not edit.\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AAC,GAAG;AACpC,KAAA,CAAC;AAEF,IAAA,OAAO,KAAK;AACd;;AC1BA;;AAEG;;ACFH;;AAEG;;;;"}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { InjectionToken } from '@angular/core';
|
|
3
|
+
import { CanActivateFn } from '@angular/router';
|
|
4
|
+
|
|
5
|
+
declare class CloudIdeShared {
|
|
6
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<CloudIdeShared, never>;
|
|
7
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<CloudIdeShared, "lib-cloud-ide-shared", never, {}, {}, never, never, true, never>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
declare const authGuard: CanActivateFn;
|
|
11
|
+
|
|
12
|
+
interface IAuthService {
|
|
13
|
+
isAuthenticated(): boolean;
|
|
14
|
+
isTokenExpired(): boolean;
|
|
15
|
+
signOut(): void;
|
|
16
|
+
refreshAuthState(): void;
|
|
17
|
+
}
|
|
18
|
+
interface IAppStateService {
|
|
19
|
+
isUserAuthenticated(): boolean;
|
|
20
|
+
refreshFromLocalStorage(): void;
|
|
21
|
+
}
|
|
22
|
+
declare const AUTH_SERVICE_TOKEN: InjectionToken<IAuthService>;
|
|
23
|
+
declare const APP_STATE_SERVICE_TOKEN: InjectionToken<IAppStateService>;
|
|
24
|
+
|
|
25
|
+
export { APP_STATE_SERVICE_TOKEN, AUTH_SERVICE_TOKEN, CloudIdeShared, authGuard };
|
|
26
|
+
export type { IAppStateService, IAuthService };
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cloud-ide-shared",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"peerDependencies": {
|
|
5
|
+
"@angular/common": "^20.1.0",
|
|
6
|
+
"@angular/core": "^20.1.0"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"tslib": "^2.3.0"
|
|
10
|
+
},
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"module": "fesm2022/cloud-ide-shared.mjs",
|
|
13
|
+
"typings": "index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
"./package.json": {
|
|
16
|
+
"default": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./index.d.ts",
|
|
20
|
+
"default": "./fesm2022/cloud-ide-shared.mjs"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|