@arinova-ai/spaces-sdk 0.1.0 → 0.1.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 CHANGED
@@ -1,94 +1,91 @@
1
- # @arinova-ai/spaces-sdk
1
+ # @arinova/spaces-sdk
2
2
 
3
- Official SDK for integrating external games with the Arinova platform.
3
+ OAuth PKCE SDK for Arinova Spaces authenticate users without exposing secrets.
4
4
 
5
- ## Install
5
+ ## Installation
6
6
 
7
7
  ```bash
8
- npm install @arinova-ai/spaces-sdk
8
+ npm install @arinova/spaces-sdk
9
9
  ```
10
10
 
11
11
  ## Quick Start
12
12
 
13
- ### 1. Initialize
13
+ ```js
14
+ import { Arinova } from "@arinova/spaces-sdk";
14
15
 
15
- ```typescript
16
- import { Arinova } from "@arinova-ai/spaces-sdk";
16
+ const arinova = new Arinova({ appId: "your-client-id" });
17
17
 
18
- Arinova.init({
19
- appId: "your-client-id",
20
- baseUrl: "https://api.arinova.ai", // optional, defaults to production
21
- });
18
+ // Trigger login (opens popup)
19
+ const token = await arinova.login();
20
+ console.log(token.user.name); // "Alice"
21
+ console.log(token.access_token); // Bearer token for API calls
22
22
  ```
23
23
 
24
- ### 2. Login (Frontend)
24
+ ## Setup
25
25
 
26
- ```typescript
27
- // Redirect to Arinova login
28
- Arinova.login({ scope: ["profile", "agents"] });
26
+ 1. Register your app: `arinova-cli app create --name "My App" --redirect-uri "https://myapp.com"`
27
+ 2. Copy the `Client ID` from the output
28
+ 3. No `client_secret` needed — all apps use PKCE
29
29
 
30
- // Handle callback (on your redirect page)
31
- const { user, accessToken } = await Arinova.handleCallback({
32
- code: urlParams.get("code"),
33
- clientId: "your-client-id",
34
- clientSecret: "your-client-secret",
35
- redirectUri: window.location.origin + "/callback",
36
- });
37
- ```
30
+ ## API
38
31
 
39
- ### 3. Use Agent API
32
+ ### `new Arinova(config)`
40
33
 
41
- ```typescript
42
- // Get user's agents
43
- const agents = await Arinova.user.agents(accessToken);
34
+ | Option | Type | Default | Description |
35
+ |--------|------|---------|-------------|
36
+ | `appId` | `string` | *required* | Your OAuth app client_id |
37
+ | `endpoint` | `string` | `https://chat.arinova.ai` | Arinova server URL |
38
+ | `redirectUri` | `string` | `{origin}/callback` | OAuth callback URL |
39
+ | `scope` | `string` | `"profile"` | OAuth scope |
44
40
 
45
- // Chat with agent (sync)
46
- const { response } = await Arinova.agent.chat({
47
- agentId: agents[0].id,
48
- prompt: "Your board state...",
49
- accessToken,
50
- });
41
+ ### `arinova.login(): Promise<TokenResponse>`
51
42
 
52
- // Chat with agent (streaming)
53
- const result = await Arinova.agent.chatStream({
54
- agentId: agents[0].id,
55
- prompt: "Your move?",
56
- accessToken,
57
- onChunk: (chunk) => console.log("Streaming:", chunk),
58
- });
43
+ Opens a popup for user authorization (PKCE flow). Returns:
44
+
45
+ ```ts
46
+ {
47
+ access_token: string;
48
+ token_type: "Bearer";
49
+ expires_in: 604800; // 7 days
50
+ scope: "profile";
51
+ user: { id, name, email, image };
52
+ }
59
53
  ```
60
54
 
61
- ### 4. Economy (Server-to-Server)
55
+ ### `arinova.handleCallback(): Promise<TokenResponse>`
56
+
57
+ Call on your redirect_uri page to complete the flow (for redirect mode instead of popup).
58
+
59
+ ## PKCE Flow
62
60
 
63
- ```typescript
64
- // Charge coins
65
- const { newBalance } = await Arinova.economy.charge({
66
- userId: "user-id",
67
- amount: 10,
68
- description: "Game entry fee",
69
- clientId: "your-client-id",
70
- clientSecret: "your-client-secret",
61
+ 1. SDK generates `code_verifier` (random) and `code_challenge = BASE64URL(SHA256(code_verifier))`
62
+ 2. User is redirected to Arinova with `code_challenge`
63
+ 3. After authorization, Arinova redirects back with `code`
64
+ 4. SDK exchanges `code` + `code_verifier` for `access_token` (no secret needed)
65
+
66
+ ## redirect_uri Rules
67
+
68
+ - Origin match: scheme + host + port must match your registered URI
69
+ - Path can differ (SDK uses `window.location.origin + /callback` by default)
70
+ - Must use HTTPS in production
71
+ - `http://localhost` is allowed for development
72
+
73
+ ## Example: Redirect Mode
74
+
75
+ If popups are blocked, use redirect mode:
76
+
77
+ ```js
78
+ // On login page:
79
+ const arinova = new Arinova({
80
+ appId: "your-client-id",
81
+ redirectUri: "https://myapp.com/auth/callback",
71
82
  });
83
+ arinova.login(); // Will redirect if popup is blocked
72
84
 
73
- // Award coins
74
- const { newBalance, platformFee } = await Arinova.economy.award({
75
- userId: "user-id",
76
- amount: 20,
77
- description: "Game prize",
78
- clientId: "your-client-id",
79
- clientSecret: "your-client-secret",
85
+ // On callback page (/auth/callback):
86
+ const arinova = new Arinova({
87
+ appId: "your-client-id",
88
+ redirectUri: "https://myapp.com/auth/callback",
80
89
  });
90
+ const token = await arinova.handleCallback();
81
91
  ```
