@kamilio/wire 0.1.3 → 0.1.4

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 (47) hide show
  1. package/dist/auth.d.ts.map +1 -1
  2. package/dist/auth.js +3 -10
  3. package/dist/auth.js.map +1 -1
  4. package/dist/executable.d.ts.map +1 -1
  5. package/dist/executable.js +33 -8
  6. package/dist/executable.js.map +1 -1
  7. package/dist/hooks.d.ts.map +1 -1
  8. package/dist/hooks.js +18 -7
  9. package/dist/hooks.js.map +1 -1
  10. package/node_modules/provider-chatgpt/dist/chatgpt.d.ts.map +1 -1
  11. package/node_modules/provider-chatgpt/dist/chatgpt.js +22 -3
  12. package/node_modules/provider-chatgpt/dist/chatgpt.js.map +1 -1
  13. package/node_modules/provider-chatgpt/src/chatgpt.ts +20 -3
  14. package/node_modules/provider-gmail/dist/gmail.d.ts.map +1 -1
  15. package/node_modules/provider-gmail/dist/gmail.js +2 -0
  16. package/node_modules/provider-gmail/dist/gmail.js.map +1 -1
  17. package/node_modules/provider-gmail/src/gmail.ts +1 -0
  18. package/node_modules/provider-google-docs/dist/google-docs.d.ts.map +1 -1
  19. package/node_modules/provider-google-docs/dist/google-docs.js +9 -6
  20. package/node_modules/provider-google-docs/dist/google-docs.js.map +1 -1
  21. package/node_modules/provider-google-docs/src/google-docs.ts +10 -7
  22. package/node_modules/provider-notion/dist/notion-sync.d.ts +1 -1
  23. package/node_modules/provider-notion/dist/notion-sync.d.ts.map +1 -1
  24. package/node_modules/provider-notion/dist/notion-sync.js +41 -12
  25. package/node_modules/provider-notion/dist/notion-sync.js.map +1 -1
  26. package/node_modules/provider-notion/dist/notion.js +1 -1
  27. package/node_modules/provider-notion/dist/notion.js.map +1 -1
  28. package/node_modules/provider-notion/src/notion-sync.ts +41 -12
  29. package/node_modules/provider-notion/src/notion.ts +1 -1
  30. package/node_modules/wire-core/dist/core/transform.d.ts +1 -0
  31. package/node_modules/wire-core/dist/core/transform.d.ts.map +1 -1
  32. package/node_modules/wire-core/dist/core/transform.js +4 -0
  33. package/node_modules/wire-core/dist/core/transform.js.map +1 -1
  34. package/node_modules/wire-core/dist/operations.d.ts.map +1 -1
  35. package/node_modules/wire-core/dist/operations.js +8 -6
  36. package/node_modules/wire-core/dist/operations.js.map +1 -1
  37. package/node_modules/wire-core/dist/runtime/chrome.d.ts +1 -0
  38. package/node_modules/wire-core/dist/runtime/chrome.d.ts.map +1 -1
  39. package/node_modules/wire-core/dist/runtime/chrome.js +64 -79
  40. package/node_modules/wire-core/dist/runtime/chrome.js.map +1 -1
  41. package/node_modules/wire-core/src/core/transform.ts +5 -1
  42. package/node_modules/wire-core/src/operations.ts +8 -6
  43. package/node_modules/wire-core/src/runtime/chrome.ts +69 -75
  44. package/package.json +1 -1
  45. package/src/auth.ts +3 -9
  46. package/src/executable.ts +33 -8
  47. package/src/hooks.ts +16 -6
package/src/executable.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { existsSync, readFileSync, statSync } from "node:fs";
2
2
  import { writeFile } from "node:fs/promises";
3
- import { dirname, join } from "node:path";
3
+ import { dirname, isAbsolute, join, resolve } from "node:path";
4
4
 
5
5
  import { createRoot } from "./adapters/root.js";
6
6
  import { composeAuth } from "./auth.js";
@@ -52,15 +52,21 @@ function loadConfiguredEnvironment(environment: NodeEnvironment, currentDirector
52
52
  return config.env === undefined ? environment : Object.freeze({ ...environment, ...config.env });
53
53
  }
54
54
 
