@pipl-csui/sso-ui.js 0.0.0-stage → 0.0.1

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,132 @@
1
+ /**
2
+ * * `"1.0"`: `/validate`
3
+ * * `"2.0"`: `/serviceValidate`
4
+ * * `"3.0"`: `/p3/serviceValidate`
5
+ */
6
+ type CASVersion = "1.0" | "2.0" | "3.0";
7
+ /**
8
+ * the vocabulary for kd_org field
9
+ */
10
+ interface OrgDetails {
11
+ /** Faculty name in id. e.g. Fakultas Ilmu Komputer */
12
+ fakultas: string;
13
+ /** Faculty name in en. e.g. Faculty of Computer Science */
14
+ faculty: string;
15
+ /** Short name in id. e.g. Fasilkom, FT, FK; vernacular names */
16
+ fak: string;
17
+ /** Short name in en. e.g. CS, SCI; based on faculty homepage subdomain */
18
+ fac: string;
19
+ /** Department name in id, based on the faculty. e.g. Departemen Matematika */
20
+ departemen: string;
21
+ /** Department name in en, based on the faculty. e.g. Department of Mathematics */
22
+ department: string;
23
+ /** Department short name. e.g. DTE, MATH */
24
+ dep: string;
25
+ /** Major name in id. e.g. Sarjana Ilmu Komputer */
26
+ prodi: string;
27
+ /** Major name in en. e.g. Bachelor of Computer Science */
28
+ major: string;
29
+ /** Alias for {@linkcode prodi} */
30
+ studyProgram?: string;
31
+ /** jenjang */
32
+ educationalProgram?: string;
33
+ }
34
+ /**
35
+ * user but normalized
36
+ */
37
+ interface SSOUser {
38
+ /** SSO username */
39
+ username: string;
40
+ /** Full name */
41
+ name: string;
42
+ role: "mahasiswa" | "staff" | string;
43
+ /** NPM if {@linkcode role} is `"mahasiswa"` */
44
+ npm?: string;
45
+ /** NPM if {@linkcode role} is `"staff"` */
46
+ nip?: string;
47
+ /** Organization code; `kd_org` */
48
+ orgCode?: string;
49
+ organization?: OrgDetails;
50
+ /** Common name for LDAP */
51
+ ldapCn?: string;
52
+ /** Raw attributes */
53
+ rawAttributes: Record<string, string>;
54
+ }
55
+ interface SSOConfig {
56
+ /**
57
+ * base url
58
+ * @default "https://sso.ui.ac.id/cas2"
59
+ */
60
+ casUrl?: string;
61
+ /**
62
+ * @default "2.0"
63
+ */
64
+ version?: CASVersion;
65
+ /**
66
+ * callback url for your app
67
+ */
68
+ serviceUrl?: string;
69
+ /**
70
+ * @default 10000
71
+ */
72
+ timeoutMs?: number;
73
+ fetch?: typeof globalThis.fetch;
74
+ }
75
+ interface LoginUrlOptions {
76
+ /** URL to redirect after the login */
77
+ serviceUrl?: string;
78
+ renew?: boolean;
79
+ gateway?: boolean;
80
+ }
81
+ interface LogoutUrlOptions {
82
+ serviceUrl?: string;
83
+ url?: string;
84
+ }
85
+ interface ValidateTicketOptions {
86
+ serviceUrl?: string;
87
+ version?: CASVersion;
88
+ signal?: AbortSignal;
89
+ fetchOptions?: RequestInit;
90
+ }
91
+ type res = {
92
+ success: true;
93
+ user: SSOUser;
94
+ error?: never;
95
+ } | {
96
+ success: false;
97
+ user?: never;
98
+ error: Error;
99
+ };
100
+
101
+ declare const DEFAULT_CAS_URL = "https://sso.ui.ac.id/cas2";
102
+ declare function normalize(url?: string): string;
103
+ declare function LoginURL(casUrl: string, serviceUrl?: string, options?: LoginUrlOptions): string;
104
+ declare function LogoutURL(casUrl: string, options?: LogoutUrlOptions): string;
105
+ declare function ValidateURL(casUrl: string, serviceUrl: string, ticket: string, version?: CASVersion): string;
106
+
107
+ interface RawOrgEntry {
108
+ faculty: string;
109
+ shortFaculty: string;
110
+ major: string;
111
+ program: string;
112
+ }
113
+ declare const ORG_CODES: Record<string, RawOrgEntry>;
114
+
115
+ declare function lookupOrgCode(code?: string): OrgDetails | undefined;
116
+
117
+ declare function parseResponse(body: string, version?: CASVersion): SSOUser;
118
+ declare class SSO {
119
+ casUrl: string;
120
+ serviceUrl?: string;
121
+ version: CASVersion;
122
+ timeoutMs: number;
123
+ fetchFn: typeof globalThis.fetch;
124
+ constructor(config?: SSOConfig);
125
+ loginUrl(serviceUrl?: string, options?: LoginUrlOptions): string;
126
+ logoutUrl(options?: LogoutUrlOptions | string): string;
127
+ validate(ticket: string, options?: ValidateTicketOptions | string): Promise<SSOUser>;
128
+ validateSafe(ticket: string, options?: ValidateTicketOptions | string): Promise<res>;
129
+ }
130
+
131
+ export { DEFAULT_CAS_URL, LoginURL, LogoutURL, ORG_CODES, SSO, ValidateURL, SSO as default, lookupOrgCode, normalize, parseResponse };
132
+ export type { CASVersion, LoginUrlOptions, LogoutUrlOptions, OrgDetails, RawOrgEntry, SSOConfig, SSOUser, ValidateTicketOptions, res };
@@ -0,0 +1,132 @@
1
+ /**
2
+ * * `"1.0"`: `/validate`
3
+ * * `"2.0"`: `/serviceValidate`
4
+ * * `"3.0"`: `/p3/serviceValidate`
5
+ */
6
+ type CASVersion = "1.0" | "2.0" | "3.0";
7
+ /**
8
+ * the vocabulary for kd_org field
9
+ */
10
+ interface OrgDetails {
11
+ /** Faculty name in id. e.g. Fakultas Ilmu Komputer */
12
+ fakultas: string;
13
+ /** Faculty name in en. e.g. Faculty of Computer Science */
14
+ faculty: string;
15
+ /** Short name in id. e.g. Fasilkom, FT, FK; vernacular names */
16
+ fak: string;
17
+ /** Short name in en. e.g. CS, SCI; based on faculty homepage subdomain */
18
+ fac: string;
19
+ /** Department name in id, based on the faculty. e.g. Departemen Matematika */
20
+ departemen: string;
21
+ /** Department name in en, based on the faculty. e.g. Department of Mathematics */
22
+ department: string;
23
+ /** Department short name. e.g. DTE, MATH */
24
+ dep: string;
25
+ /** Major name in id. e.g. Sarjana Ilmu Komputer */
26
+ prodi: string;
27
+ /** Major name in en. e.g. Bachelor of Computer Science */
28
+ major: string;
29
+ /** Alias for {@linkcode prodi} */
30
+ studyProgram?: string;
31
+ /** jenjang */
32
+ educationalProgram?: string;
33
+ }
34
+ /**
35
+ * user but normalized
36
+ */
37
+ interface SSOUser {
38
+ /** SSO username */
39
+ username: string;
40
+ /** Full name */
41
+ name: string;
42
+ role: "mahasiswa" | "staff" | string;
43
+ /** NPM if {@linkcode role} is `"mahasiswa"` */
44
+ npm?: string;
45
+ /** NPM if {@linkcode role} is `"staff"` */
46
+ nip?: string;
47
+ /** Organization code; `kd_org` */
48
+ orgCode?: string;
49
+ organization?: OrgDetails;
50
+ /** Common name for LDAP */
51
+ ldapCn?: string;
52
+ /** Raw attributes */
53
+ rawAttributes: Record<string, string>;
54
+ }
55
+ interface SSOConfig {
56
+ /**
57
+ * base url
58
+ * @default "https://sso.ui.ac.id/cas2"
59
+ */
60
+ casUrl?: string;
61
+ /**
62
+ * @default "2.0"
63
+ */
64
+ version?: CASVersion;
65
+ /**
66
+ * callback url for your app
67
+ */
68
+ serviceUrl?: string;
69
+ /**
70
+ * @default 10000
71
+ */
72
+ timeoutMs?: number;
73
+ fetch?: typeof globalThis.fetch;
74
+ }
75
+ interface LoginUrlOptions {
76
+ /** URL to redirect after the login */
77
+ serviceUrl?: string;
78
+ renew?: boolean;
79
+ gateway?: boolean;
80
+ }
81
+ interface LogoutUrlOptions {
82
+ serviceUrl?: string;
83
+ url?: string;
84
+ }
85
+ interface ValidateTicketOptions {
86
+ serviceUrl?: string;
87
+ version?: CASVersion;
88
+ signal?: AbortSignal;
89
+ fetchOptions?: RequestInit;
90
+ }
91
+ type res = {
92
+ success: true;
93
+ user: SSOUser;
94
+ error?: never;
95
+ } | {
96
+ success: false;
97
+ user?: never;
98
+ error: Error;
99
+ };
100
+
101
+ declare const DEFAULT_CAS_URL = "https://sso.ui.ac.id/cas2";
102
+ declare function normalize(url?: string): string;
103
+ declare function LoginURL(casUrl: string, serviceUrl?: string, options?: LoginUrlOptions): string;
104
+ declare function LogoutURL(casUrl: string, options?: LogoutUrlOptions): string;
105
+ declare function ValidateURL(casUrl: string, serviceUrl: string, ticket: string, version?: CASVersion): string;
106
+
107
+ interface RawOrgEntry {
108
+ faculty: string;
109
+ shortFaculty: string;
110
+ major: string;
111
+ program: string;
112
+ }
113
+ declare const ORG_CODES: Record<string, RawOrgEntry>;
114
+
115
+ declare function lookupOrgCode(code?: string): OrgDetails | undefined;
116
+
117
+ declare function parseResponse(body: string, version?: CASVersion): SSOUser;
118
+ declare class SSO {
119
+ casUrl: string;
120
+ serviceUrl?: string;
121
+ version: CASVersion;
122
+ timeoutMs: number;
123
+ fetchFn: typeof globalThis.fetch;
124
+ constructor(config?: SSOConfig);
125
+ loginUrl(serviceUrl?: string, options?: LoginUrlOptions): string;
126
+ logoutUrl(options?: LogoutUrlOptions | string): string;
127
+ validate(ticket: string, options?: ValidateTicketOptions | string): Promise<SSOUser>;
128
+ validateSafe(ticket: string, options?: ValidateTicketOptions | string): Promise<res>;
129
+ }
130
+
131
+ export { DEFAULT_CAS_URL, LoginURL, LogoutURL, ORG_CODES, SSO, ValidateURL, SSO as default, lookupOrgCode, normalize, parseResponse };
132
+ export type { CASVersion, LoginUrlOptions, LogoutUrlOptions, OrgDetails, RawOrgEntry, SSOConfig, SSOUser, ValidateTicketOptions, res };