@opencraw/studio 0.0.11 → 0.0.12

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/dist/index.esm.js +26 -6
  2. package/package.json +3 -3
package/dist/index.esm.js CHANGED
@@ -2,7 +2,7 @@ import { join, dirname, basename, extname, normalize, sep, resolve } from 'node:
2
2
  import { createServer } from 'node:http';
3
3
  import { fileURLToPath, pathToFileURL } from 'node:url';
4
4
  import { z } from 'zod';
5
- import { BODY_KINDS, HttpClient, BrowserClient, NODE_ID_ATTRIBUTE, rowsOfCells, parseXml, findDeckTables, findGridTables, analyzeTables, parseRegion, regionText, deckRegionText, isDeckDocument, readRecipeSource, parseInputRecipe, parseOutputRecipe, bindRecipeSet, memorySink, createCrawler, traceLine, UnknownHookError, resolveMissingPolicy, isWorkbookDocument, RecipeBindingError, RecipeValidationError, countMatches, matchesOf, tryParseJson, isPdfDocument, BrowserProfiles } from '@opencraw/core';
5
+ import { BODY_KINDS, HttpClient, BrowserClient, NODE_ID_ATTRIBUTE, sessionStateOf, rowsOfCells, parseXml, findDeckTables, findGridTables, analyzeTables, parseRegion, regionText, deckRegionText, isDeckDocument, readRecipeSource, parseInputRecipe, parseOutputRecipe, bindRecipeSet, memorySink, createCrawler, traceLine, UnknownHookError, resolveMissingPolicy, isWorkbookDocument, RecipeBindingError, RecipeValidationError, countMatches, matchesOf, tryParseJson, isPdfDocument, BrowserProfiles } from '@opencraw/core';
6
6
  import { randomBytes, createHash } from 'node:crypto';
7
7
  import { execFile } from 'node:child_process';
8
8
  import { createRequire } from 'node:module';
@@ -1119,12 +1119,30 @@ async function takeSnapshot(input, stepPath, browser) {
1119
1119
  if (stepPath !== 'start') throw new Error(`takeSnapshot: "${stepPath}" is not supported yet — only "start" (the first start point, before any step runs) is; see this function's doc comment`);
1120
1120
  const point = input.start[0];
1121
1121
  if (point === undefined) throw new Error(`recipe "${input.id}" has no start point`);
1122
- return input.mode === 'web' ? snapshotWeb(point.url, browser) : snapshotApi(point.url);
1122
+ const storageState = await loginState(input, browser);
1123
+ return input.mode === 'web' ? snapshotWeb(point.url, storageState, browser) : snapshotApi(point.url, storageState);
1123
1124
  }
1124
- async function snapshotWeb(url, browser) {
1125
+ /** What the recipe's own login leaves behind, so the snapshot shows the page as the crawl sees it (issue #185); nothing when it declares no login. */
1126
+ async function loginState(input, browser) {
1127
+ if (input.session === undefined) return undefined;
1128
+ let client;
1129
+ try {
1130
+ return await sessionStateOf(input, {
1131
+ browser: async () => {
1132
+ client = await ensureBrowserLaunch(browser, () => BrowserClient.launch(browser));
1133
+ return client;
1134
+ }
1135
+ });
1136
+ } finally {
1137
+ await client?.close();
1138
+ }
1139
+ }
1140
+ async function snapshotWeb(url, storageState, browser) {
1125
1141
  const client = await ensureBrowserLaunch(browser, () => BrowserClient.launch(browser));
1126
1142
  try {
1127
- const session = await client.newSession();
1143
+ const session = await client.newSession({
1144
+ storageState
1145
+ });
1128
1146
  try {
1129
1147
  await session.page.goto(url);
1130
1148
  await session.page.evaluate(hiddenMarksScript(HIDDEN_ATTRIBUTE));
@@ -1143,8 +1161,10 @@ async function snapshotWeb(url, browser) {
1143
1161
  await client.close();
1144
1162
  }
1145
1163
  }
1146
- async function snapshotApi(url) {
1147
- const client = await HttpClient.open({});
1164
+ async function snapshotApi(url, storageState) {
1165
+ const client = await HttpClient.open({
1166
+ storageState
1167
+ });
1148
1168
  try {
1149
1169
  const response = await client.send({
1150
1170
  url
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencraw/studio",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "type": "module",
5
5
  "main": "./dist/index.esm.js",
6
6
  "module": "./dist/index.esm.js",
@@ -24,8 +24,8 @@
24
24
  "!**/*.js.map"
25
25
  ],
26
26
  "dependencies": {
27
- "@opencraw/core": "^0.1.22",
28
- "@opencraw/probe": "^0.0.5",
27
+ "@opencraw/core": "^0.1.23",
28
+ "@opencraw/probe": "^0.0.6",
29
29
  "cheerio": "^1.2.0",
30
30
  "playwright": "^1.63.0",
31
31
  "zod": "^4.6.5",