toolcraft 0.0.92 → 0.0.93

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 (60) hide show
  1. package/composition.json +1 -6
  2. package/dist/composition.json +1 -6
  3. package/node_modules/@poe-code/agent-defs/package.json +9 -5
  4. package/node_modules/@poe-code/agent-human-in-loop/package.json +8 -4
  5. package/node_modules/@poe-code/agent-mcp-config/package.json +8 -4
  6. package/node_modules/@poe-code/config-mutations/package.json +8 -4
  7. package/node_modules/@poe-code/frontmatter/package.json +8 -4
  8. package/node_modules/@poe-code/process-runner/package.json +8 -4
  9. package/node_modules/@poe-code/task-list/package.json +8 -4
  10. package/node_modules/auth-store/package.json +3 -4
  11. package/node_modules/tiny-mcp-client/.turbo/turbo-build.log +1 -1
  12. package/node_modules/tiny-mcp-client/dist/index.d.ts +660 -2
  13. package/node_modules/tiny-mcp-client/dist/index.js +3870 -1
  14. package/node_modules/tiny-mcp-client/package.json +8 -4
  15. package/node_modules/tiny-mcp-client/scripts/build.mjs +63 -0
  16. package/node_modules/toolcraft-design/package.json +3 -7
  17. package/package.json +4 -6
  18. package/node_modules/mcp-oauth/LICENSE +0 -21
  19. package/node_modules/mcp-oauth/README.md +0 -31
  20. package/node_modules/mcp-oauth/dist/client/auth-store-session-store.d.ts +0 -14
  21. package/node_modules/mcp-oauth/dist/client/auth-store-session-store.js +0 -169
  22. package/node_modules/mcp-oauth/dist/client/authorization-state.d.ts +0 -8
  23. package/node_modules/mcp-oauth/dist/client/authorization-state.js +0 -47
  24. package/node_modules/mcp-oauth/dist/client/default-oauth-client-provider.d.ts +0 -3
  25. package/node_modules/mcp-oauth/dist/client/default-oauth-client-provider.js +0 -627
  26. package/node_modules/mcp-oauth/dist/client/loopback-authorization.d.ts +0 -20
  27. package/node_modules/mcp-oauth/dist/client/loopback-authorization.js +0 -207
  28. package/node_modules/mcp-oauth/dist/client/pkce.d.ts +0 -2
  29. package/node_modules/mcp-oauth/dist/client/pkce.js +0 -7
  30. package/node_modules/mcp-oauth/dist/client/token-endpoint.d.ts +0 -40
  31. package/node_modules/mcp-oauth/dist/client/token-endpoint.js +0 -164
  32. package/node_modules/mcp-oauth/dist/client/types.d.ts +0 -113
  33. package/node_modules/mcp-oauth/dist/client/types.js +0 -1
  34. package/node_modules/mcp-oauth/dist/index.d.ts +0 -10
  35. package/node_modules/mcp-oauth/dist/index.js +0 -7
  36. package/node_modules/mcp-oauth/dist/resource-indicator.d.ts +0 -1
  37. package/node_modules/mcp-oauth/dist/resource-indicator.js +0 -11
  38. package/node_modules/mcp-oauth/dist/server/jwks-token-verifier.d.ts +0 -28
  39. package/node_modules/mcp-oauth/dist/server/jwks-token-verifier.js +0 -304
  40. package/node_modules/mcp-oauth/dist/types.compile-check.d.ts +0 -1
  41. package/node_modules/mcp-oauth/dist/types.compile-check.js +0 -22
  42. package/node_modules/mcp-oauth/package.json +0 -32
  43. package/node_modules/tiny-mcp-client/dist/internal.d.ts +0 -556
  44. package/node_modules/tiny-mcp-client/dist/internal.js +0 -2688
  45. package/node_modules/tiny-mcp-client/dist/jsonrpc-types.compile-check.d.ts +0 -1
  46. package/node_modules/tiny-mcp-client/dist/jsonrpc-types.compile-check.js +0 -37
  47. package/node_modules/tiny-mcp-client/dist/mcp-lifecycle-types.compile-check.d.ts +0 -1
  48. package/node_modules/tiny-mcp-client/dist/mcp-lifecycle-types.compile-check.js +0 -50
  49. package/node_modules/tiny-mcp-client/dist/mcp-prompt-types.compile-check.d.ts +0 -1
  50. package/node_modules/tiny-mcp-client/dist/mcp-prompt-types.compile-check.js +0 -50
  51. package/node_modules/tiny-mcp-client/dist/mcp-resource-types.compile-check.d.ts +0 -1
  52. package/node_modules/tiny-mcp-client/dist/mcp-resource-types.compile-check.js +0 -51
  53. package/node_modules/tiny-mcp-client/dist/mcp-tool-types.compile-check.d.ts +0 -1
  54. package/node_modules/tiny-mcp-client/dist/mcp-tool-types.compile-check.js +0 -99
  55. package/node_modules/tiny-mcp-client/dist/mcp-transport-types.compile-check.d.ts +0 -1
  56. package/node_modules/tiny-mcp-client/dist/mcp-transport-types.compile-check.js +0 -56
  57. package/node_modules/tiny-mcp-client/dist/mcp-utility-types.compile-check.d.ts +0 -1
  58. package/node_modules/tiny-mcp-client/dist/mcp-utility-types.compile-check.js +0 -145
  59. package/node_modules/tiny-mcp-client/dist/oauth-discovery.d.ts +0 -24
  60. package/node_modules/tiny-mcp-client/dist/oauth-discovery.js +0 -382
