windmill-client 1.326.1 → 1.327.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 ADDED
@@ -0,0 +1,9 @@
1
+ # Windmill Client
2
+
3
+ The SDK for the Windmill API.
4
+
5
+ ```
6
+ import * as wmill from 'windmill-client';
7
+
8
+ await wmill.getVariable('u/foo/my_variable')
9
+ ```
package/dist/client.js CHANGED
@@ -27,7 +27,6 @@ Object.defineProperty(exports, "SettingsService", { enumerable: true, get: funct
27
27
  Object.defineProperty(exports, "UserService", { enumerable: true, get: function () { return index_3.UserService; } });
28
28
  Object.defineProperty(exports, "WorkspaceService", { enumerable: true, get: function () { return index_3.WorkspaceService; } });
29
29
  exports.SHARED_FOLDER = "/shared";
30
- let clientSet = false;
31
30
  function setClient(token, baseUrl) {
32
31
  var _a, _b, _c;
33
32
  if (baseUrl === undefined) {
@@ -40,16 +39,16 @@ function setClient(token, baseUrl) {
40
39
  index_2.OpenAPI.WITH_CREDENTIALS = true;
41
40
  index_2.OpenAPI.TOKEN = token;
42
41
  index_2.OpenAPI.BASE = baseUrl + "/api";
43
- clientSet = true;
44
42
  }
45
43
  exports.setClient = setClient;
46
44
  const getEnv = (key) => {
45
+ var _a, _b, _c;
47
46
  if (typeof window === "undefined") {
48
47
  // node
49
- return process.env[key];
48
+ return (_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a[key];
50
49
  }
51
50
  // browser
52
- return window.process.env[key];
51
+ return (_c = (_b = window === null || window === void 0 ? void 0 : window.process) === null || _b === void 0 ? void 0 : _b.env) === null || _c === void 0 ? void 0 : _c[key];
53
52
  };
54
53
  /**
55
54
  * Create a client configuration from env variables
@@ -68,7 +67,6 @@ exports.getWorkspace = getWorkspace;
68
67
  */
69
68
  function getResource(path, undefinedIfEmpty) {
70
69
  return __awaiter(this, void 0, void 0, function* () {
71
- !clientSet && setClient();
72
70
  const workspace = getWorkspace();
73
71
  path = path !== null && path !== void 0 ? path : getStatePath();
74
72
  try {
@@ -95,7 +93,6 @@ exports.getResource = getResource;
95
93
  */
96
94
  function getRootJobId(jobId) {
97
95
  return __awaiter(this, void 0, void 0, function* () {
98
- !clientSet && setClient();
99
96
  const workspace = getWorkspace();
100
97
  jobId = jobId !== null && jobId !== void 0 ? jobId : getEnv("WM_JOB_ID");
101
98
  if (jobId === undefined) {
@@ -147,7 +144,6 @@ function waitJob(jobId_1) {
147
144
  exports.waitJob = waitJob;
148
145
  function getResult(jobId) {
149
146
  return __awaiter(this, void 0, void 0, function* () {
150
- !clientSet && setClient();
151
147
  const workspace = getWorkspace();
152
148
  return yield index_1.JobService.getCompletedJobResult({ workspace, id: jobId });
153
149
  });
@@ -155,7 +151,6 @@ function getResult(jobId) {
155
151
  exports.getResult = getResult;
156
152
  function getResultMaybe(jobId) {
157
153
  return __awaiter(this, void 0, void 0, function* () {
158
- !clientSet && setClient();
159
154
  const workspace = getWorkspace();
160
155
  return yield index_1.JobService.getCompletedJobResultMaybe({ workspace, id: jobId });
161
156
  });
@@ -173,7 +168,6 @@ function getParamNames(func) {
173
168
  return result;
174
169
  }
175
170
  function task(f) {
176
- !clientSet && setClient();
177
171
  return (...y) => __awaiter(this, void 0, void 0, function* () {
178
172
  const args = {};
179
173
  const paramNames = getParamNames(f);
@@ -196,7 +190,6 @@ function task(f) {
196
190
  exports.task = task;
197
191
  function runScriptAsync(path_1, hash_1, args_1) {
198
192
  return __awaiter(this, arguments, void 0, function* (path, hash_, args, scheduledInSeconds = null) {
199
- !clientSet && setClient();
200
193
  // Create a script job and return its job id.
201
194
  if (path && hash_) {
202
195
  throw new Error("path and hash_ are mutually exclusive");
@@ -270,7 +263,6 @@ exports.getStatePath = getStatePath;
270
263
  */
271
264
  function setResource(value, path, initializeToTypeIfNotExist) {
272
265
  return __awaiter(this, void 0, void 0, function* () {
273
- !clientSet && setClient();
274
266
  path = path !== null && path !== void 0 ? path : getStatePath();
275
267
  const workspace = getWorkspace();
276
268
  if (yield index_1.ResourceService.existsResource({ workspace, path })) {
@@ -321,7 +313,6 @@ exports.setState = setState;
321
313
  */
322
314
  function setFlowUserState(key, value, errorIfNotPossible) {
323
315
  return __awaiter(this, void 0, void 0, function* () {
324
- !clientSet && setClient();
325
316
  if (value === undefined) {
326
317
  value = null;
327
318
  }
@@ -352,7 +343,6 @@ exports.setFlowUserState = setFlowUserState;
352
343
  */
353
344
  function getFlowUserState(key, errorIfNotPossible) {
354
345
  return __awaiter(this, void 0, void 0, function* () {
355
- !clientSet && setClient();
356
346
  const workspace = getWorkspace();
357
347
  try {
358
348
  return yield index_1.JobService.getFlowUserState({
@@ -415,7 +405,6 @@ exports.getState = getState;
415
405
  */
416
406
  function getVariable(path) {
417
407
  return __awaiter(this, void 0, void 0, function* () {
418
- !clientSet && setClient();
419
408
  const workspace = getWorkspace();
420
409
  try {
421
410
  return yield index_1.VariableService.getVariableValue({ workspace, path });
@@ -435,7 +424,6 @@ exports.getVariable = getVariable;
435
424
  */
436
425
  function setVariable(path, value, isSecretIfNotExist, descriptionIfNotExist) {
437
426
  return __awaiter(this, void 0, void 0, function* () {
438
- !clientSet && setClient();
439
427
  const workspace = getWorkspace();
440
428
  if (yield index_1.VariableService.existsVariable({ workspace, path })) {
441
429
  yield index_1.VariableService.updateVariable({
@@ -486,7 +474,6 @@ exports.databaseUrlFromResource = databaseUrlFromResource;
486
474
  // }
487
475
  function denoS3LightClientSettings(s3_resource_path) {
488
476
  return __awaiter(this, void 0, void 0, function* () {
489
- !clientSet && setClient();
490
477
  const workspace = getWorkspace();
491
478
  const s3Resource = yield index_1.HelpersService.s3ResourceInfo({
492
479
  workspace: workspace,
@@ -511,7 +498,6 @@ exports.denoS3LightClientSettings = denoS3LightClientSettings;
511
498
  */
512
499
  function loadS3File(s3object_1) {
513
500
  return __awaiter(this, arguments, void 0, function* (s3object, s3ResourcePath = undefined) {
514
- !clientSet && setClient();
515
501
  const fileContentBlob = yield loadS3FileStream(s3object, s3ResourcePath);
516
502
  if (fileContentBlob === undefined) {
517
503
  return undefined;
@@ -551,7 +537,6 @@ exports.loadS3File = loadS3File;
551
537
  */
552
538
  function loadS3FileStream(s3object_1) {
553
539
  return __awaiter(this, arguments, void 0, function* (s3object, s3ResourcePath = undefined) {
554
- !clientSet && setClient();
555
540
  let params = {};
556
541
  params["file_key"] = s3object.s3;
557
542
  if (s3ResourcePath !== undefined) {
@@ -580,7 +565,6 @@ exports.loadS3FileStream = loadS3FileStream;
580
565
  */
581
566
  function writeS3File(s3object_1, fileContent_1) {
582
567
  return __awaiter(this, arguments, void 0, function* (s3object, fileContent, s3ResourcePath = undefined) {
583
- !clientSet && setClient();
584
568
  let fileContentBlob;
585
569
  if (typeof fileContent === "string") {
586
570
  fileContentBlob = new Blob([fileContent], {
@@ -612,7 +596,6 @@ function getResumeUrls(approver) {
612
596
  return __awaiter(this, void 0, void 0, function* () {
613
597
  var _a;
614
598
  const nonce = Math.floor(Math.random() * 4294967295);
615
- !clientSet && setClient();
616
599
  const workspace = getWorkspace();
617
600
  return yield index_1.JobService.getResumeUrls({
618
601
  workspace,
@@ -637,7 +620,6 @@ exports.getResumeEndpoints = getResumeEndpoints;
637
620
  */
638
621
  function getIdToken(audience) {
639
622
  return __awaiter(this, void 0, void 0, function* () {
640
- !clientSet && setClient();
641
623
  const workspace = getWorkspace();
642
624
  return yield index_1.OidcService.getOidcToken({
643
625
  workspace,
@@ -1,6 +1,18 @@
1
1
  "use strict";
2
+ var _a, _b;
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.OpenAPI = exports.Interceptors = void 0;
5
+ const getEnv = (key) => {
6
+ var _a, _b, _c;
7
+ if (typeof window === "undefined") {
8
+ // node
9
+ return (_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a[key];
10
+ }
11
+ // browser
12
+ return (_c = (_b = window === null || window === void 0 ? void 0 : window.process) === null || _b === void 0 ? void 0 : _b.env) === null || _c === void 0 ? void 0 : _c[key];
13
+ };
14
+ const baseUrl = (_b = (_a = getEnv("BASE_INTERNAL_URL")) !== null && _a !== void 0 ? _a : getEnv("BASE_URL")) !== null && _b !== void 0 ? _b : "http://localhost:8000";
15
+ const baseUrlApi = (baseUrl !== null && baseUrl !== void 0 ? baseUrl : '') + "/api";
4
16
  class Interceptors {
5
17
  constructor() {
6
18
  this._fns = [];
@@ -17,15 +29,15 @@ class Interceptors {
17
29
  }
18
30
  exports.Interceptors = Interceptors;
19
31
  exports.OpenAPI = {
20
- BASE: '/api',
32
+ BASE: baseUrlApi,
21
33
  CREDENTIALS: 'include',
22
34
  ENCODE_PATH: undefined,
23
35
  HEADERS: undefined,
24
36
  PASSWORD: undefined,
25
- TOKEN: undefined,
37
+ TOKEN: getEnv("WM_TOKEN"),
26
38
  USERNAME: undefined,
27
- VERSION: '1.326.1',
28
- WITH_CREDENTIALS: false,
39
+ VERSION: '1.327.0',
40
+ WITH_CREDENTIALS: true,
29
41
  interceptors: {
30
42
  request: new Interceptors(),
31
43
  response: new Interceptors(),
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "windmill-client",
3
3
  "description": "Windmill SDK client for browsers and Node.js",
4
- "version": "1.326.1",
4
+ "version": "1.327.0",
5
5
  "author": "Ruben Fiszel",
6
6
  "license": "Apache 2.0",
7
7
  "devDependencies": {
8
8
  "@types/node": "^20.4.10",
9
+ "dts-bundle-generator": "^9.5.1",
10
+ "esbuild": "^0.21.1",
9
11
  "typescript": "^5.4.5"
10
12
  },
11
13
  "main": "dist/index.js",