@opentabs-dev/opentabs-plugin-prescript-test 0.0.1
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/adapter.iife.js +14194 -0
- package/dist/adapter.iife.js.map +7 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/pre-script.d.ts +2 -0
- package/dist/pre-script.d.ts.map +1 -0
- package/dist/pre-script.iife.js +81 -0
- package/dist/pre-script.iife.js.map +7 -0
- package/dist/pre-script.js +52 -0
- package/dist/pre-script.js.map +1 -0
- package/dist/tools/echo-auth.d.ts +15 -0
- package/dist/tools/echo-auth.d.ts.map +1 -0
- package/dist/tools/echo-auth.js +32 -0
- package/dist/tools/echo-auth.js.map +1 -0
- package/dist/tools.json +69 -0
- package/package.json +60 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { OpenTabsPlugin } from '@opentabs-dev/plugin-sdk';
|
|
2
|
+
import type { ToolDefinition } from '@opentabs-dev/plugin-sdk';
|
|
3
|
+
declare class PreScriptTestPlugin extends OpenTabsPlugin {
|
|
4
|
+
readonly name = "prescript-test";
|
|
5
|
+
readonly description = "Test plugin for the pre-script feature \u2014 captures bearer tokens at document_start before the page can overwrite window.fetch";
|
|
6
|
+
readonly displayName = "Pre-Script Test";
|
|
7
|
+
readonly urlPatterns: string[];
|
|
8
|
+
readonly tools: ToolDefinition[];
|
|
9
|
+
isReady(): Promise<boolean>;
|
|
10
|
+
}
|
|
11
|
+
declare const _default: PreScriptTestPlugin;
|
|
12
|
+
export default _default;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG/D,cAAM,mBAAoB,SAAQ,cAAc;IAC9C,QAAQ,CAAC,IAAI,oBAAoB;IACjC,QAAQ,CAAC,WAAW,uIAC6G;IACjI,SAAkB,WAAW,qBAAqB;IAClD,QAAQ,CAAC,WAAW,WAAgD;IACpE,QAAQ,CAAC,KAAK,EAAE,cAAc,EAAE,CAAc;IAE/B,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;CAG3C;;AAED,wBAAyC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OpenTabsPlugin } from '@opentabs-dev/plugin-sdk';
|
|
2
|
+
import { echoAuth } from './tools/echo-auth.js';
|
|
3
|
+
class PreScriptTestPlugin extends OpenTabsPlugin {
|
|
4
|
+
name = 'prescript-test';
|
|
5
|
+
description = 'Test plugin for the pre-script feature — captures bearer tokens at document_start before the page can overwrite window.fetch';
|
|
6
|
+
displayName = 'Pre-Script Test';
|
|
7
|
+
urlPatterns = ['http://localhost/*', 'http://127.0.0.1/*'];
|
|
8
|
+
tools = [echoAuth];
|
|
9
|
+
async isReady() {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export default new PreScriptTestPlugin();
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,MAAM,mBAAoB,SAAQ,cAAc;IACrC,IAAI,GAAG,gBAAgB,CAAC;IACxB,WAAW,GAClB,8HAA8H,CAAC;IAC/G,WAAW,GAAG,iBAAiB,CAAC;IACzC,WAAW,GAAG,CAAC,oBAAoB,EAAE,oBAAoB,CAAC,CAAC;IAC3D,KAAK,GAAqB,CAAC,QAAQ,CAAC,CAAC;IAErC,KAAK,CAAC,OAAO;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,eAAe,IAAI,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pre-script.d.ts","sourceRoot":"","sources":["../src/pre-script.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
(() => {
|
|
3
|
+
// dist/_pre_script_setup_0360980b-b5a6-4be0-9b79-6dab63ed4392.ts
|
|
4
|
+
if (!globalThis.__openTabs) {
|
|
5
|
+
globalThis.__openTabs = {};
|
|
6
|
+
}
|
|
7
|
+
var _ot = globalThis.__openTabs;
|
|
8
|
+
if (!_ot.preScript) {
|
|
9
|
+
_ot.preScript = {};
|
|
10
|
+
}
|
|
11
|
+
_ot.preScript["prescript-test"] = {};
|
|
12
|
+
var _logPrefix = "[opentabs:prescript-test:pre-script]";
|
|
13
|
+
var _log = {
|
|
14
|
+
debug: (...args) => {
|
|
15
|
+
console.debug(_logPrefix, ...args);
|
|
16
|
+
},
|
|
17
|
+
info: (...args) => {
|
|
18
|
+
console.info(_logPrefix, ...args);
|
|
19
|
+
},
|
|
20
|
+
warn: (...args) => {
|
|
21
|
+
console.warn(_logPrefix, ...args);
|
|
22
|
+
},
|
|
23
|
+
error: (...args) => {
|
|
24
|
+
console.error(_logPrefix, ...args);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
_ot._preScriptRunner = (fn) => {
|
|
28
|
+
delete _ot._preScriptRunner;
|
|
29
|
+
const ctx = {
|
|
30
|
+
set(key, value) {
|
|
31
|
+
_ot.preScript["prescript-test"][key] = value;
|
|
32
|
+
},
|
|
33
|
+
log: _log
|
|
34
|
+
};
|
|
35
|
+
try {
|
|
36
|
+
fn(ctx);
|
|
37
|
+
} catch (e) {
|
|
38
|
+
console.error(_logPrefix, "pre-script threw:", e);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// node_modules/@opentabs-dev/plugin-sdk/dist/pre-script.js
|
|
43
|
+
var definePreScript = (fn) => {
|
|
44
|
+
const ot = globalThis.__openTabs;
|
|
45
|
+
ot?._preScriptRunner?.(fn);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/pre-script.ts
|
|
49
|
+
definePreScript(({ set, log }) => {
|
|
50
|
+
const g = globalThis;
|
|
51
|
+
const origFetch = g["fetch"];
|
|
52
|
+
const patchedFetch = async (input, init) => {
|
|
53
|
+
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
54
|
+
const headers = init?.headers;
|
|
55
|
+
let bearer;
|
|
56
|
+
if (headers instanceof Headers) {
|
|
57
|
+
bearer = headers.get("Authorization") ?? headers.get("authorization") ?? void 0;
|
|
58
|
+
} else if (Array.isArray(headers)) {
|
|
59
|
+
for (const entry of headers) {
|
|
60
|
+
if (entry[0]?.toLowerCase() === "authorization") {
|
|
61
|
+
bearer = entry[1];
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
} else if (headers && typeof headers === "object") {
|
|
66
|
+
const h = headers;
|
|
67
|
+
bearer = h["Authorization"] ?? h["authorization"];
|
|
68
|
+
}
|
|
69
|
+
if (bearer?.startsWith("Bearer ")) {
|
|
70
|
+
set("authToken", bearer.slice(7));
|
|
71
|
+
set("authUrl", url);
|
|
72
|
+
set("capturedAt", Date.now());
|
|
73
|
+
log.debug(`[prescript-test] captured bearer for ${url}`);
|
|
74
|
+
}
|
|
75
|
+
return origFetch(input, init);
|
|
76
|
+
};
|
|
77
|
+
g["fetch"] = patchedFetch;
|
|
78
|
+
log.info("[prescript-test] fetch interceptor installed");
|
|
79
|
+
});
|
|
80
|
+
})();
|
|
81
|
+
//# sourceMappingURL=pre-script.iife.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["_pre_script_setup_0360980b-b5a6-4be0-9b79-6dab63ed4392.ts", "../node_modules/@opentabs-dev/plugin-sdk/src/pre-script.ts", "../src/pre-script.ts"],
|
|
4
|
+
"sourcesContent": ["declare global {\n var __openTabs: {\n _preScriptRunner?: (fn: (ctx: {\n set(key: string, value: unknown): void;\n log: {\n debug(...args: unknown[]): void;\n info(...args: unknown[]): void;\n warn(...args: unknown[]): void;\n error(...args: unknown[]): void;\n };\n }) => void) => void;\n preScript?: Record<string, Record<string, unknown>>;\n } | undefined;\n}\n\nif (!globalThis.__openTabs) {\n (globalThis as Record<string, unknown>).__openTabs = {};\n}\nconst _ot = globalThis.__openTabs!;\nif (!_ot.preScript) {\n _ot.preScript = {};\n}\n\n// Reset this plugin's pre-script bucket on every load. Each navigation gets\n// a clean slate so stale values from the previous page don't leak.\n_ot.preScript[\"prescript-test\"] = {};\n\n// Plugin-scoped logger. Pre-script logs go directly to console \u2014 the\n// extension's ISOLATED-world log relay hasn't loaded yet at document_start.\nconst _logPrefix = \"[opentabs:prescript-test:pre-script]\";\nconst _log = {\n debug: (...args: unknown[]) => { console.debug(_logPrefix, ...args); },\n info: (...args: unknown[]) => { console.info(_logPrefix, ...args); },\n warn: (...args: unknown[]) => { console.warn(_logPrefix, ...args); },\n error: (...args: unknown[]) => { console.error(_logPrefix, ...args); },\n};\n\n// Install _preScriptRunner so definePreScript() in the user module can invoke\n// the callback synchronously. Self-destructs after first call so it cannot\n// be called again after the pre-script has loaded.\n_ot._preScriptRunner = (fn) => {\n delete _ot._preScriptRunner;\n const ctx = {\n set(key: string, value: unknown) {\n _ot.preScript![\"prescript-test\"]![key] = value;\n },\n log: _log,\n };\n try {\n fn(ctx as Parameters<typeof fn>[0]);\n } catch (e) {\n console.error(_logPrefix, 'pre-script threw:', e);\n }\n};\n", null, "import { definePreScript } from '@opentabs-dev/plugin-sdk/pre-script';\n\n/**\n * Pre-script for the prescript-test plugin.\n *\n * Runs at document_start in MAIN world, strictly before any page script.\n * Wraps window.fetch to capture bearer tokens from outbound requests \u2014\n * simulating the PR #69 scenario where the page overwrites window.fetch\n * immediately after its own bootstrap fetch, which would prevent a normal\n * adapter from ever seeing the token.\n *\n * The adapter reads the captured values later via getPreScriptValue().\n */\ndefinePreScript(({ set, log }) => {\n const g = globalThis as Record<string, unknown>;\n const origFetch = g['fetch'] as typeof fetch;\n\n const patchedFetch = async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {\n // Resolve the URL string for storage\n const url =\n typeof input === 'string'\n ? input\n : input instanceof URL\n ? input.href\n : (input as Request).url;\n\n // Extract any Authorization: Bearer header from whichever HeadersInit shape was passed\n const headers = init?.headers;\n let bearer: string | undefined;\n\n if (headers instanceof Headers) {\n bearer = headers.get('Authorization') ?? headers.get('authorization') ?? undefined;\n } else if (Array.isArray(headers)) {\n for (const entry of headers as string[][]) {\n if (entry[0]?.toLowerCase() === 'authorization') {\n bearer = entry[1];\n break;\n }\n }\n } else if (headers && typeof headers === 'object') {\n const h = headers as Record<string, string>;\n bearer = h['Authorization'] ?? h['authorization'];\n }\n\n if (bearer?.startsWith('Bearer ')) {\n set('authToken', bearer.slice(7));\n set('authUrl', url);\n set('capturedAt', Date.now());\n log.debug(`[prescript-test] captured bearer for ${url}`);\n }\n\n return origFetch(input, init);\n };\n\n g['fetch'] = patchedFetch;\n log.info('[prescript-test] fetch interceptor installed');\n});\n"],
|
|
5
|
+
"mappings": ";;;AAeA,MAAI,CAAC,WAAW,YAAY;AAC1B,IAAC,WAAuC,aAAa,CAAC;AAAA,EACxD;AACA,MAAM,MAAM,WAAW;AACvB,MAAI,CAAC,IAAI,WAAW;AAClB,QAAI,YAAY,CAAC;AAAA,EACnB;AAIA,MAAI,UAAU,gBAAgB,IAAI,CAAC;AAInC,MAAM,aAAa;AACnB,MAAM,OAAO;AAAA,IACX,OAAO,IAAI,SAAoB;AAAE,cAAQ,MAAM,YAAY,GAAG,IAAI;AAAA,IAAG;AAAA,IACrE,MAAO,IA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EAAE,eAAe;AAAA,MAClD;AAEA,UAAI,QAAQ,WAAW,SAAS,GAAG;AACjC,YAAI,aAAa,OAAO,MAAM,CAAC,CAAC;AAChC,YAAI,WAAW,GAAG;AAClB,YAAI,cAAc,KAAK,IAAI,CAAC;AAC5B,YAAI,MAAM,wCAAwC,GAAG,EAAE;AAAA,MACzD;AAEA,aAAO,UAAU,OAAO,IAAI;AAAA,IAC9B;AAEA,MAAE,OAAO,IAAI;AACb,QAAI,KAAK,8CAA8C;AAAA,EACzD,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { definePreScript } from '@opentabs-dev/plugin-sdk/pre-script';
|
|
2
|
+
/**
|
|
3
|
+
* Pre-script for the prescript-test plugin.
|
|
4
|
+
*
|
|
5
|
+
* Runs at document_start in MAIN world, strictly before any page script.
|
|
6
|
+
* Wraps window.fetch to capture bearer tokens from outbound requests —
|
|
7
|
+
* simulating the PR #69 scenario where the page overwrites window.fetch
|
|
8
|
+
* immediately after its own bootstrap fetch, which would prevent a normal
|
|
9
|
+
* adapter from ever seeing the token.
|
|
10
|
+
*
|
|
11
|
+
* The adapter reads the captured values later via getPreScriptValue().
|
|
12
|
+
*/
|
|
13
|
+
definePreScript(({ set, log }) => {
|
|
14
|
+
const g = globalThis;
|
|
15
|
+
const origFetch = g['fetch'];
|
|
16
|
+
const patchedFetch = async (input, init) => {
|
|
17
|
+
// Resolve the URL string for storage
|
|
18
|
+
const url = typeof input === 'string'
|
|
19
|
+
? input
|
|
20
|
+
: input instanceof URL
|
|
21
|
+
? input.href
|
|
22
|
+
: input.url;
|
|
23
|
+
// Extract any Authorization: Bearer header from whichever HeadersInit shape was passed
|
|
24
|
+
const headers = init?.headers;
|
|
25
|
+
let bearer;
|
|
26
|
+
if (headers instanceof Headers) {
|
|
27
|
+
bearer = headers.get('Authorization') ?? headers.get('authorization') ?? undefined;
|
|
28
|
+
}
|
|
29
|
+
else if (Array.isArray(headers)) {
|
|
30
|
+
for (const entry of headers) {
|
|
31
|
+
if (entry[0]?.toLowerCase() === 'authorization') {
|
|
32
|
+
bearer = entry[1];
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else if (headers && typeof headers === 'object') {
|
|
38
|
+
const h = headers;
|
|
39
|
+
bearer = h['Authorization'] ?? h['authorization'];
|
|
40
|
+
}
|
|
41
|
+
if (bearer?.startsWith('Bearer ')) {
|
|
42
|
+
set('authToken', bearer.slice(7));
|
|
43
|
+
set('authUrl', url);
|
|
44
|
+
set('capturedAt', Date.now());
|
|
45
|
+
log.debug(`[prescript-test] captured bearer for ${url}`);
|
|
46
|
+
}
|
|
47
|
+
return origFetch(input, init);
|
|
48
|
+
};
|
|
49
|
+
g['fetch'] = patchedFetch;
|
|
50
|
+
log.info('[prescript-test] fetch interceptor installed');
|
|
51
|
+
});
|
|
52
|
+
//# sourceMappingURL=pre-script.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pre-script.js","sourceRoot":"","sources":["../src/pre-script.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAEtE;;;;;;;;;;GAUG;AACH,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE;IAC/B,MAAM,CAAC,GAAG,UAAqC,CAAC;IAChD,MAAM,SAAS,GAAG,CAAC,CAAC,OAAO,CAAiB,CAAC;IAE7C,MAAM,YAAY,GAAG,KAAK,EAAE,KAAwB,EAAE,IAAkB,EAAqB,EAAE;QAC7F,qCAAqC;QACrC,MAAM,GAAG,GACP,OAAO,KAAK,KAAK,QAAQ;YACvB,CAAC,CAAC,KAAK;YACP,CAAC,CAAC,KAAK,YAAY,GAAG;gBACpB,CAAC,CAAC,KAAK,CAAC,IAAI;gBACZ,CAAC,CAAE,KAAiB,CAAC,GAAG,CAAC;QAE/B,uFAAuF;Q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,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the bearer token captured by the pre-script at document_start.
|
|
4
|
+
*
|
|
5
|
+
* The pre-script installs a fetch interceptor that captures Authorization: Bearer
|
|
6
|
+
* headers from outbound requests before the page can overwrite window.fetch.
|
|
7
|
+
* This tool reads the captured values back to verify end-to-end pre-script behavior.
|
|
8
|
+
*/
|
|
9
|
+
export declare const echoAuth: import("@opentabs-dev/plugin-sdk").ToolDefinition<z.ZodObject<{}, z.core.$strip>, z.ZodObject<{
|
|
10
|
+
token: z.ZodNullable<z.ZodString>;
|
|
11
|
+
authUrl: z.ZodNullable<z.ZodString>;
|
|
12
|
+
capturedAt: z.ZodNullable<z.ZodNumber>;
|
|
13
|
+
source: z.ZodString;
|
|
14
|
+
}, z.core.$strip>>;
|
|
15
|
+
//# sourceMappingURL=echo-auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"echo-auth.d.ts","sourceRoot":"","sources":["../../src/tools/echo-auth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ;;;;;kBAqBnB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { defineTool, getPreScriptValue } from '@opentabs-dev/plugin-sdk';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* Returns the bearer token captured by the pre-script at document_start.
|
|
5
|
+
*
|
|
6
|
+
* The pre-script installs a fetch interceptor that captures Authorization: Bearer
|
|
7
|
+
* headers from outbound requests before the page can overwrite window.fetch.
|
|
8
|
+
* This tool reads the captured values back to verify end-to-end pre-script behavior.
|
|
9
|
+
*/
|
|
10
|
+
export const echoAuth = defineTool({
|
|
11
|
+
name: 'echo_auth',
|
|
12
|
+
displayName: 'Echo Auth',
|
|
13
|
+
description: 'Returns the bearer token captured by the pre-script at document_start',
|
|
14
|
+
summary: 'Return captured bearer token',
|
|
15
|
+
icon: 'key',
|
|
16
|
+
group: 'Pre-Script Test',
|
|
17
|
+
input: z.object({}),
|
|
18
|
+
output: z.object({
|
|
19
|
+
token: z.string().nullable().describe('Bearer token captured by the pre-script, or null if not yet captured'),
|
|
20
|
+
authUrl: z.string().nullable().describe('URL of the request that carried the bearer token'),
|
|
21
|
+
capturedAt: z.number().nullable().describe('Timestamp (ms since epoch) when the token was captured'),
|
|
22
|
+
source: z.string().describe("Source of the token: 'pre-script' when captured, 'none' when not available"),
|
|
23
|
+
}),
|
|
24
|
+
handle: async () => {
|
|
25
|
+
const token = getPreScriptValue('authToken') ?? null;
|
|
26
|
+
const authUrl = getPreScriptValue('authUrl') ?? null;
|
|
27
|
+
const capturedAt = getPreScriptValue('capturedAt') ?? null;
|
|
28
|
+
const source = token !== null ? 'pre-script' : 'none';
|
|
29
|
+
return { token, authUrl, capturedAt, source };
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=echo-auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"echo-auth.js","sourceRoot":"","sources":["../../src/tools/echo-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC;IACjC,IAAI,EAAE,WAAW;IACjB,WAAW,EAAE,WAAW;IACxB,WAAW,EAAE,uEAAuE;IACpF,OAAO,EAAE,8BAA8B;IACvC,IAAI,EAAE,KAAK;IACX,KAAK,EAAE,iBAAiB;IACxB,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;IACnB,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;QACf,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,sEAAsE,CAAC;QAC7G,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,kDAAkD,CAAC;QAC3F,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,wDAAwD,CAAC;QACpG,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,4EAA4E,CAAC;KAC1G,CAAC;IACF,MAAM,EAAE,KAAK,IAAI,EAAE;QACjB,MAAM,KAAK,GAAG,iBAAiB,CAAS,WAAW,CAAC,IAAI,IAAI,CAAC;QAC7D,MAAM,OAAO,GAAG,iBAAiB,CAAS,SAAS,CAAC,IAAI,IAAI,CAAC;QAC7D,MAAM,UAAU,GAAG,iBAAiB,CAAS,YAAY,CAAC,IAAI,IAAI,CAAC;QACnE,MAAM,MAAM,GAAG,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC;QACtD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;IAChD,CAAC;CACF,CAAC,CAAC"}
|
package/dist/tools.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"sdkVersion": "0.0.104",
|
|
3
|
+
"preScriptFile": "pre-script.iife.js",
|
|
4
|
+
"preScriptHash": "67f8d4a827a99555beb064c6d1db97e1948e27179b32a616ad68284a75b44267",
|
|
5
|
+
"tools": [
|
|
6
|
+
{
|
|
7
|
+
"name": "echo_auth",
|
|
8
|
+
"displayName": "Echo Auth",
|
|
9
|
+
"description": "Returns the bearer token captured by the pre-script at document_start",
|
|
10
|
+
"summary": "Return captured bearer token",
|
|
11
|
+
"icon": "key",
|
|
12
|
+
"group": "Pre-Script Test",
|
|
13
|
+
"input_schema": {
|
|
14
|
+
"type": "object",
|
|
15
|
+
"properties": {},
|
|
16
|
+
"additionalProperties": false
|
|
17
|
+
},
|
|
18
|
+
"output_schema": {
|
|
19
|
+
"type": "object",
|
|
20
|
+
"properties": {
|
|
21
|
+
"token": {
|
|
22
|
+
"anyOf": [
|
|
23
|
+
{
|
|
24
|
+
"type": "string"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"type": "null"
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
"description": "Bearer token captured by the pre-script, or null if not yet captured"
|
|
31
|
+
},
|
|
32
|
+
"authUrl": {
|
|
33
|
+
"anyOf": [
|
|
34
|
+
{
|
|
35
|
+
"type": "string"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"type": "null"
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
"description": "URL of the request that carried the bearer token"
|
|
42
|
+
},
|
|
43
|
+
"capturedAt": {
|
|
44
|
+
"anyOf": [
|
|
45
|
+
{
|
|
46
|
+
"type": "number"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"type": "null"
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
"description": "Timestamp (ms since epoch) when the token was captured"
|
|
53
|
+
},
|
|
54
|
+
"source": {
|
|
55
|
+
"type": "string",
|
|
56
|
+
"description": "Source of the token: 'pre-script' when captured, 'none' when not available"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"required": [
|
|
60
|
+
"token",
|
|
61
|
+
"authUrl",
|
|
62
|
+
"capturedAt",
|
|
63
|
+
"source"
|
|
64
|
+
],
|
|
65
|
+
"additionalProperties": false
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@opentabs-dev/opentabs-plugin-prescript-test",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"version": "0.0.1",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/adapter.iife.js",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"opentabs-plugin"
|
|
11
|
+
],
|
|
12
|
+
"opentabs": {
|
|
13
|
+
"displayName": "Pre-Script Test",
|
|
14
|
+
"description": "Test plugin for the pre-script feature — captures bearer tokens at document_start before the page can overwrite window.fetch",
|
|
15
|
+
"urlPatterns": [
|
|
16
|
+
"http://localhost/*",
|
|
17
|
+
"http://127.0.0.1/*"
|
|
18
|
+
],
|
|
19
|
+
"preScript": "src/pre-script.ts"
|
|
20
|
+
},
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc && opentabs-plugin build",
|
|
33
|
+
"dev": "tsc --watch --preserveWatchOutput & opentabs-plugin build --watch",
|
|
34
|
+
"type-check": "tsc --noEmit",
|
|
35
|
+
"lint": "biome lint src/",
|
|
36
|
+
"lint:fix": "biome lint --fix src/",
|
|
37
|
+
"format:check": "biome format src/",
|
|
38
|
+
"format": "biome format --write src/",
|
|
39
|
+
"check": "npm run build && npm run type-check && npm run lint && npm run format:check"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"zod": "^4.0.0"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@opentabs-dev/plugin-sdk": "^0.0.104"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@biomejs/biome": "2.4.6",
|
|
49
|
+
"@opentabs-dev/plugin-tools": "^0.0.104",
|
|
50
|
+
"jiti": "^2.6.1",
|
|
51
|
+
"typescript": "^5.9.3",
|
|
52
|
+
"zod": "^4.3.6"
|
|
53
|
+
},
|
|
54
|
+
"license": "MIT",
|
|
55
|
+
"repository": {
|
|
56
|
+
"type": "git",
|
|
57
|
+
"url": "https://github.com/opentabs-dev/opentabs.git",
|
|
58
|
+
"directory": "plugins/prescript-test"
|
|
59
|
+
}
|
|
60
|
+
}
|