@@ -1,13 +1,11 @@
1
1
  {
2
- "name": "tiny-mcp-client",
3
- "version": "0.1.0",
4
- "license": "MIT",
5
2
  "private": true,
3
+ "license": "MIT",
6
4
  "type": "module",
7
5
  "main": "./dist/index.js",
8
6
  "types": "./dist/index.d.ts",
9
7
  "scripts": {
10
- "build": "node ../../scripts/guard-package-dist.mjs && tsc"
8
+ "build": "node scripts/build.mjs"
11
9
  },
12
10
  "repository": {
13
11
  "type": "git",
@@ -16,6 +14,12 @@
16
14
  },
17
15
  "devDependencies": {
18
16
  "@modelcontextprotocol/sdk": "^1.26.0",
17
+ "mcp-oauth": "*",
19
18
  "tiny-stdio-mcp-server": "*"
19
+ },
20
+ "poeCode": {
21
+ "inlinedDependencies": [
22
+ "mcp-oauth"
23
+ ]
20
24
  }
21
25
  }
@@ -0,0 +1,63 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { createRequire } from "node:module";
3
+ import { cp, mkdir, mkdtemp, rm } from "node:fs/promises";
4
+ import os from "node:os";
5
+ import path from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+ import { build } from "esbuild";
8
+ import { rollup } from "rollup";
9
+ import { dts } from "rollup-plugin-dts";
10
+ import { assertSafeOutputDirectory } from "../../../scripts/guard-package-dist.mjs";
11
+
12
+ const require = createRequire(import.meta.url);
13
+ const packageDir = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
14
+ const packagesDir = path.dirname(packageDir);
15
+ const distDir = path.join(packageDir, "dist");
16
+ const temporaryDir = await mkdtemp(path.join(os.tmpdir(), "tiny-mcp-client-build-"));
17
+
18
+ const declarationAliases = new Map([
19
+ ["mcp-oauth", path.join(packagesDir, "mcp-oauth", "dist", "index.d.ts")],
20
+ ["auth-store", path.join(packagesDir, "auth-store", "dist", "index.d.ts")]
21
+ ]);
22
+
23
+ const inlineWorkspaceDeclarations = {
24
+ name: "inline-workspace-declarations",
25
+ resolveId(source) {
26
+ return declarationAliases.get(source) ?? null;
27
+ }
28
+ };
29
+
30
+ try {
31
+ await assertSafeOutputDirectory(packageDir, distDir);
32
+ await rm(distDir, { recursive: true, force: true });
33
+ execFileSync(
34
+ process.execPath,
35
+ [require.resolve("typescript/bin/tsc"), "--emitDeclarationOnly"],
36
+ { cwd: packageDir, stdio: "inherit" }
37
+ );
38
+
39
+ const declarationBundle = await rollup({
40
+ input: path.join(distDir, "index.d.ts"),
41
+ external: (source) => source.startsWith("node:"),
42
+ plugins: [inlineWorkspaceDeclarations, dts()]
43
+ });
44
+ await declarationBundle.write({
45
+ file: path.join(temporaryDir, "index.d.ts"),
46
+ format: "es"
47
+ });
48
+ await declarationBundle.close();
49
+
50
+ await rm(distDir, { recursive: true, force: true });
51
+ await mkdir(distDir, { recursive: true });
52
+ await build({
53
+ entryPoints: [path.join(packageDir, "src", "index.ts")],
54
+ outfile: path.join(distDir, "index.js"),
55
+ bundle: true,
56
+ format: "esm",
57
+ platform: "node",
58
+ target: "node18"
59
+ });
60
+ await cp(path.join(temporaryDir, "index.d.ts"), path.join(distDir, "index.d.ts"));
61
+ } finally {
62
+ await rm(temporaryDir, { recursive: true, force: true });
63
+ }
@@ -1,8 +1,6 @@
1
1
  {
2
- "name": "toolcraft-design",
3
- "version": "0.0.2",
4
- "license": "MIT",
5
2
  "private": true,
3
+ "license": "MIT",
6
4
  "type": "module",
7
5
  "main": "dist/index.js",
8
6
  "types": "dist/index.d.ts",
@@ -18,7 +16,8 @@
18
16
  "generate:design-docs:all": "tsx scripts/generate-docs.ts all"
19
17
  },
