notebooklm-sdk 0.1.7 → 0.1.8

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/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { A as AuthTokens, a as ConnectOptions } from './auth-Ba2hsZW_.cjs';
2
- export { C as CookieMap, d as connect } from './auth-Ba2hsZW_.cjs';
1
+ import { A as AuthTokens, a as ConnectOptions } from './auth-Dxsm8894.cjs';
2
+ export { C as CookieMap, d as connect } from './auth-Dxsm8894.cjs';
3
3
  export { ArtifactDownloadError, ArtifactError, ArtifactNotFoundError, ArtifactNotReadyError, ArtifactParseError, AuthError, ChatError, ClientError, NetworkError, NotebookError, NotebookLMError, NotebookNotFoundError, RPCError, RPCTimeoutError, RateLimitError, ServerError, SourceAddError, SourceError, SourceNotFoundError, SourceProcessingError, SourceTimeoutError } from './errors.cjs';
4
4
 
5
5
  /** RPC method IDs for NotebookLM batchexecute API. */
@@ -523,10 +523,12 @@ interface ClientOptions {
523
523
  *
524
524
  * @example
525
525
  * ```ts
526
- * const client = await NotebookLMClient.connect({
527
- * cookies: process.env.NOTEBOOKLM_COOKIES,
528
- * });
526
+ * // After running `npx notebooklm-sdk login` once:
527
+ * const client = await NotebookLMClient.connect();
529
528
  * const notebooks = await client.notebooks.list();
529
+ *
530
+ * // Or with explicit credentials:
531
+ * const client = await NotebookLMClient.connect({ cookiesFile: './session.json' });
530
532
  * ```
531
533
  */
532
534
  declare class NotebookLMClient {
@@ -544,7 +546,7 @@ declare class NotebookLMClient {
544
546
  * Connect to NotebookLM using cookies.
545
547
  * Fetches CSRF and session tokens from the NotebookLM homepage.
546
548
  */
547
- static connect(opts: ConnectOptions, clientOpts?: ClientOptions): Promise<NotebookLMClient>;
549
+ static connect(opts?: ConnectOptions, clientOpts?: ClientOptions): Promise<NotebookLMClient>;
548
550
  /**
549
551
  * Refresh CSRF and session tokens (e.g. if they expire mid-session).
550
552
  */
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { A as AuthTokens, a as ConnectOptions } from './auth-Ba2hsZW_.js';
2
- export { C as CookieMap, d as connect } from './auth-Ba2hsZW_.js';
1
+ import { A as AuthTokens, a as ConnectOptions } from './auth-Dxsm8894.js';
2
+ export { C as CookieMap, d as connect } from './auth-Dxsm8894.js';
3
3
  export { ArtifactDownloadError, ArtifactError, ArtifactNotFoundError, ArtifactNotReadyError, ArtifactParseError, AuthError, ChatError, ClientError, NetworkError, NotebookError, NotebookLMError, NotebookNotFoundError, RPCError, RPCTimeoutError, RateLimitError, ServerError, SourceAddError, SourceError, SourceNotFoundError, SourceProcessingError, SourceTimeoutError } from './errors.js';
4
4
 
5
5
  /** RPC method IDs for NotebookLM batchexecute API. */
@@ -523,10 +523,12 @@ interface ClientOptions {
523
523
  *
524
524
  * @example
525
525
  * ```ts
526
- * const client = await NotebookLMClient.connect({
527
- * cookies: process.env.NOTEBOOKLM_COOKIES,
528
- * });
526
+ * // After running `npx notebooklm-sdk login` once:
527
+ * const client = await NotebookLMClient.connect();
529
528
  * const notebooks = await client.notebooks.list();
529
+ *
530
+ * // Or with explicit credentials:
531
+ * const client = await NotebookLMClient.connect({ cookiesFile: './session.json' });
530
532
  * ```
531
533
  */
532
534
  declare class NotebookLMClient {
@@ -544,7 +546,7 @@ declare class NotebookLMClient {
544
546
  * Connect to NotebookLM using cookies.
545
547
  * Fetches CSRF and session tokens from the NotebookLM homepage.
546
548
  */
547
- static connect(opts: ConnectOptions, clientOpts?: ClientOptions): Promise<NotebookLMClient>;
549
+ static connect(opts?: ConnectOptions, clientOpts?: ClientOptions): Promise<NotebookLMClient>;
548
550
  /**
549
551
  * Refresh CSRF and session tokens (e.g. if they expire mid-session).
550
552
  */
package/dist/index.js CHANGED
@@ -1,4 +1,6 @@
1
- import { readFileSync } from 'fs';
1
+ import { readFileSync, existsSync } from 'fs';
2
+ import { homedir } from 'os';
3
+ import { join } from 'path';
2
4
 
3
5
  var __defProp = Object.defineProperty;
4
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -452,8 +454,8 @@ function loadCookiesFromFile(filePath) {
452
454
  raw = readFileSync(filePath, "utf-8");
453
455
  } catch {
454
456
  throw new AuthError(
455
- `Cookie file not found: ${filePath}
456
- Provide valid Playwright storage state JSON.`
457
+ `Session file not found: ${filePath}
458
+ Run: npx notebooklm-sdk login`
457
459
  );
458
460
  }
459
461
  return extractCookiesFromStorageState(JSON.parse(raw));
@@ -497,7 +499,7 @@ function extractCookiesFromStorageState(storageState) {
497
499
  }
498
500
  if (!cookies["SID"]) {
499
501
  throw new AuthError(
500
- "Missing required cookie: SID. Provide valid Playwright storage state with Google cookies."
502
+ "Missing required cookie: SID. Session may be invalid or expired.\nRun: npx notebooklm-sdk login"
501
503
  );
502
504
  }
503
505
  return cookies;
@@ -536,7 +538,7 @@ function extractCsrfToken(html, finalUrl) {
536
538
  const match = /"SNlM0e"\s*:\s*"([^"]+)"/.exec(html);
537
539
  if (!match?.[1]) {
538
540
  if (isGoogleAuthRedirect(finalUrl) || html.includes("accounts.google.com")) {
539
- throw new AuthError("Authentication expired or invalid. Cookies may need to be refreshed.");
541
+ throw new AuthError("Session expired or invalid.\nRun: npx notebooklm-sdk login");
540
542
  }
541
543
  throw new AuthError("CSRF token (SNlM0e) not found in NotebookLM page HTML.");
542
544
  }
@@ -546,7 +548,7 @@ function extractSessionId(html, finalUrl) {
546
548
  const match = /"FdrFJe"\s*:\s*"([^"]+)"/.exec(html);
547
549
  if (!match?.[1]) {
548
550
  if (isGoogleAuthRedirect(finalUrl) || html.includes("accounts.google.com")) {
549
- throw new AuthError("Authentication expired or invalid. Cookies may need to be refreshed.");
551
+ throw new AuthError("Session expired or invalid.\nRun: npx notebooklm-sdk login");
550
552
  }
551
553
  throw new AuthError("Session ID (FdrFJe) not found in NotebookLM page HTML.");
552
554
  }
@@ -555,7 +557,7 @@ function extractSessionId(html, finalUrl) {
555
557
  function isGoogleAuthRedirect(url) {
556
558
  return url.includes("accounts.google.com") || url.includes("signin");
557
559
  }
558
- async function connect(opts) {
560
+ async function connect(opts = {}) {
559
561
  let cookieMap;
560
562
  let googleCookieHeader = null;
561
563
  if (opts.cookies) {
@@ -572,11 +574,24 @@ async function connect(opts) {
572
574
  }
573
575
  } else {
574
576
  const envCookies = process.env["NOTEBOOKLM_COOKIES"];
575
- if (envCookies) {
577
+ const envFile = process.env["NOTEBOOKLM_COOKIES_FILE"];
578
+ if (envFile) {
579
+ cookieMap = loadCookiesFromFile(envFile);
580
+ } else if (existsSync(DEFAULT_SESSION_FILE)) {
581
+ const raw = readFileSync(DEFAULT_SESSION_FILE, "utf-8");
582
+ const storageState = JSON.parse(raw);
583
+ cookieMap = loadCookiesFromObject(storageState);
584
+ googleCookieHeader = buildGoogleCookieHeader(storageState);
585
+ } else if (existsSync("storage_state.json")) {
586
+ const raw = readFileSync("storage_state.json", "utf-8");
587
+ const storageState = JSON.parse(raw);
588
+ cookieMap = loadCookiesFromObject(storageState);
589
+ googleCookieHeader = buildGoogleCookieHeader(storageState);
590
+ } else if (envCookies) {
576
591
  cookieMap = loadCookiesFromString(envCookies);
577
592
  } else {
578
593
  throw new AuthError(
579
- "No cookies provided. Pass cookies, cookiesFile, or cookiesObject to connect()."
594
+ "No session found. Run: npx notebooklm-sdk login"
580
595
  );
581
596
  }
582
597
  }
@@ -590,10 +605,11 @@ async function connect(opts) {
590
605
  googleCookieHeader: googleCookieHeader ?? cookieHeader
591
606
  };
592
607
  }
593
- var NOTEBOOKLM_URL;
608
+ var DEFAULT_SESSION_FILE, NOTEBOOKLM_URL;
594
609
  var init_auth = __esm({
595
610
  "src/auth.ts"() {
596
611
  init_errors();
612
+ DEFAULT_SESSION_FILE = join(homedir(), ".notebooklm", "session.json");
597
613
  NOTEBOOKLM_URL = "https://notebooklm.google.com/";
598
614
  }
599
615
  });
@@ -2395,7 +2411,7 @@ var NotebookLMClient = class _NotebookLMClient {
2395
2411
  * Connect to NotebookLM using cookies.
2396
2412
  * Fetches CSRF and session tokens from the NotebookLM homepage.
2397
2413
  */
2398
- static async connect(opts, clientOpts = {}) {
2414
+ static async connect(opts = {}, clientOpts = {}) {
2399
2415
  const auth = await connect(opts);
2400
2416
  return new _NotebookLMClient(auth, clientOpts);
2401
2417
  }