@newgameplusinc/odyssey-sso 2.0.4 → 2.0.5

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