20
18
  "files": [
21
- "dist"
19
+ "dist",
20
+ "LICENSE"
22
21
  ],
23
22
  "dependencies": {
24
23
  "fast-string-width": "^3.0.2",
@@ -46,8 +45,5 @@
46
45
  "type": "git",
47
46
  "url": "git+https://github.com/poe-platform/poe-code.git",
48
47
  "directory": "packages/toolcraft-design"
49
- },
50
- "publishConfig": {
51
- "access": "public"
52
48
  }
53
49
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcraft",
3
- "version": "0.0.92",
3
+ "version": "0.0.93",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -56,11 +56,11 @@
56
56
  "test": "cd ../.. && vitest run packages/toolcraft/src",
57
57
  "test:unit": "cd ../.. && vitest run packages/toolcraft/src",
58
58
  "lint": "cd ../.. && eslint packages/toolcraft/src --ext ts && tsc -p packages/toolcraft/tsconfig.json --noEmit",
59
- "prepack": "node ../../scripts/manage-bundled-workspace-deps.mjs prepare . toolcraft-design @poe-code/frontmatter @poe-code/agent-mcp-config @poe-code/agent-human-in-loop @poe-code/task-list @poe-code/agent-defs @poe-code/config-mutations @poe-code/process-runner tiny-mcp-client mcp-oauth auth-store",
60
- "postpack": "node ../../scripts/manage-bundled-workspace-deps.mjs cleanup . toolcraft-design @poe-code/frontmatter @poe-code/agent-mcp-config @poe-code/agent-human-in-loop @poe-code/task-list @poe-code/agent-defs @poe-code/config-mutations @poe-code/process-runner tiny-mcp-client mcp-oauth auth-store"
59
+ "prepack": "node ../../scripts/manage-bundled-workspace-deps.mjs prepare . toolcraft-design @poe-code/frontmatter @poe-code/agent-mcp-config @poe-code/agent-human-in-loop @poe-code/task-list @poe-code/agent-defs @poe-code/config-mutations @poe-code/process-runner tiny-mcp-client auth-store",
60
+ "postpack": "node ../../scripts/manage-bundled-workspace-deps.mjs cleanup . toolcraft-design @poe-code/frontmatter @poe-code/agent-mcp-config @poe-code/agent-human-in-loop @poe-code/task-list @poe-code/agent-defs @poe-code/config-mutations @poe-code/process-runner tiny-mcp-client auth-store"
61
61
  },
62
62
  "dependencies": {
63
- "toolcraft-schema": "0.0.92",
63
+ "toolcraft-schema": "0.0.93",
64
64
  "commander": "^13.1.0",
65
65
  "fast-string-width": "^3.0.2",
66
66
  "fast-wrap-ansi": "^0.2.0",
@@ -96,7 +96,6 @@
96
96
  "@poe-code/config-mutations",
97
97
  "@poe-code/process-runner",
98
98
  "tiny-mcp-client",
99
- "mcp-oauth",
100
99
  "auth-store"
101
100
  ],