55
+ function operationPath(value: string, path: string): string {
56
+ if (value.startsWith("http://") || value.startsWith("https://")) return path;
57
+ return isAbsolute(value) ? value : resolve(path, value);
58
+ }
59
+
55
60
  export function createExecutableRoot(environment: NodeEnvironment, currentDirectory: string, options = { allowPaste: true }) {
56
61
  const repositoryRoot = environment["WIRE_REPOSITORY_ROOT"] ?? discoverRepositoryRoot(currentDirectory);
57
62
  const baseEnvironment = repositoryRoot === undefined ? environment : Object.freeze({ ...environment, WIRE_REPOSITORY_ROOT: repositoryRoot });
58
- const resolvedEnvironment = loadConfiguredEnvironment(baseEnvironment, currentDirectory);
63
+ let activeConfigurationPath = currentDirectory;
64
+ const configuredEnvironment = () => loadConfiguredEnvironment(baseEnvironment, activeConfigurationPath);
59
65
  const http = createNodeHttp();
60
66
  const filesystem = createNodeFilesystem();
61
67
  const processCapability = createNodeProcess();
62
68
  const clock = createNodeClock();
63
- const configuration = createNodeConfiguration(resolvedEnvironment);
69
+ const configuration = Object.freeze({ get: (name: string) => createNodeConfiguration(configuredEnvironment()).get(name) });
64
70
  const home = configuration.get("HOME");
65
71
  const runtimeBase = {
66
72
  http,
@@ -69,14 +75,14 @@ export function createExecutableRoot(environment: NodeEnvironment, currentDirect
69
75
  clock,
70
76
  openFiles: createNodeOpenFiles(processCapability),
71
77
  configuration,
72
- secrets: createNodeSecrets(filesystem, resolvedEnvironment),
78
+ secrets: createNodeSecrets(filesystem, configuredEnvironment()),
73
79
  gmailTokens: Object.freeze({ load: () => createGoogleTokensCapability(filesystem, http, clock, configuration.get("GOOGLE_CREDENTIALS_FILE"), configuration.get("GOOGLE_TOKEN_FILE")).load(), refresh: () => createGoogleTokensCapability(filesystem, http, clock, configuration.get("GOOGLE_CREDENTIALS_FILE"), configuration.get("GOOGLE_TOKEN_FILE")).refresh() }),
74
80
  googleFormsTokens: Object.freeze({ load: () => createGoogleTokensCapability(filesystem, http, clock, configuration.get("GOOGLE_CREDENTIALS_FILE"), configuration.get("GOOGLE_FORMS_TOKEN_FILE")).load(), refresh: () => createGoogleTokensCapability(filesystem, http, clock, configuration.get("GOOGLE_CREDENTIALS_FILE"), configuration.get("GOOGLE_FORMS_TOKEN_FILE")).refresh() }),
75
81
  };
76
82
  let auth: ReturnType<typeof composeAuth>;
77
- const runtime = Object.freeze({ ...runtimeBase, cookies: createCookiesCapability(filesystem, () => home, () => resolvedEnvironment["WIRE_REPOSITORY_ROOT"]) });
78
- auth = composeAuth(runtime, resolvedEnvironment, extractChromeCookies);
79
- const wire = withWireHooks(composeWire({
83
+ const runtime = Object.freeze({ ...runtimeBase, cookies: createCookiesCapability(filesystem, () => home, () => configuredEnvironment()["WIRE_REPOSITORY_ROOT"]) });
84
+ auth = composeAuth(runtime, configuredEnvironment(), extractChromeCookies);
85
+ const baseWire = composeWire({
80
86
  home,
81
87
  fetchInput: runtime,
82
88
  catalog: serviceCatalog,
@@ -98,6 +104,25 @@ export function createExecutableRoot(environment: NodeEnvironment, currentDirect
98
104
  watch: createNodeWatch(),
99
105
  now: runtime.clock.now,
100
106
  open: runtime.openFiles.open,
101
- }), { currentDirectory, home, environment: resolvedEnvironment });
107
+ });
108
+ const configuredWire = Object.freeze({
109
+ ...baseWire,
110
+ attach: async (url: string, path: string) => { activeConfigurationPath = path; return baseWire.attach(url, path); },
111
+ create: async (url: string, path: string) => { activeConfigurationPath = path; return baseWire.create(url, path); },
112
+ view: async (url: string) => { activeConfigurationPath = currentDirectory; return baseWire.view(url); },
113
+ downloadSource: async (url: string, path: string) => { activeConfigurationPath = path; return baseWire.downloadSource(url, path); },
114
+ sync: async (value: string, path: string) => { activeConfigurationPath = operationPath(value, path); return baseWire.sync(value, path); },
115
+ download: async (value: string, path: string) => { activeConfigurationPath = operationPath(value, path); return baseWire.download(value, path); },
116
+ detach: async (value: string, path: string) => { activeConfigurationPath = operationPath(value, path); return baseWire.detach(value, path); },
117
+ unlink: async (value: string, path: string) => { activeConfigurationPath = operationPath(value, path); return baseWire.unlink(value, path); },
118
+ watch: async (value: string, path: string) => { activeConfigurationPath = operationPath(value, path); return baseWire.watch(value, path); },
119
+ openResource: async (value: string, path: string) => { activeConfigurationPath = operationPath(value, path); return baseWire.openResource(value, path); },
120
+ syncAll: async (path: string) => { activeConfigurationPath = path; return baseWire.syncAll(path); },
121
+ listResources: async (path: string) => { activeConfigurationPath = path; return baseWire.listResources(path); },
122
+ showResource: async (value: string, path: string) => { activeConfigurationPath = operationPath(value, path); return baseWire.showResource(value, path); },
123
+ init: baseWire.init,
124
+ switchBackend: baseWire.switchBackend,
125
+ });
126
+ const wire = withWireHooks(configuredWire, { currentDirectory, home, environment: configuredEnvironment() });
102
127
  return createRoot(wire, currentDirectory, auth, readStandardInput, options);
103
128
  }
package/src/hooks.ts CHANGED
@@ -5,7 +5,7 @@ import { dirname, isAbsolute, join, resolve } from "node:path";
5
5
  import { promisify } from "node:util";
6
6
 
7
7
  import type { Resource, Wire, WireResult } from "wire-core";
8
- import { configuredWireRoot, openWireRegistry, wireRelativePath } from "wire-core";
8
+ import { configuredWireRoot, loadWireConfig, openWireRegistry, wireRelativePath } from "wire-core";
9
9
  import type { WireWatchSyncHook } from "wire-core/internal/operations";
10
10
  import { wireWatchHooks } from "wire-core/internal/operations";
11
11
 
@@ -118,10 +118,18 @@ async function updateMovedResult(options: WireHookOptions, wireRoot: string, res
118
118
  { ...primary, path: relativePath },
119
119
  ],
120
120
  };
121
- if (result.summary.action !== "detached") await (await openWireRegistry(wireRoot, options.home)).put(resource);
121
+ if (result.summary.action !== "detached") {
122
+ const registry = await openWireRegistry(wireRoot, options.home);
123
+ if ((await registry.listResources()).some((item) => item.id === result.resource.id)) await registry.put(resource);
124
+ }
122
125
  return { ...result, resource, path: outputPath, summary: { ...result.summary, local: outputPath } };
123
126
  }
