@diffbot/typescript 0.1.0 → 0.2.0
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 +142 -8
- package/dist/index.cjs +141 -71
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +111 -6
- package/dist/index.d.ts +111 -6
- package/dist/index.js +141 -45
- package/dist/index.js.map +1 -1
- package/dist/node/index.cjs +93 -0
- package/dist/node/index.cjs.map +1 -0
- package/dist/node/index.d.cts +27 -0
- package/dist/node/index.d.ts +27 -0
- package/dist/node/index.js +63 -0
- package/dist/node/index.js.map +1 -0
- package/package.json +10 -3
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TokenSource, OntologyStore, DiffbotClient, OntologyStoreOptions } from '@diffbot/typescript';
|
|
2
|
+
|
|
3
|
+
declare function defaultCredentialsPath(): string;
|
|
4
|
+
/** Mutable for tests; defaults to `~/.diffbot/credentials`. */
|
|
5
|
+
declare const authConfig: {
|
|
6
|
+
credentialsPath?: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Resolve a Diffbot API token from an explicit arg, an `env` object, then
|
|
10
|
+
* `process.env`, then `~/.diffbot/credentials`. Superset of the core
|
|
11
|
+
* `resolveTokenFromEnv` — same first three steps, plus the file fallback.
|
|
12
|
+
*/
|
|
13
|
+
declare function resolveToken(token?: string | null, env?: TokenSource): string;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Filesystem-backed ontology cache. Replaces the old `dqlRefreshOntology` +
|
|
17
|
+
* `Ontology.fromPath` pair with a single read-through cache, consistent with
|
|
18
|
+
* `KVOntologyStore` in core.
|
|
19
|
+
*/
|
|
20
|
+
declare class FileOntologyStore extends OntologyStore {
|
|
21
|
+
private readonly path;
|
|
22
|
+
constructor(client: DiffbotClient, path: string, options?: OntologyStoreOptions);
|
|
23
|
+
protected read(): Promise<string | undefined>;
|
|
24
|
+
protected write(text: string): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { FileOntologyStore, authConfig, defaultCredentialsPath, resolveToken };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// src/node/auth.ts
|
|
2
|
+
import { existsSync, readFileSync } from "fs";
|
|
3
|
+
import { homedir } from "os";
|
|
4
|
+
import { join } from "path";
|
|
5
|
+
import { resolveTokenFromEnv } from "@diffbot/typescript";
|
|
6
|
+
var TOKEN_ENV_VAR = "DIFFBOT_API_TOKEN";
|
|
7
|
+
function defaultCredentialsPath() {
|
|
8
|
+
return join(homedir(), ".diffbot", "credentials");
|
|
9
|
+
}
|
|
10
|
+
var authConfig = {};
|
|
11
|
+
function readCredentialsFile(path) {
|
|
12
|
+
if (!existsSync(path)) {
|
|
13
|
+
return "";
|
|
14
|
+
}
|
|
15
|
+
const text = readFileSync(path, "utf8");
|
|
16
|
+
for (const line of text.split("\n")) {
|
|
17
|
+
const trimmed = line.trim();
|
|
18
|
+
if (trimmed.startsWith(`${TOKEN_ENV_VAR}=`)) {
|
|
19
|
+
return trimmed.slice(TOKEN_ENV_VAR.length + 1).trim();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return "";
|
|
23
|
+
}
|
|
24
|
+
function resolveToken(token, env) {
|
|
25
|
+
const fromEnv = resolveTokenFromEnv(token, env);
|
|
26
|
+
if (fromEnv) {
|
|
27
|
+
return fromEnv;
|
|
28
|
+
}
|
|
29
|
+
return readCredentialsFile(authConfig.credentialsPath ?? defaultCredentialsPath());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/node/ontology-store.ts
|
|
33
|
+
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
34
|
+
import { dirname } from "path";
|
|
35
|
+
import { OntologyStore } from "@diffbot/typescript";
|
|
36
|
+
var FileOntologyStore = class extends OntologyStore {
|
|
37
|
+
path;
|
|
38
|
+
constructor(client, path, options) {
|
|
39
|
+
super(client, options);
|
|
40
|
+
this.path = path;
|
|
41
|
+
}
|
|
42
|
+
async read() {
|
|
43
|
+
try {
|
|
44
|
+
return await readFile(this.path, "utf8");
|
|
45
|
+
} catch (error) {
|
|
46
|
+
if (error.code === "ENOENT") {
|
|
47
|
+
return void 0;
|
|
48
|
+
}
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async write(text) {
|
|
53
|
+
await mkdir(dirname(this.path), { recursive: true });
|
|
54
|
+
await writeFile(this.path, text);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
export {
|
|
58
|
+
FileOntologyStore,
|
|
59
|
+
authConfig,
|
|
60
|
+
defaultCredentialsPath,
|
|
61
|
+
resolveToken
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/node/auth.ts","../../src/node/ontology-store.ts"],"sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { resolveTokenFromEnv, type TokenSource } from \"@diffbot/typescript\";\n\nconst TOKEN_ENV_VAR = \"DIFFBOT_API_TOKEN\";\n\nexport function defaultCredentialsPath(): string {\n return join(homedir(), \".diffbot\", \"credentials\");\n}\n\n/** Mutable for tests; defaults to `~/.diffbot/credentials`. */\nexport const authConfig: { credentialsPath?: string } = {};\n\nfunction readCredentialsFile(path: string): string {\n if (!existsSync(path)) {\n return \"\";\n }\n const text = readFileSync(path, \"utf8\");\n for (const line of text.split(\"\\n\")) {\n const trimmed = line.trim();\n if (trimmed.startsWith(`${TOKEN_ENV_VAR}=`)) {\n return trimmed.slice(TOKEN_ENV_VAR.length + 1).trim();\n }\n }\n return \"\";\n}\n\n/**\n * Resolve a Diffbot API token from an explicit arg, an `env` object, then\n * `process.env`, then `~/.diffbot/credentials`. Superset of the core\n * `resolveTokenFromEnv` — same first three steps, plus the file fallback.\n */\nexport function resolveToken(token?: string | null, env?: TokenSource): string {\n const fromEnv = resolveTokenFromEnv(token, env);\n if (fromEnv) {\n return fromEnv;\n }\n return readCredentialsFile(authConfig.credentialsPath ?? defaultCredentialsPath());\n}\n","import { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { dirname } from \"node:path\";\nimport { OntologyStore, type OntologyStoreOptions } from \"@diffbot/typescript\";\nimport type { DiffbotClient } from \"@diffbot/typescript\";\n\n/**\n * Filesystem-backed ontology cache. Replaces the old `dqlRefreshOntology` +\n * `Ontology.fromPath` pair with a single read-through cache, consistent with\n * `KVOntologyStore` in core.\n */\nexport class FileOntologyStore extends OntologyStore {\n private readonly path: string;\n\n constructor(client: DiffbotClient, path: string, options?: OntologyStoreOptions) {\n super(client, options);\n this.path = path;\n }\n\n protected override async read(): Promise<string | undefined> {\n try {\n return await readFile(this.path, \"utf8\");\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") {\n return undefined;\n }\n throw error;\n }\n }\n\n protected override async write(text: string): Promise<void> {\n await mkdir(dirname(this.path), { recursive: true });\n await writeFile(this.path, text);\n }\n}\n"],"mappings":";AAAA,SAAS,YAAY,oBAAoB;AACzC,SAAS,eAAe;AACxB,SAAS,YAAY;AACrB,SAAS,2BAA6C;AAEtD,IAAM,gBAAgB;AAEf,SAAS,yBAAiC;AAC/C,SAAO,KAAK,QAAQ,GAAG,YAAY,aAAa;AAClD;AAGO,IAAM,aAA2C,CAAC;AAEzD,SAAS,oBAAoB,MAAsB;AACjD,MAAI,CAAC,WAAW,IAAI,GAAG;AACrB,WAAO;AAAA,EACT;AACA,QAAM,OAAO,aAAa,MAAM,MAAM;AACtC,aAAW,QAAQ,KAAK,MAAM,IAAI,GAAG;AACnC,UAAM,UAAU,KAAK,KAAK;AAC1B,QAAI,QAAQ,WAAW,GAAG,aAAa,GAAG,GAAG;AAC3C,aAAO,QAAQ,MAAM,cAAc,SAAS,CAAC,EAAE,KAAK;AAAA,IACtD;AAAA,EACF;AACA,SAAO;AACT;AAOO,SAAS,aAAa,OAAuB,KAA2B;AAC7E,QAAM,UAAU,oBAAoB,OAAO,GAAG;AAC9C,MAAI,SAAS;AACX,WAAO;AAAA,EACT;AACA,SAAO,oBAAoB,WAAW,mBAAmB,uBAAuB,CAAC;AACnF;;;ACvCA,SAAS,OAAO,UAAU,iBAAiB;AAC3C,SAAS,eAAe;AACxB,SAAS,qBAAgD;AAQlD,IAAM,oBAAN,cAAgC,cAAc;AAAA,EAClC;AAAA,EAEjB,YAAY,QAAuB,MAAc,SAAgC;AAC/E,UAAM,QAAQ,OAAO;AACrB,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,MAAyB,OAAoC;AAC3D,QAAI;AACF,aAAO,MAAM,SAAS,KAAK,MAAM,MAAM;AAAA,IACzC,SAAS,OAAO;AACd,UAAK,MAAgC,SAAS,UAAU;AACtD,eAAO;AAAA,MACT;AACA,YAAM;AAAA,IACR;AAAA,EACF;AAAA,EAEA,MAAyB,MAAM,MAA6B;AAC1D,UAAM,MAAM,QAAQ,KAAK,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;AACnD,UAAM,UAAU,KAAK,MAAM,IAAI;AAAA,EACjC;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diffbot/typescript",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "TypeScript client library for Diffbot APIs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -11,7 +11,13 @@
|
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
12
|
"import": "./dist/index.js",
|
|
13
13
|
"require": "./dist/index.cjs"
|
|
14
|
-
}
|
|
14
|
+
},
|
|
15
|
+
"./node": {
|
|
16
|
+
"types": "./dist/node/index.d.ts",
|
|
17
|
+
"import": "./dist/node/index.js",
|
|
18
|
+
"require": "./dist/node/index.cjs"
|
|
19
|
+
},
|
|
20
|
+
"./package.json": "./package.json"
|
|
15
21
|
},
|
|
16
22
|
"files": [
|
|
17
23
|
"dist",
|
|
@@ -29,7 +35,8 @@
|
|
|
29
35
|
"test:watch": "vitest",
|
|
30
36
|
"test:live": "vitest run --config vitest.live.config.ts",
|
|
31
37
|
"test:coverage": "vitest run --coverage --coverage.include='src/**'",
|
|
32
|
-
"typecheck": "tsc --noEmit"
|
|
38
|
+
"typecheck": "tsc --noEmit",
|
|
39
|
+
"postbuild": "node scripts/assert-no-node-builtins.mjs"
|
|
33
40
|
},
|
|
34
41
|
"keywords": [
|
|
35
42
|
"diffbot",
|