102
101
  "optionalDependencies": {
@@ -109,7 +108,6 @@
109
108
  "@poe-code/config-mutations": "*",
110
109
  "@poe-code/process-runner": "*",
111
110
  "tiny-mcp-client": "*",
112
- "mcp-oauth": "*",
113
111
  "auth-store": "*"
114
112
  }
115
113
  }
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Poe Platform
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,31 +0,0 @@
1
- # mcp-oauth
2
-
3
- OAuth client primitives for MCP HTTP transports.
4
-
5
- ## Config
6
-
7
- `createDefaultOAuthClientProvider(options)` accepts:
8
-
9
- - `client`
10
- - `mode: "dynamic"` with optional `metadata`
11
- - `mode: "static"` with `clientId`, optional `clientSecret`, optional `metadata`
12
- - `browser.openBrowser(url)`
13
- - `browser.readLine()` optional
14
- - `browser.createServer()` optional
15
- - `browser.landingPage` optional
16
- - `sessionStore` optional
17
- - `authStore` optional `auth-store` backend config for the default session store
18
- - `now()` optional clock override
19
-
20
- `createJwksTokenVerifier(options)` accepts:
21
-
22
- - `jwksUrl`
23
- - `clockSkewSeconds` optional, defaults to `30`
24
- - `allowedAlgorithms` optional asymmetric allow-list
25
- - `fetch` optional override
26
-
27
- `createAuthStoreSessionStore(options)` accepts the standard `auth-store` config.
28
-
29
- ## Environment Variables
30
-
31
- None directly. When `authStore` is used, `auth-store` honors its own backend env var configuration.
@@ -1,14 +0,0 @@
1
- import { type CreateSecretStoreInput } from "auth-store";
2
- import type { OAuthSessionStore } from "./types.js";
3
- interface StoredOAuthClient {
4
- clientId: string;
5
- clientSecret?: string;
6
- }
7
- export interface OAuthClientStore {
8
- load(issuer: string): Promise<StoredOAuthClient | null>;
9
- save(issuer: string, client: StoredOAuthClient): Promise<void>;
10
- clear(issuer: string): Promise<void>;
11
- }
12
- export declare function createAuthStoreSessionStore(options?: CreateSecretStoreInput): OAuthSessionStore;
13
- export declare function createAuthStoreClientStore(options: CreateSecretStoreInput): OAuthClientStore;
14
- export {};
@@ -1,169 +0,0 @@
1
- import crypto from "node:crypto";
2
- import path from "node:path";
3
- import { createSecretStore } from "auth-store";
4
- import { canonicalizeResourceIndicator } from "../resource-indicator.js";
5
- const DEFAULT_FILE_SALT = "poe-code:mcp-oauth:v1";
6
- const DEFAULT_FILE_DIRECTORY = ".poe-code/mcp-oauth";
7
- const DEFAULT_KEYCHAIN_SERVICE = "poe-code-mcp-oauth";
8
- const DEFAULT_CLIENT_FILE_SALT = "poe-code:mcp-oauth:clients:v1";
9
- const DEFAULT_CLIENT_FILE_DIRECTORY = ".poe-code/mcp-oauth/clients";
10
- const DEFAULT_CLIENT_KEYCHAIN_SERVICE = "poe-code-mcp-oauth-clients";
11
- const MAX_JS_DATE_MS = 8_640_000_000_000_000;
12
- export function createAuthStoreSessionStore(options = {}) {
13
- return {
14
- async load(resource) {
15
- const store = createResourceSecretStore(resource, options);
16
- const value = await store.get();
17
- if (value === null) {
18
- return null;
19
- }
20
- const parsed = JSON.parse(value);
21
- if (isStoredOAuthSession(parsed)) {
22
- return parsed;
23
- }
24
- throw new Error("Stored OAuth session must match the expected shape");
25
- },
26
- async save(resource, session) {
27
- const store = createResourceSecretStore(resource, options);
28
- await store.set(JSON.stringify(session));
29
- },
30
- async clear(resource) {
31
- const store = createResourceSecretStore(resource, options);
32
- await store.delete();
33
- }
34
- };
35
- }
36
- export function createAuthStoreClientStore(options) {
37
- return {
38
- async load(issuer) {
39
- const store = createIssuerSecretStore(issuer, options);
40
- const value = await store.get();
41
- if (value === null) {
42
- return null;
43
- }
44
- const parsed = JSON.parse(value);
45
- const clientId = isObjectRecord(parsed) ? getOwnString(parsed, "clientId") : undefined;
46
- if (clientId !== undefined) {
47
- const client = { clientId };
48
- if (isObjectRecord(parsed) &&
49
- Object.prototype.hasOwnProperty.call(parsed, "clientSecret")) {
50
- client.clientSecret = getOwnEntry(parsed, "clientSecret");
51
- }
52
- return client;
53
- }
54
- throw new Error("Stored OAuth client must be a JSON object with clientId");
55
- },
56
- async save(issuer, client) {
57
- const store = createIssuerSecretStore(issuer, options);
58
- await store.set(JSON.stringify(client));
59
- },
60
- async clear(issuer) {
61
- const store = createIssuerSecretStore(issuer, options);
62
- await store.delete();
63
- }
64
- };
65
- }
66
- function createNamedSecretStore(key, options, defaults) {
67
- const hash = crypto.createHash("sha256").update(key).digest("hex");
68
- const configuredFilePath = options.fileStore?.filePath;
69
- const parsedFilePath = configuredFilePath === undefined ? null : path.parse(configuredFilePath);
70
- const fileStore = {
71
- ...options.fileStore,
72
- filePath: parsedFilePath === null
73
- ? undefined
74
- : path.join(parsedFilePath.dir, `${parsedFilePath.name}-${hash}${parsedFilePath.ext || ".enc"}`),
75
- salt: options.fileStore?.salt ?? defaults.salt,
76
- defaultDirectory: options.fileStore?.defaultDirectory || defaults.directory,
77
- defaultFileName: parsedFilePath === null
78
- ? `${hash}.enc`
79
- : `${parsedFilePath.name}-${hash}${parsedFilePath.ext || ".enc"}`
80
- };
81
- const keychainStore = {
82
- ...options.keychainStore,
83
- service: options.keychainStore?.service ?? defaults.service,
84
- account: `${options.keychainStore?.account ?? defaults.accountPrefix}:${hash}`
85
- };
86
- return createSecretStore({ ...options, fileStore, keychainStore }).store;
87
- }
88
- function createResourceSecretStore(resource, options) {
89
- return createNamedSecretStore(canonicalizeResourceIndicator(resource), options, {
90
- salt: DEFAULT_FILE_SALT,
91
- directory: DEFAULT_FILE_DIRECTORY,
92
- service: DEFAULT_KEYCHAIN_SERVICE,
93
- accountPrefix: "provider"
94
- });
95
- }
96
- function createIssuerSecretStore(issuer, options) {
97
- return createNamedSecretStore(issuer, options, {
98
- salt: DEFAULT_CLIENT_FILE_SALT,
99
- directory: DEFAULT_CLIENT_FILE_DIRECTORY,
100
- service: DEFAULT_CLIENT_KEYCHAIN_SERVICE,
101
- accountPrefix: "issuer"
102
- });
103
- }
104
- function isObjectRecord(value) {
105
- return typeof value === "object" && value !== null && !Array.isArray(value);
106
- }
107
- function getOwnEntry(record, key) {
108
- return Object.prototype.hasOwnProperty.call(record, key) ? record[key] : undefined;
109
- }
110
- function getOwnString(record, key) {
111
- const value = getOwnEntry(record, key);
112
- return typeof value === "string" ? value : undefined;
113
- }
114
- function isStoredOAuthSession(value) {
115
- if (!isObjectRecord(value)) {
116
- return false;
117
- }
118
- return (isNonBlankOwnString(value, "resource") &&
119
- isNonBlankOwnString(value, "authorizationServer") &&
120
- isStoredOAuthClient(getOwnEntry(value, "client")) &&
121
- isStoredOAuthDiscovery(getOwnEntry(value, "discovery")) &&
122
- isStoredOAuthTokensOrMissing(getOwnEntry(value, "tokens")));
123
- }
124
- function isStoredOAuthClient(value) {
125
- if (!isObjectRecord(value) || !isNonBlankOwnString(value, "clientId")) {
126
- return false;
127
- }
128
- const clientSecret = getOwnEntry(value, "clientSecret");
129
- return (clientSecret === undefined ||
130
- (typeof clientSecret === "string" && clientSecret.trim().length > 0));
131
- }
132
- function isStoredOAuthDiscovery(value) {
133
- if (!isObjectRecord(value)) {
134
- return false;
135
- }
136
- return (isNonBlankOwnString(value, "resourceMetadataUrl") &&
137
- isObjectRecord(getOwnEntry(value, "resourceMetadata")) &&
138
- isObjectRecord(getOwnEntry(value, "authorizationServerMetadata")));
139
- }
140
- function isStoredOAuthTokensOrMissing(value) {
141
- if (value === undefined) {
142
- return true;
143
- }
144
- if (!isObjectRecord(value)) {
145
- return false;
146
- }
147
- if (!isNonBlankOwnString(value, "accessToken") || getOwnString(value, "tokenType") !== "Bearer") {
148
- return false;
149
- }
150
- const expiresAt = getOwnEntry(value, "expiresAt");
151
- if (expiresAt !== null &&
152
- (typeof expiresAt !== "number" ||
153
- !Number.isSafeInteger(expiresAt) ||
154
- expiresAt > MAX_JS_DATE_MS ||
155
- !Number.isFinite(new Date(expiresAt).getTime()))) {
156
- return false;
157
- }
158
- const refreshToken = getOwnEntry(value, "refreshToken");
159
- if (refreshToken !== undefined &&
160
- (typeof refreshToken !== "string" || refreshToken.trim().length === 0)) {
161
- return false;
162
- }
163
- const scope = getOwnEntry(value, "scope");
164
- return scope === undefined || (typeof scope === "string" && scope.trim().length > 0);
165
- }
166
- function isNonBlankOwnString(record, key) {
167
- const value = getOwnString(record, key);
168
- return value !== undefined && value.trim().length > 0;
169
- }
@@ -1,8 +0,0 @@
1
- export declare function createAuthorizationState(input: {
2
- issuer: string;
3
- requireIssuer: boolean;
4
- }): string;
5
- export declare function parseAuthorizationState(value: string | null): {
6
- issuer: string;
7
- requireIssuer: boolean;
8
- } | null;
@@ -1,47 +0,0 @@
1
- import crypto from "node:crypto";
2
- export function createAuthorizationState(input) {
3
- const payload = {
4
- v: 1,
5
- n: crypto.randomBytes(16).toString("base64url"),
6
- i: input.issuer,
7
- r: input.requireIssuer,
8
- };
9
- return Buffer.from(JSON.stringify(payload), "utf8").toString("base64url");
10
- }
11
- export function parseAuthorizationState(value) {
12
- if (value === null || value.length === 0) {
13
- return null;
14
- }
15
- try {
16
- const decoded = Buffer.from(value, "base64url").toString("utf8");
17
- const parsed = JSON.parse(decoded);
18
- if (!isObjectRecord(parsed)) {
19
- return null;
20
- }
21
- const version = getOwnEntry(parsed, "v");
22
- const nonce = getOwnEntry(parsed, "n");
23
- const issuer = getOwnEntry(parsed, "i");
24
- const requireIssuer = getOwnEntry(parsed, "r");
25
- if (version !== 1
26
- || typeof nonce !== "string"
27
- || nonce.length === 0
28
- || typeof issuer !== "string"
29
- || issuer.length === 0
30
- || typeof requireIssuer !== "boolean") {
31
- return null;
32
- }
33
- return {
34
- issuer,
35
- requireIssuer,
36
- };
37
- }
38
- catch {
39
- return null;
40
- }
41
- }
42
- function isObjectRecord(value) {
43
- return typeof value === "object" && value !== null && !Array.isArray(value);
44
- }
45
- function getOwnEntry(record, key) {
46
- return Object.prototype.hasOwnProperty.call(record, key) ? record[key] : undefined;
47
- }
@@ -1,3 +0,0 @@
1
- import type { DefaultOAuthClientProviderOptions, OAuthClientProvider, OAuthClientProviderOptions } from "./types.js";
2
- export declare function createOAuthClientProvider(options: OAuthClientProviderOptions): OAuthClientProvider;
3
- export declare function createDefaultOAuthClientProvider(options: DefaultOAuthClientProviderOptions): OAuthClientProvider;