@newgameplusinc/odyssey-sso 2.0.4 → 2.0.6

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.
Files changed (2) hide show
  1. package/README.md +165 -1
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1 +1,165 @@
1
- # Odyssey SSO SDK
1
+ # Odyssey SSO SDK
2
+
3
+ The **Odyssey SSO SDK** provides an easy way to integrate Single Sign-On (SSO) functionality, user profile management, and resource management (Cloths, Materials, Skulls) in your browser-based applications.
4
+
5
+ ---
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @newgameplusinc/odyssey-sso
11
+ ```
12
+
13
+ ---
14
+
15
+ ## Usage
16
+
17
+ ```ts
18
+ import SSO from "@newgameplusinc/odyssey-sso";
19
+
20
+ const sso = new SSO({
21
+ sdkKey: process.env.NEXT_PUBLIC_SDK_KEY,
22
+ debug: true,
23
+ });
24
+
25
+ // Login
26
+ sso.login("https://your-app.com/redirect");
27
+
28
+ // Exchange token from URL and get profile
29
+ const user = await sso.exchange();
30
+
31
+ // Fetch user profile
32
+ const profile = await sso.fetchProfile();
33
+
34
+ // Refresh token
35
+ const tokens = await sso.refresh();
36
+
37
+ // Logout
38
+ await sso.logout();
39
+
40
+ // Listen to SDK events
41
+ sso.onEvents((event) => {
42
+ console.log("SSO Event:", event);
43
+ });
44
+ ```
45
+
46
+ ---
47
+
48
+ ## SDK Configuration
49
+
50
+ | Field | Type | Description |
51
+ | -------- | ------- | ---------------------------- |
52
+ | `sdkKey` | string | Your SSO SDK key |
53
+ | `debug` | boolean | Enable debug logs (optional) |
54
+
55
+ ---
56
+
57
+ ## Methods
58
+
59
+ ### `login(redirectUrl: string): Promise<void>`
60
+
61
+ Redirects the user to the SSO login page.
62
+
63
+ * **Parameters:**
64
+
65
+ * `redirectUrl` — URL to redirect after login
66
+
67
+ ---
68
+
69
+ ### `exchange(): Promise<{ tokens; userData } | undefined>`
70
+
71
+ Exchanges the SSO token from the URL for access/refresh tokens and stores the profile locally.
72
+
73
+ * **Returns:** User profile + tokens or `undefined` if exchange fails
74
+
75
+ ---
76
+
77
+ ### `fetchProfile(): Promise<Profile | undefined>`
78
+
79
+ Fetches the user profile from the SSO server.
80
+
81
+ * **Returns:** Profile object
82
+
83
+ ---
84
+
85
+ ### `refresh(): Promise<{ accessToken: string; refreshToken: string } | undefined>`
86
+
87
+ Refreshes the access token using the stored refresh token.
88
+
89
+ * **Returns:** Updated tokens
90
+
91
+ ---
92
+
93
+ ### `logout(): Promise<boolean | undefined>`
94
+
95
+ Logs out the user from the SSO server and clears local storage.
96
+
97
+ * **Returns:** `true` on success
98
+
99
+ ---
100
+
101
+ ### `onEvents(cb: Cb)`
102
+
103
+ Subscribe to SDK events. Event types:
104
+
105
+ * `login` — user logged in
106
+ * `logout` — user logged out
107
+ * `refresh` — token refreshed
108
+ * `profile_fetch` — profile fetched
109
+ * `profile_update` — profile updated
110
+ * `profile_photo_update` — avatar updated
111
+ * `cloth_add/update/delete/fetch` — cloth operations
112
+ * `material_add/update/delete/fetch` — material operations
113
+ * `skull_add/update/delete/fetch` — skull operations
114
+
115
+ ---
116
+
117
+ ## Profile Management
118
+
119
+ ### `profileUpdate(payload: UpdateProfilePayload)`
120
+
121
+ Update user profile.
122
+
123
+ ### `avatarUpdate(file: File)`
124
+
125
+ Update user avatar by uploading a `File`.
126
+
127
+ ---
128
+
129
+ ## Cloth Management
130
+
131
+ * `clothAdd(payload: AddClothFilePayload)`
132
+ * `clothGetAll(options?: GetClothsOptions)`
133
+ * `clothGetById(clothId: string)`
134
+ * `clothUpdate(clothId: string, payload: UpdateClothPayload)`
135
+ * `clothDelete(clothId: string)`
136
+
137
+ All methods handle file uploads and token refresh automatically.
138
+
139
+ ---
140
+
141
+ ## Material Management
142
+
143
+ * `materialAdd(payload: AddMaterialFilePayload)`
144
+ * `materialGetAll(options?: GetMaterialsOptions)`
145
+ * `materialGetById(materialId: string)`
146
+ * `materialUpdate(materialId: string, payload: UpdateMaterialPayload)`
147
+ * `materialDelete(materialId: string)`
148
+
149
+ ---
150
+
151
+ ## Skull Management
152
+
153
+ * `skullAdd(payload: AddSkullFilePayload)`
154
+ * `skullGetAll()`
155
+ * `skullGetById(skullId: string)`
156
+ * `skullUpdate(skullId: string, payload: UpdateSkullPayload)`
157
+ * `skullDelete(skullId: string)`
158
+
159
+ ---
160
+
161
+ ## Notes
162
+
163
+ * This SDK is **browser-only**. All methods check for the browser environment.
164
+ * Uses a local database (`IndexedDB`) to store tokens and user profile for session persistence.
165
+ * Automatically handles token refresh for API requests.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newgameplusinc/odyssey-sso",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "SDK for SSO Service.",
5
5
  "type": "module",
6
6
  "browser": true,