82
-
83
- ## API Reference
84
-
85
- ### `Arinova.init(config)`
86
- ### `Arinova.login(options?)`
87
- ### `Arinova.handleCallback(params)`
88
- ### `Arinova.user.profile(accessToken)`
89
- ### `Arinova.user.agents(accessToken)`
90
- ### `Arinova.agent.chat(options)`
91
- ### `Arinova.agent.chatStream(options)`
92
- ### `Arinova.economy.charge(options)`
93
- ### `Arinova.economy.award(options)`
94
- ### `Arinova.economy.balance(accessToken)`
package/dist/index.d.ts CHANGED
@@ -1,70 +1,52 @@
1
- import type { ArinovaConfig, LoginOptions, LoginResult, ArinovaUser, AgentInfo, AgentChatOptions, AgentChatResponse, AgentChatStreamOptions, AgentChatStreamResponse, ChargeOptions, ChargeResponse, AwardOptions, AwardResponse, BalanceResponse } from "./types.js";
2
- export type * from "./types.js";
3
- export declare const Arinova: {
4
- /**
5
- * Initialize the SDK with your app configuration.
6
- */
7
- init(config: ArinovaConfig & {
8
- clientId?: string;
9
- clientSecret?: string;
10
- }): void;
1
+ /**
2
+ * Arinova Spaces SDK
3
+ *
4
+ * Public client OAuth with PKCE — no client_secret needed.
5
+ *
6
+ * Usage:
7
+ * const arinova = new Arinova({ appId: "my-app-abc123" });
8
+ * const token = await arinova.login();
9
+ * // token.access_token is ready to use
10
+ */
11
+ export interface ArinovaConfig {
12
+ /** Your OAuth app's client_id (from Developer Console) */
13
+ appId: string;
14
+ /** Arinova server URL (default: https://chat.arinova.ai) */
15
+ endpoint?: string;
16
+ /** OAuth redirect URI (default: current page origin + /callback) */
17
+ redirectUri?: string;
18
+ /** OAuth scope (default: "profile") */
19
+ scope?: string;
20
+ }
21
+ export interface TokenResponse {
22
+ access_token: string;
23
+ token_type: string;
24
+ expires_in: number;
25
+ scope: string;
26
+ user: {
27
+ id: string;
28
+ name: string;
29
+ email: string;
30
+ image: string | null;
31
+ };
32
+ }
33
+ export declare class Arinova {
34
+ private appId;
35
+ private endpoint;
36
+ private redirectUri;
37
+ private scope;
38
+ constructor(config: ArinovaConfig);
11
39
  /**
12
- * Redirect to Arinova OAuth login page.
13
- * Call this from your game's frontend.
40
+ * Start the OAuth PKCE login flow.
41
+ * Opens a popup window for authorization.
42
+ * Returns the token response on success.
14
43
  */
15
- login(options?: LoginOptions): void;
44
+ login(): Promise<TokenResponse>;
16
45
  /**
17
- * Handle the OAuth callback. Call this on your redirect page.
18
- * Exchanges the authorization code for an access token.
46
+ * Handle the OAuth callback (call this on your redirect_uri page).
47
+ * Reads code and state from URL, exchanges for token.
19
48
  */
20
- handleCallback(params: {
21
- code: string;
22
- clientId: string;
23
- clientSecret: string;
24
- redirectUri: string;
25
- }): Promise<LoginResult>;
26
- user: {
27
- /**
28
- * Get the authenticated user's profile.
29
- */
30
- profile(accessToken: string): Promise<ArinovaUser>;
31
- /**
32
- * Get the authenticated user's agents.
33
- * Requires "agents" scope.
34
- */
35
- agents(accessToken: string): Promise<AgentInfo[]>;
36
- };
37
- agent: {
38
- /**
39
- * Send a prompt to a user's agent and get a complete response.
40
- */
41
- chat(options: AgentChatOptions): Promise<AgentChatResponse>;
42
- /**
43
- * Send a prompt to a user's agent and receive a streaming response via SSE.
44
- */
45
- chatStream(options: AgentChatStreamOptions): Promise<AgentChatStreamResponse>;
46
- };
47
- economy: {
48
- /**
49
- * Charge coins from a user's balance (server-to-server).
50
- * Requires clientId and clientSecret.
51
- */
52
- charge(options: ChargeOptions & {
53
- clientId: string;
54
- clientSecret: string;
55
- }): Promise<ChargeResponse>;
56
- /**
57
- * Award coins to a user (server-to-server).
58
- * Requires clientId and clientSecret.
59
- */
60
- award(options: AwardOptions & {
61
- clientId: string;
62
- clientSecret: string;
63
- }): Promise<AwardResponse>;
64
- /**
65
- * Get a user's coin balance (uses OAuth access token).
66
- */
67
- balance(accessToken: string): Promise<BalanceResponse>;
68
- };
69
- };
70
- //# sourceMappingURL=index.d.ts.map
49
+ handleCallback(): Promise<TokenResponse>;
50
+ private exchangeCode;
51
+ }
52
+ export default Arinova;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EACZ,WAAW,EACX,WAAW,EACX,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACtB,uBAAuB,EACvB,aAAa,EACb,cAAc,EACd,YAAY,EACZ,aAAa,EACb,eAAe,EAEhB,MAAM,YAAY,CAAC;AAEpB,mBAAmB,YAAY,CAAC;AAehC,eAAO,MAAM,OAAO;IAClB;;OAEG;iBACU,aAAa,GAAG;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE;IAOzE;;;OAGG;oBACa,YAAY,GAAG,IAAI;IAkBnC;;;OAGG;2BAC0B;QAC3B,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,YAAY,EAAE,MAAM,CAAC;QACrB,WAAW,EAAE,MAAM,CAAC;KACrB,GAAG,OAAO,CAAC,WAAW,CAAC;;QA4BtB;;WAEG;6BACwB,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;QASxD;;;WAGG;4BACuB,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;;;QAYvD;;WAEG;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AAM,GAAG,OAAO,CAAC,WAAW,CAAC;QASxD;;;WAGG;4BACuB,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;;;QAYvD;;WAEG;sBACiB,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;QAuBjE;;WAEG;4BACuB,sBAAsB,GAAG,OAAO,CAAC,uBAAuB,CAAC;;;QAwDnF;;;WAGG;wBACmB,aAAa,GAAG;YAAE,QAAQ,EAAE,MAAM,CAAC;YAAC,YAAY,EAAE,MAAM,CAAA;SAAE,GAAG,OAAO,CAAC,cAAc,CAAC;QAwB1G;;;WAGG;uBACkB,YAAY,GAAG;YAAE,QAAQ,EAAE,MAAM,CAAC;YAAC,YAAY,EAAE,MAAM,CAAA;SAAE,GAAG,OAAO,CAAC,aAAa,CAAC;QAwBvG;;WAEG;6BACwB,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;;CAU/D,CAAC"}
package/dist/index.js CHANGED
@@ -1,242 +1,153 @@
1
- let _config = null;
2
- let _oauthClientInfo = null;
3
- function getBaseUrl() {
4
- if (!_config)
5
- throw new Error("Arinova SDK not initialized. Call Arinova.init() first.");
6
- return _config.baseUrl || "https://api.arinova.ai";
7
- }
8
- function getConfig() {
9
- if (!_config)
10
- throw new Error("Arinova SDK not initialized. Call Arinova.init() first.");
11
- return _config;
12
- }
13
- export const Arinova = {
14
- /**
15
- * Initialize the SDK with your app configuration.
16
- */
17
- init(config) {
18
- _config = config;
19
- if (config.clientId && config.clientSecret) {
20
- _oauthClientInfo = { clientId: config.clientId, clientSecret: config.clientSecret };
21
- }
22
- },
1
+ /**
2
+ * Arinova Spaces SDK
3
+ *
4
+ * Public client OAuth with PKCE — no client_secret needed.
5
+ *
6
+ * Usage:
7
+ * const arinova = new Arinova({ appId: "my-app-abc123" });
8
+ * const token = await arinova.login();
9
+ * // token.access_token is ready to use
10
+ */
11
+ export class Arinova {
12
+ constructor(config) {
13
+ this.appId = config.appId;
14
+ this.endpoint = (config.endpoint ?? "https://chat.arinova.ai").replace(/\/+$/, "");
15
+ this.redirectUri =
16
+ config.redirectUri ?? `${window.location.origin}/callback`;
17
+ this.scope = config.scope ?? "profile";
18
+ }
23
19
  /**
24
- * Redirect to Arinova OAuth login page.
25
- * Call this from your game's frontend.
20
+ * Start the OAuth PKCE login flow.
21
+ * Opens a popup window for authorization.
22
+ * Returns the token response on success.
26
23
  */
27
- login(options) {
28
- const config = getConfig();
29
- const baseUrl = getBaseUrl();
30
- const scope = options?.scope?.join(" ") || "profile";
31
- // Store current URL for callback
32
- const currentUrl = typeof window !== "undefined" ? window.location.href : "";
24
+ async login() {
25
+ const { verifier, challenge } = await generatePKCE();
26
+ const state = generateRandom(32);
27
+ // Store state + verifier for callback validation
28
+ sessionStorage.setItem("arinova_pkce_verifier", verifier);
29
+ sessionStorage.setItem("arinova_pkce_state", state);
33
30
  const params = new URLSearchParams({
34
- client_id: config.appId,
35
- redirect_uri: currentUrl,
36
- scope,
37
- state: crypto.randomUUID(),
31
+ client_id: this.appId,
32
+ redirect_uri: this.redirectUri,
33
+ scope: this.scope,
34
+ state,
35
+ code_challenge: challenge,
36
+ code_challenge_method: "S256",
37
+ response_type: "code",
38
+ });
39
+ const authUrl = `${this.endpoint}/oauth/authorize?${params}`;
40
+ return new Promise((resolve, reject) => {
41
+ const popup = window.open(authUrl, "arinova_auth", "width=500,height=600");
42
+ if (!popup) {
43
+ // Fallback: redirect instead of popup
44
+ window.location.href = authUrl;
45
+ reject(new Error("Popup blocked — redirecting instead"));
46
+ return;
47
+ }
48
+ const interval = setInterval(() => {
49
+ try {
50
+ if (popup.closed) {
51
+ clearInterval(interval);
52
+ reject(new Error("Login cancelled"));
53
+ }
54
+ const popupUrl = popup.location.href;
55
+ if (popupUrl.startsWith(this.redirectUri)) {
56
+ clearInterval(interval);
57
+ popup.close();
58
+ const url = new URL(popupUrl);
59
+ const code = url.searchParams.get("code");
60
+ const returnedState = url.searchParams.get("state");
61
+ if (returnedState !== state) {
62
+ reject(new Error("State mismatch — possible CSRF attack"));
63
+ return;
64
+ }
65
+ if (!code) {
66
+ reject(new Error(url.searchParams.get("error_description") ?? "No code received"));
67
+ return;
68
+ }
69
+ this.exchangeCode(code, verifier).then(resolve).catch(reject);
70
+ }
71
+ }
72
+ catch {
73
+ // Cross-origin — popup is on a different domain, ignore
74
+ }
75
+ }, 200);
76
+ // Timeout after 5 minutes
77
+ setTimeout(() => {
78
+ clearInterval(interval);
79
+ try {
80
+ popup.close();
81
+ }
82
+ catch { /* ignore */ }
83
+ reject(new Error("Login timed out"));
84
+ }, 300000);
38
85
  });
39
- window.location.href = `${baseUrl}/oauth/authorize?${params}`;
40
- },
86
+ }
41
87
  /**
42
- * Handle the OAuth callback. Call this on your redirect page.
43
- * Exchanges the authorization code for an access token.
88
+ * Handle the OAuth callback (call this on your redirect_uri page).
89
+ * Reads code and state from URL, exchanges for token.
44
90
  */
45
- async handleCallback(params) {
46
- const baseUrl = getBaseUrl();
47
- const res = await fetch(`${baseUrl}/oauth/token`, {
91
+ async handleCallback() {
92
+ const url = new URL(window.location.href);
93
+ const code = url.searchParams.get("code");
94
+ const state = url.searchParams.get("state");
95
+ const verifier = sessionStorage.getItem("arinova_pkce_verifier");
96
+ const expectedState = sessionStorage.getItem("arinova_pkce_state");
97
+ sessionStorage.removeItem("arinova_pkce_verifier");
98
+ sessionStorage.removeItem("arinova_pkce_state");
99
+ if (!code) {
100
+ throw new Error(url.searchParams.get("error_description") ?? "No authorization code");
101
+ }
102
+ if (state !== expectedState) {
103
+ throw new Error("State mismatch");
104
+ }
105
+ if (!verifier) {
106
+ throw new Error("No PKCE verifier found — did you start login()?");
107
+ }
108
+ return this.exchangeCode(code, verifier);
109
+ }
110
+ async exchangeCode(code, codeVerifier) {
111
+ const res = await fetch(`${this.endpoint}/oauth/token`, {
48
112
  method: "POST",
49
113
  headers: { "Content-Type": "application/json" },
50
114
  body: JSON.stringify({
51
115
  grant_type: "authorization_code",
52
- code: params.code,
53
- client_id: params.clientId,
54
- client_secret: params.clientSecret,
55
- redirect_uri: params.redirectUri,
116
+ client_id: this.appId,
117
+ code,
118
+ redirect_uri: this.redirectUri,
119
+ code_verifier: codeVerifier,
56
120
  }),
57
121
  });
58
122
  if (!res.ok) {
59
- const error = await res.json().catch(() => ({ error: "token_exchange_failed" }));
60
- throw new Error(error.error || "Token exchange failed");
123
+ const body = await res.json().catch(() => ({}));
124
+ throw new Error(body.error_description ??
125
+ body.error ??
126
+ `Token exchange failed (${res.status})`);
61
127
  }
62
- const data = await res.json();
63
- return {
64
- user: data.user,
65
- accessToken: data.access_token,
66
- };
67
- },
68
- user: {
69
- /**
70
- * Get the authenticated user's profile.
71
- */
72
- async profile(accessToken) {
73
- const baseUrl = getBaseUrl();
74
- const res = await fetch(`${baseUrl}/api/v1/user/profile`, {
75
- headers: { Authorization: `Bearer ${accessToken}` },
76
- });
77
- if (!res.ok)
78
- throw new Error("Failed to get user profile");
79
- return res.json();
80
- },
81
- /**
82
- * Get the authenticated user's agents.
83
- * Requires "agents" scope.
84
- */
85
- async agents(accessToken) {
86
- const baseUrl = getBaseUrl();
87
- const res = await fetch(`${baseUrl}/api/v1/user/agents`, {
88
- headers: { Authorization: `Bearer ${accessToken}` },
89
- });
90
- if (!res.ok)
91
- throw new Error("Failed to get user agents");
92
- const data = await res.json();
93
- return data.agents;
94
- },
95
- },
96
- agent: {
97
- /**
98
- * Send a prompt to a user's agent and get a complete response.
99
- */
100
- async chat(options) {
101
- const baseUrl = getBaseUrl();
102
- const res = await fetch(`${baseUrl}/api/v1/agent/chat`, {
103
- method: "POST",
104
- headers: {
105
- "Content-Type": "application/json",
106
- Authorization: `Bearer ${options.accessToken}`,
107
- },
108
- body: JSON.stringify({
109
- agentId: options.agentId,
110
- prompt: options.prompt,
111
- systemPrompt: options.systemPrompt,
112
- }),
113
- });
114
- if (!res.ok) {
115
- const error = await res.json().catch(() => ({ error: "agent_chat_failed" }));
116
- throw new Error(error.error || "Agent chat failed");
117
- }
118
- return res.json();
119
- },
120
- /**
121
- * Send a prompt to a user's agent and receive a streaming response via SSE.
122
- */
123
- async chatStream(options) {
124
- const baseUrl = getBaseUrl();
125
- const res = await fetch(`${baseUrl}/api/v1/agent/chat/stream`, {
126
- method: "POST",
127
- headers: {
128
- "Content-Type": "application/json",
129
- Authorization: `Bearer ${options.accessToken}`,
130
- },
131
- body: JSON.stringify({
132
- agentId: options.agentId,
133
- prompt: options.prompt,
134
- systemPrompt: options.systemPrompt,
135
- }),
136
- });
137
- if (!res.ok) {
138
- const error = await res.json().catch(() => ({ error: "agent_stream_failed" }));
139
- throw new Error(error.error || "Agent stream failed");
140
- }
141
- const reader = res.body.getReader();
142
- const decoder = new TextDecoder();
143
- let fullContent = "";
144
- let buffer = "";
145
- while (true) {
146
- const { done, value } = await reader.read();
147
- if (done)
148
- break;
149
- buffer += decoder.decode(value, { stream: true });
150
- const lines = buffer.split("\n");
151
- buffer = lines.pop() || "";
152
- for (const line of lines) {
153
- if (!line.startsWith("data: "))
154
- continue;
155
- try {
156
- const event = JSON.parse(line.slice(6));
157
- if (event.type === "chunk") {
158
- options.onChunk(event.content);
159
- fullContent = event.content;
160
- }
161
- else if (event.type === "done") {
162
- fullContent = event.content;
163
- }
164
- else if (event.type === "error") {
165
- throw new Error(event.error);
166
- }
167
- }
168
- catch (e) {
169
- if (e instanceof Error && e.message !== "Unexpected end of JSON input")
170
- throw e;
171
- }
172
- }
173
- }
174
- return { content: fullContent, agentId: options.agentId };
175
- },
176
- },
177
- economy: {
178
- /**
179
- * Charge coins from a user's balance (server-to-server).
180
- * Requires clientId and clientSecret.
181
- */
182
- async charge(options) {
183
- const baseUrl = getBaseUrl();
184
- const res = await fetch(`${baseUrl}/api/v1/economy/charge`, {
185
- method: "POST",
186
- headers: {
187
- "Content-Type": "application/json",
188
- "X-Client-Id": options.clientId,
189
- "X-App-Secret": options.clientSecret,
190
- },
191
- body: JSON.stringify({
192
- userId: options.userId,
193
- amount: options.amount,
194
- description: options.description,
195
- }),
196
- });
197
- if (!res.ok) {
198
- const error = await res.json().catch(() => ({ error: "charge_failed" }));
199
- throw new Error(error.error || "Charge failed");
200
- }
201
- return res.json();
202
- },
203
- /**
204
- * Award coins to a user (server-to-server).
205
- * Requires clientId and clientSecret.
206
- */
207
- async award(options) {
208
- const baseUrl = getBaseUrl();
209
- const res = await fetch(`${baseUrl}/api/v1/economy/award`, {
210
- method: "POST",
211
- headers: {
212
- "Content-Type": "application/json",
213
- "X-Client-Id": options.clientId,
214
- "X-App-Secret": options.clientSecret,
215
- },
216
- body: JSON.stringify({
217
- userId: options.userId,
218
- amount: options.amount,
219
- description: options.description,
220
- }),
221
- });
222
- if (!res.ok) {
223
- const error = await res.json().catch(() => ({ error: "award_failed" }));
224
- throw new Error(error.error || "Award failed");
225
- }
226
- return res.json();
227
- },
228
- /**
229
- * Get a user's coin balance (uses OAuth access token).
230
- */
231
- async balance(accessToken) {
232
- const baseUrl = getBaseUrl();
233
- const res = await fetch(`${baseUrl}/api/v1/economy/balance`, {
234
- headers: { Authorization: `Bearer ${accessToken}` },
235
- });
236
- if (!res.ok)
237
- throw new Error("Failed to get balance");
238
- return res.json();
239
- },
240
- },
241
- };
242
- //# sourceMappingURL=index.js.map
128
+ return res.json();
129
+ }
130
+ }
131
+ // ── PKCE Helpers ──────────────────────────────────────────────
132
+ function generateRandom(length) {
133
+ const array = new Uint8Array(length);
134
+ crypto.getRandomValues(array);
135
+ return Array.from(array, (b) => b.toString(16).padStart(2, "0")).join("");
136
+ }
137
+ async function generatePKCE() {
138
+ const verifier = generateRandom(32); // 64 hex chars
139
+ const encoder = new TextEncoder();
140
+ const data = encoder.encode(verifier);
141
+ const hash = await crypto.subtle.digest("SHA-256", data);
142
+ const challenge = base64UrlEncode(new Uint8Array(hash));
143
+ return { verifier, challenge };
144
+ }
145
+ function base64UrlEncode(buffer) {
146
+ let binary = "";
147
+ for (const byte of buffer) {
148
+ binary += String.fromCharCode(byte);
149
+ }
150
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
151
+ }
152
+ // Default export for convenience
153
+ export default Arinova;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAoBA,IAAI,OAAO,GAAyB,IAAI,CAAC;AACzC,IAAI,gBAAgB,GAAsD,IAAI,CAAC;AAE/E,SAAS,UAAU;IACjB,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IACzF,OAAO,OAAO,CAAC,OAAO,IAAI,wBAAwB,CAAC;AACrD,CAAC;AAED,SAAS,SAAS;IAChB,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IACzF,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB;;OAEG;IACH,IAAI,CAAC,MAAoE;QACvE,OAAO,GAAG,MAAM,CAAC;QACjB,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;YAC3C,gBAAgB,GAAG,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,CAAC,YAAY,EAAE,CAAC;QACtF,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,OAAsB;QAC1B,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;QAC3B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;QAC7B,MAAM,KAAK,GAAG,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC;QAErD,iCAAiC;QACjC,MAAM,UAAU,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QAE7E,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC;YACjC,SAAS,E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;oBACtB,MAAM,EAAE,OAAO,CAAC,MAAM;oBACtB,WAAW,EAAE,OAAO,CAAC,WAAW;iBACjC,CAAC;aACH,CAAC,CAAC;YAEH,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;gBACZ,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC;gBACxE,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,cAAc,CAAC,CAAC;YACjD,CAAC;YAED,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC;QACpB,CAAC;QAED;;WAEG;QACH,KAAK,CAAC,OAAO,CAAC,WAAmB;YAC/B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;YAC7B,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,OAAO,yBAAyB,EAAE;gBAC3D,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE;aACpD,CAAC,CAAC;YAEH,IAAI,CAAC,GAAG,CAAC,EAAE;gBAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;YACtD,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC;QACpB,CAAC;KACF;CACF,CAAC"}
package/dist/types.d.ts CHANGED
@@ -9,6 +9,14 @@ export interface LoginResult {
9
9
  user: ArinovaUser;
10
10
  accessToken: string;
11
11
  }
12
+ export interface ConnectOptions {
13
+ timeout?: number;
14
+ }
15
+ export interface ConnectResult {
16
+ user: ArinovaUser;
17
+ accessToken: string;
18
+ agents: AgentInfo[];
19
+ }
12
20
  export interface ArinovaUser {
13
21
  id: string;
14
22
  name: string;
@@ -73,4 +81,3 @@ export interface SSEErrorEvent {
73
81
  error: string;
74
82
  }
75
83
  export type SSEEvent = SSEChunkEvent | SSEDoneEvent | SSEErrorEvent;
76
- //# sourceMappingURL=types.d.ts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CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;CACjB;AAGD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,QAAQ,GAAG,aAAa,GAAG,YAAY,GAAG,aAAa,CAAC"}
package/dist/types.js CHANGED
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=types.js.map
package/package.json CHANGED
@@ -1,20 +1,15 @@
1
1
  {
2
2
  "name": "@arinova-ai/spaces-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
+ "description": "Arinova Spaces SDK — OAuth PKCE login for third-party apps",
4
5
  "type": "module",
5
- "main": "./dist/index.js",
6
- "types": "./dist/index.d.ts",
7
- "exports": {
8
- ".": {
9
- "import": "./dist/index.js",
10
- "types": "./dist/index.d.ts"
11
- }
12
- },
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": ["dist"],
13
9
  "scripts": {
14
- "build": "tsc",
15
- "dev": "tsc --watch"
10
+ "build": "tsc"
16
11
  },
17
12
  "devDependencies": {
18
- "typescript": "^5.6.0"
13
+ "typescript": "^5.4.0"
19
14
  }
20
15
  }
package/src/index.ts DELETED
@@ -1,286 +0,0 @@
1
- import type {
2
- ArinovaConfig,
3
- LoginOptions,
4
- LoginResult,
5
- ArinovaUser,
6
- AgentInfo,
7
- AgentChatOptions,
8
- AgentChatResponse,
9
- AgentChatStreamOptions,
10
- AgentChatStreamResponse,
11
- ChargeOptions,
12
- ChargeResponse,
13
- AwardOptions,
14
- AwardResponse,
15
- BalanceResponse,
16
- SSEEvent,
17
- } from "./types.js";
18
-
19
- export type * from "./types.js";
20
-
21
- let _config: ArinovaConfig | null = null;
22
- let _oauthClientInfo: { clientId: string; clientSecret: string } | null = null;
23
-
24
- function getBaseUrl(): string {
25
- if (!_config) throw new Error("Arinova SDK not initialized. Call Arinova.init() first.");
26
- return _config.baseUrl || "https://api.arinova.ai";
27
- }
28
-
29
- function getConfig(): ArinovaConfig {
30
- if (!_config) throw new Error("Arinova SDK not initialized. Call Arinova.init() first.");
31
- return _config;
32
- }
33
-
34
- export const Arinova = {
35
- /**
36
- * Initialize the SDK with your app configuration.
37
- */
38
- init(config: ArinovaConfig & { clientId?: string; clientSecret?: string }) {
39
- _config = config;
40
- if (config.clientId && config.clientSecret) {
41
- _oauthClientInfo = { clientId: config.clientId, clientSecret: config.clientSecret };
42
- }
43
- },
44
-
45
- /**
46
- * Redirect to Arinova OAuth login page.
47
- * Call this from your game's frontend.
48
- */
49
- login(options?: LoginOptions): void {
50
- const config = getConfig();
51
- const baseUrl = getBaseUrl();
52
- const scope = options?.scope?.join(" ") || "profile";
53
-
54
- // Store current URL for callback
55
- const currentUrl = typeof window !== "undefined" ? window.location.href : "";
56
-
57
- const params = new URLSearchParams({
58
- client_id: config.appId,
59
- redirect_uri: currentUrl,
60
- scope,
61
- state: crypto.randomUUID(),
62
- });
63
-
64
- window.location.href = `${baseUrl}/oauth/authorize?${params}`;
65
- },
66
-
67
- /**
68
- * Handle the OAuth callback. Call this on your redirect page.
69
- * Exchanges the authorization code for an access token.
70
- */
71
- async handleCallback(params: {
72
- code: string;
73
- clientId: string;
74
- clientSecret: string;
75
- redirectUri: string;
76
- }): Promise<LoginResult> {
77
- const baseUrl = getBaseUrl();
78
-
79
- const res = await fetch(`${baseUrl}/oauth/token`, {
80
- method: "POST",
81
- headers: { "Content-Type": "application/json" },
82
- body: JSON.stringify({
83
- grant_type: "authorization_code",
84
- code: params.code,
85
- client_id: params.clientId,
86
- client_secret: params.clientSecret,
87
- redirect_uri: params.redirectUri,
88
- }),
89
- });
90
-
91
- if (!res.ok) {
92
- const error = await res.json().catch(() => ({ error: "token_exchange_failed" }));
93
- throw new Error(error.error || "Token exchange failed");
94
- }
95
-
96
- const data = await res.json();
97
- return {
98
- user: data.user,
99
- accessToken: data.access_token,
100
- };
101
- },
102
-
103
- user: {
104
- /**
105
- * Get the authenticated user's profile.
106
- */
107
- async profile(accessToken: string): Promise<ArinovaUser> {
108
- const baseUrl = getBaseUrl();
109
- const res = await fetch(`${baseUrl}/api/v1/user/profile`, {
110
- headers: { Authorization: `Bearer ${accessToken}` },
111
- });
112
- if (!res.ok) throw new Error("Failed to get user profile");
113
- return res.json();
114
- },
115
-
116
- /**
117
- * Get the authenticated user's agents.
118
- * Requires "agents" scope.
119
- */
120
- async agents(accessToken: string): Promise<AgentInfo[]> {
121
- const baseUrl = getBaseUrl();
122
- const res = await fetch(`${baseUrl}/api/v1/user/agents`, {
123
- headers: { Authorization: `Bearer ${accessToken}` },
124
- });
125
- if (!res.ok) throw new Error("Failed to get user agents");
126
- const data = await res.json();
127
- return data.agents;
128
- },
129
- },
130
-
131
- agent: {
132
- /**
133
- * Send a prompt to a user's agent and get a complete response.
134
- */
135
- async chat(options: AgentChatOptions): Promise<AgentChatResponse> {
136
- const baseUrl = getBaseUrl();
137
- const res = await fetch(`${baseUrl}/api/v1/agent/chat`, {
138
- method: "POST",
139
- headers: {
140
- "Content-Type": "application/json",
141
- Authorization: `Bearer ${options.accessToken}`,
142
- },
143
- body: JSON.stringify({
144
- agentId: options.agentId,
145
- prompt: options.prompt,
146
- systemPrompt: options.systemPrompt,
147
- }),
148
- });
149
-
150
- if (!res.ok) {
151
- const error = await res.json().catch(() => ({ error: "agent_chat_failed" }));
152
- throw new Error(error.error || "Agent chat failed");
153
- }
154
-
155
- return res.json();
156
- },
157
-
158
- /**
159
- * Send a prompt to a user's agent and receive a streaming response via SSE.
160
- */
161
- async chatStream(options: AgentChatStreamOptions): Promise<AgentChatStreamResponse> {
162
- const baseUrl = getBaseUrl();
163
- const res = await fetch(`${baseUrl}/api/v1/agent/chat/stream`, {
164
- method: "POST",
165
- headers: {
166
- "Content-Type": "application/json",
167
- Authorization: `Bearer ${options.accessToken}`,
168
- },
169
- body: JSON.stringify({
170
- agentId: options.agentId,
171
- prompt: options.prompt,
172
- systemPrompt: options.systemPrompt,
173
- }),
174
- });
175
-
176
- if (!res.ok) {
177
- const error = await res.json().catch(() => ({ error: "agent_stream_failed" }));
178
- throw new Error(error.error || "Agent stream failed");
179
- }
180
-
181
- const reader = res.body!.getReader();
182
- const decoder = new TextDecoder();
183
- let fullContent = "";
184
- let buffer = "";
185
-
186
- while (true) {
187
- const { done, value } = await reader.read();
188
- if (done) break;
189
-
190
- buffer += decoder.decode(value, { stream: true });
191
- const lines = buffer.split("\n");
192
- buffer = lines.pop() || "";
193
-
194
- for (const line of lines) {
195
- if (!line.startsWith("data: ")) continue;
196
- try {
197
- const event: SSEEvent = JSON.parse(line.slice(6));
198
- if (event.type === "chunk") {
199
- options.onChunk(event.content);
200
- fullContent = event.content;
201
- } else if (event.type === "done") {
202
- fullContent = event.content;
203
- } else if (event.type === "error") {
204
- throw new Error(event.error);
205
- }
206
- } catch (e) {
207
- if (e instanceof Error && e.message !== "Unexpected end of JSON input") throw e;
208
- }
209
- }
210
- }
211
-
212
- return { content: fullContent, agentId: options.agentId };
213
- },
214
- },
215
-
216
- economy: {
217
- /**
218
- * Charge coins from a user's balance (server-to-server).
219
- * Requires clientId and clientSecret.
220
- */
221
- async charge(options: ChargeOptions & { clientId: string; clientSecret: string }): Promise<ChargeResponse> {
222
- const baseUrl = getBaseUrl();
223
- const res = await fetch(`${baseUrl}/api/v1/economy/charge`, {
224
- method: "POST",
225
- headers: {
226
- "Content-Type": "application/json",
227
- "X-Client-Id": options.clientId,
228
- "X-App-Secret": options.clientSecret,
229
- },
230
- body: JSON.stringify({
231
- userId: options.userId,
232
- amount: options.amount,
233
- description: options.description,
234
- }),
235
- });
236
-
237
- if (!res.ok) {
238
- const error = await res.json().catch(() => ({ error: "charge_failed" }));
239
- throw new Error(error.error || "Charge failed");
240
- }
241
-
242
- return res.json();
243
- },
244
-
245
- /**
246
- * Award coins to a user (server-to-server).
247
- * Requires clientId and clientSecret.
248
- */
249
- async award(options: AwardOptions & { clientId: string; clientSecret: string }): Promise<AwardResponse> {
250
- const baseUrl = getBaseUrl();
251
- const res = await fetch(`${baseUrl}/api/v1/economy/award`, {
252
- method: "POST",
253
- headers: {
254
- "Content-Type": "application/json",
255
- "X-Client-Id": options.clientId,
256
- "X-App-Secret": options.clientSecret,
257
- },
258
- body: JSON.stringify({
259
- userId: options.userId,
260
- amount: options.amount,
261
- description: options.description,
262
- }),
263
- });
264
-
265
- if (!res.ok) {
266
- const error = await res.json().catch(() => ({ error: "award_failed" }));
267
- throw new Error(error.error || "Award failed");
268
- }
269
-
270
- return res.json();
271
- },
272
-
273
- /**
274
- * Get a user's coin balance (uses OAuth access token).
275
- */
276
- async balance(accessToken: string): Promise<BalanceResponse> {
277
- const baseUrl = getBaseUrl();
278
- const res = await fetch(`${baseUrl}/api/v1/economy/balance`, {
279
- headers: { Authorization: `Bearer ${accessToken}` },
280
- });
281
-
282
- if (!res.ok) throw new Error("Failed to get balance");
283
- return res.json();
284
- },
285
- },
286
- };
package/src/types.ts DELETED
@@ -1,97 +0,0 @@
1
- // ===== Config =====
2
- export interface ArinovaConfig {
3
- appId: string;
4
- baseUrl?: string; // defaults to "https://api.arinova.ai"
5
- }
6
-
7
- // ===== Auth =====
8
- export interface LoginOptions {
9
- scope?: string[]; // defaults to ["profile"]
10
- }
11
-
12
- export interface LoginResult {
13
- user: ArinovaUser;
14
- accessToken: string;
15
- }
16
-
17
- export interface ArinovaUser {
18
- id: string;
19
- name: string;
20
- email: string;
21
- image: string | null;
22
- }
23
-
24
- // ===== Agent =====
25
- export interface AgentInfo {
26
- id: string;
27
- name: string;
28
- description: string | null;
29
- avatarUrl: string | null;
30
- }
31
-
32
- export interface AgentChatOptions {
33
- agentId: string;
34
- prompt: string;
35
- systemPrompt?: string;
36
- accessToken: string;
37
- }
38
-
39
- export interface AgentChatResponse {
40
- response: string;
41
- agentId: string;
42
- }
43
-
44
- export interface AgentChatStreamOptions extends AgentChatOptions {
45
- onChunk: (chunk: string) => void;
46
- }
47
-
48
- export interface AgentChatStreamResponse {
49
- content: string;
50
- agentId: string;
51
- }
52
-
53
- // ===== Economy =====
54
- export interface ChargeOptions {
55
- userId: string;
56
- amount: number;
57
- description?: string;
58
- }
59
-
60
- export interface ChargeResponse {
61
- transactionId: string;
62
- newBalance: number;
63
- }
64
-
65
- export interface AwardOptions {
66
- userId: string;
67
- amount: number;
68
- description?: string;
69
- }
70
-
71
- export interface AwardResponse {
72
- transactionId: string;
73
- newBalance: number;
74
- platformFee: number;
75
- }
76
-
77
- export interface BalanceResponse {
78
- balance: number;
79
- }
80
-
81
- // ===== SSE Event =====
82
- export interface SSEChunkEvent {
83
- type: "chunk";
84
- content: string;
85
- }
86
-
87
- export interface SSEDoneEvent {
88
- type: "done";
89
- content: string;
90
- }
91
-
92
- export interface SSEErrorEvent {
93
- type: "error";
94
- error: string;
95
- }
96
-
97
- export type SSEEvent = SSEChunkEvent | SSEDoneEvent | SSEErrorEvent;
package/tsconfig.json DELETED
@@ -1,19 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "ESNext",
5
- "moduleResolution": "bundler",
6
- "lib": ["ES2022", "DOM"],
7
- "outDir": "./dist",
8
- "rootDir": "./src",
9
- "declaration": true,
10
- "declarationMap": true,
11
- "sourceMap": true,
12
- "strict": true,
13
- "esModuleInterop": true,
14
- "skipLibCheck": true,
15
- "forceConsistentCasingInFileNames": true
16
- },
17
- "include": ["src/**/*"],
18
- "exclude": ["node_modules", "dist"]
19
- }