124
127
 
128
+ async function hookEnvironment(options: WireHookOptions, wireRoot: string): Promise<Record<string, string>> {
129
+ const config = await loadWireConfig(wireRoot);
130
+ return stringEnvironment({ ...options.environment, ...config.env });
131
+ }
132
+
125
133
  async function runHookCommands(wireRoot: string, event: WireHookEvent, environment: Readonly<Record<string, string>>): Promise<Record<string, string>> {
126
134
  let current = { ...environment };
127
135
  for (const path of await hookCommandPaths(wireRoot, event)) {
@@ -132,10 +140,11 @@ async function runHookCommands(wireRoot: string, event: WireHookEvent, environme
132
140
  }
133
141
 
134
142
  async function runResourceHooks(options: WireHookOptions, command: string, result: WireResult): Promise<HookState> {
135
- const wireRoot = (await configuredWireRoot(result.path, options.home))!;
143
+ const wireRoot = await configuredWireRoot(result.path, options.home);
144
+ if (wireRoot === null) return { result, environment: {} };
136
145
  let currentResult = result;
137
146
  let environment = {
138
- ...stringEnvironment(options.environment),
147
+ ...await hookEnvironment(options, wireRoot),
139
148
  ...resourceEnvironment(command, options.currentDirectory, wireRoot, currentResult),
140
149
  };
141
150
  for (const path of await hookCommandPaths(wireRoot, "post-resource")) {
@@ -152,9 +161,10 @@ async function runResourceHooks(options: WireHookOptions, command: string, resul
152
161
  }
153
162
 
154
163
  async function runSummaryHooks(options: WireHookOptions, event: WireHookEvent, command: string, rootPath: string, results: readonly WireResult[], environment: Readonly<Record<string, string>>): Promise<Record<string, string>> {
155
- const wireRoot = (await configuredWireRoot(rootPath, options.home))!;
164
+ const wireRoot = await configuredWireRoot(rootPath, options.home);
165
+ if (wireRoot === null) return {};
156
166
  return runHookCommands(wireRoot, event, {
157
- ...stringEnvironment(options.environment),
167
+ ...await hookEnvironment(options, wireRoot),
158
168
  ...environment,
159
169
  ...summaryEnvironment(event, command, options.currentDirectory, wireRoot, results),
160
170
  });