@northflank/js-client 0.4.1 → 0.5.0-beta.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.
Files changed (257) hide show
  1. package/dist/cjs/api-client.d.ts +6013 -0
  2. package/dist/cjs/api-client.js +1 -0
  3. package/dist/cjs/package.json +3 -0
  4. package/dist/esm/api-client.d.ts +6013 -0
  5. package/dist/esm/api-client.js +15 -0
  6. package/dist/esm/package.json +3 -0
  7. package/package.json +12 -19
  8. package/dist/api-client.d.ts +0 -481
  9. package/dist/api-client.js +0 -748
  10. package/dist/api-endpoint.d.ts +0 -63
  11. package/dist/api-endpoint.js +0 -216
  12. package/dist/context/api-client-context-provider.d.ts +0 -47
  13. package/dist/context/api-client-context-provider.js +0 -332
  14. package/dist/context/api-client-file-context-provider.d.ts +0 -11
  15. package/dist/context/api-client-file-context-provider.js +0 -138
  16. package/dist/context/api-client-in-memory-context-provider.d.ts +0 -6
  17. package/dist/context/api-client-in-memory-context-provider.js +0 -82
  18. package/dist/context/index.d.ts +0 -3
  19. package/dist/context/index.js +0 -15
  20. package/dist/endpoints/abort/addon/backup.d.ts +0 -21
  21. package/dist/endpoints/abort/addon/backup.js +0 -36
  22. package/dist/endpoints/abort/addon/restore.d.ts +0 -26
  23. package/dist/endpoints/abort/addon/restore.js +0 -36
  24. package/dist/endpoints/abort/job/build.d.ts +0 -21
  25. package/dist/endpoints/abort/job/build.js +0 -36
  26. package/dist/endpoints/abort/job/run.d.ts +0 -21
  27. package/dist/endpoints/abort/job/run.js +0 -36
  28. package/dist/endpoints/abort/service/build.d.ts +0 -21
  29. package/dist/endpoints/abort/service/build.js +0 -36
  30. package/dist/endpoints/add/domain/subdomain.d.ts +0 -33
  31. package/dist/endpoints/add/domain/subdomain.js +0 -36
  32. package/dist/endpoints/add/registryCredentials.d.ts +0 -47
  33. package/dist/endpoints/add/registryCredentials.js +0 -36
  34. package/dist/endpoints/assign/subdomain/service.d.ts +0 -28
  35. package/dist/endpoints/assign/subdomain/service.js +0 -36
  36. package/dist/endpoints/backup/addon.d.ts +0 -51
  37. package/dist/endpoints/backup/addon.js +0 -36
  38. package/dist/endpoints/create/addon.d.ts +0 -90
  39. package/dist/endpoints/create/addon.js +0 -36
  40. package/dist/endpoints/create/domain.d.ts +0 -27
  41. package/dist/endpoints/create/domain.js +0 -36
  42. package/dist/endpoints/create/job/cron.d.ts +0 -157
  43. package/dist/endpoints/create/job/cron.js +0 -36
  44. package/dist/endpoints/create/job/manual.d.ts +0 -147
  45. package/dist/endpoints/create/job/manual.js +0 -36
  46. package/dist/endpoints/create/project.d.ts +0 -29
  47. package/dist/endpoints/create/project.js +0 -36
  48. package/dist/endpoints/create/secret.d.ts +0 -79
  49. package/dist/endpoints/create/secret.js +0 -36
  50. package/dist/endpoints/create/service/build.d.ts +0 -116
  51. package/dist/endpoints/create/service/build.js +0 -36
  52. package/dist/endpoints/create/service/combined.d.ts +0 -166
  53. package/dist/endpoints/create/service/combined.js +0 -36
  54. package/dist/endpoints/create/service/deployment.d.ts +0 -137
  55. package/dist/endpoints/create/service/deployment.js +0 -36
  56. package/dist/endpoints/delete/addon.d.ts +0 -19
  57. package/dist/endpoints/delete/addon.js +0 -36
  58. package/dist/endpoints/delete/backup.d.ts +0 -21
  59. package/dist/endpoints/delete/backup.js +0 -36
  60. package/dist/endpoints/delete/domain.d.ts +0 -17
  61. package/dist/endpoints/delete/domain.js +0 -36
  62. package/dist/endpoints/delete/job.d.ts +0 -19
  63. package/dist/endpoints/delete/job.js +0 -36
  64. package/dist/endpoints/delete/project.d.ts +0 -17
  65. package/dist/endpoints/delete/project.js +0 -36
  66. package/dist/endpoints/delete/registryCredentials.d.ts +0 -17
  67. package/dist/endpoints/delete/registryCredentials.js +0 -36
  68. package/dist/endpoints/delete/secret.d.ts +0 -19
  69. package/dist/endpoints/delete/secret.js +0 -36
  70. package/dist/endpoints/delete/secretLink.d.ts +0 -21
  71. package/dist/endpoints/delete/secretLink.js +0 -36
  72. package/dist/endpoints/delete/service.d.ts +0 -19
  73. package/dist/endpoints/delete/service.js +0 -36
  74. package/dist/endpoints/delete/subdomain.d.ts +0 -19
  75. package/dist/endpoints/delete/subdomain.js +0 -36
  76. package/dist/endpoints/get/addon/backup/download.d.ts +0 -24
  77. package/dist/endpoints/get/addon/backup/download.js +0 -36
  78. package/dist/endpoints/get/addon/backup.d.ts +0 -46
  79. package/dist/endpoints/get/addon/backup.js +0 -36
  80. package/dist/endpoints/get/addon/backups.d.ts +0 -54
  81. package/dist/endpoints/get/addon/backups.js +0 -40
  82. package/dist/endpoints/get/addon/containers.d.ts +0 -40
  83. package/dist/endpoints/get/addon/containers.js +0 -40
  84. package/dist/endpoints/get/addon/credentials.d.ts +0 -24
  85. package/dist/endpoints/get/addon/credentials.js +0 -36
  86. package/dist/endpoints/get/addon/types.d.ts +0 -48
  87. package/dist/endpoints/get/addon/types.js +0 -36
  88. package/dist/endpoints/get/addon/version.d.ts +0 -53
  89. package/dist/endpoints/get/addon/version.js +0 -36
  90. package/dist/endpoints/get/addon.d.ts +0 -69
  91. package/dist/endpoints/get/addon.js +0 -36
  92. package/dist/endpoints/get/dnsId.d.ts +0 -15
  93. package/dist/endpoints/get/dnsId.js +0 -36
  94. package/dist/endpoints/get/domain.d.ts +0 -33
  95. package/dist/endpoints/get/domain.js +0 -36
  96. package/dist/endpoints/get/job/buildArguments.d.ts +0 -19
  97. package/dist/endpoints/get/job/buildArguments.js +0 -36
  98. package/dist/endpoints/get/job/builds.d.ts +0 -50
  99. package/dist/endpoints/get/job/builds.js +0 -39
  100. package/dist/endpoints/get/job/containers.d.ts +0 -40
  101. package/dist/endpoints/get/job/containers.js +0 -40
  102. package/dist/endpoints/get/job/deployment.d.ts +0 -51
  103. package/dist/endpoints/get/job/deployment.js +0 -36
  104. package/dist/endpoints/get/job/environment.d.ts +0 -24
  105. package/dist/endpoints/get/job/environment.js +0 -40
  106. package/dist/endpoints/get/job/environmentDetails.d.ts +0 -42
  107. package/dist/endpoints/get/job/environmentDetails.js +0 -36
  108. package/dist/endpoints/get/job/healthChecks.d.ts +0 -44
  109. package/dist/endpoints/get/job/healthChecks.js +0 -36
  110. package/dist/endpoints/get/job/run.d.ts +0 -42
  111. package/dist/endpoints/get/job/run.js +0 -36
  112. package/dist/endpoints/get/job/runs.d.ts +0 -52
  113. package/dist/endpoints/get/job/runs.js +0 -39
  114. package/dist/endpoints/get/job.d.ts +0 -86
  115. package/dist/endpoints/get/job.js +0 -36
  116. package/dist/endpoints/get/project.d.ts +0 -72
  117. package/dist/endpoints/get/project.js +0 -36
  118. package/dist/endpoints/get/registryCredentials.d.ts +0 -34
  119. package/dist/endpoints/get/registryCredentials.js +0 -36
  120. package/dist/endpoints/get/secret.d.ts +0 -55
  121. package/dist/endpoints/get/secret.js +0 -39
  122. package/dist/endpoints/get/secretDetails.d.ts +0 -63
  123. package/dist/endpoints/get/secretDetails.js +0 -36
  124. package/dist/endpoints/get/secretLink.d.ts +0 -44
  125. package/dist/endpoints/get/secretLink.js +0 -36
  126. package/dist/endpoints/get/service/buildArguments.d.ts +0 -19
  127. package/dist/endpoints/get/service/buildArguments.js +0 -36
  128. package/dist/endpoints/get/service/builds.d.ts +0 -50
  129. package/dist/endpoints/get/service/builds.js +0 -40
  130. package/dist/endpoints/get/service/containers.d.ts +0 -40
  131. package/dist/endpoints/get/service/containers.js +0 -40
  132. package/dist/endpoints/get/service/deployment.d.ts +0 -51
  133. package/dist/endpoints/get/service/deployment.js +0 -36
  134. package/dist/endpoints/get/service/environmentVariableDetails.d.ts +0 -42
  135. package/dist/endpoints/get/service/environmentVariableDetails.js +0 -36
  136. package/dist/endpoints/get/service/environmentVariables.d.ts +0 -24
  137. package/dist/endpoints/get/service/environmentVariables.js +0 -40
  138. package/dist/endpoints/get/service/healthChecks.d.ts +0 -44
  139. package/dist/endpoints/get/service/healthChecks.js +0 -36
  140. package/dist/endpoints/get/service/ports.d.ts +0 -35
  141. package/dist/endpoints/get/service/ports.js +0 -36
  142. package/dist/endpoints/get/service.d.ts +0 -103
  143. package/dist/endpoints/get/service.js +0 -36
  144. package/dist/endpoints/get/subdomain.d.ts +0 -30
  145. package/dist/endpoints/get/subdomain.js +0 -36
  146. package/dist/endpoints/import/addon/backup.d.ts +0 -31
  147. package/dist/endpoints/import/addon/backup.js +0 -36
  148. package/dist/endpoints/list/addons.d.ts +0 -45
  149. package/dist/endpoints/list/addons.js +0 -39
  150. package/dist/endpoints/list/domains.d.ts +0 -34
  151. package/dist/endpoints/list/domains.js +0 -39
  152. package/dist/endpoints/list/jobs.d.ts +0 -44
  153. package/dist/endpoints/list/jobs.js +0 -39
  154. package/dist/endpoints/list/plans.d.ts +0 -30
  155. package/dist/endpoints/list/plans.js +0 -36
  156. package/dist/endpoints/list/projects.d.ts +0 -32
  157. package/dist/endpoints/list/projects.js +0 -39
  158. package/dist/endpoints/list/regions.d.ts +0 -18
  159. package/dist/endpoints/list/regions.js +0 -36
  160. package/dist/endpoints/list/registryCredentials.d.ts +0 -41
  161. package/dist/endpoints/list/registryCredentials.js +0 -39
  162. package/dist/endpoints/list/secrets.d.ts +0 -52
  163. package/dist/endpoints/list/secrets.js +0 -39
  164. package/dist/endpoints/list/services.d.ts +0 -44
  165. package/dist/endpoints/list/services.js +0 -39
  166. package/dist/endpoints/list/vcs.d.ts +0 -51
  167. package/dist/endpoints/list/vcs.js +0 -36
  168. package/dist/endpoints/pause/addon.d.ts +0 -19
  169. package/dist/endpoints/pause/addon.js +0 -36
  170. package/dist/endpoints/pause/service.d.ts +0 -19
  171. package/dist/endpoints/pause/service.js +0 -36
  172. package/dist/endpoints/restart/addon.d.ts +0 -19
  173. package/dist/endpoints/restart/addon.js +0 -36
  174. package/dist/endpoints/restart/service.d.ts +0 -19
  175. package/dist/endpoints/restart/service.js +0 -36
  176. package/dist/endpoints/restore/addon/backup.d.ts +0 -21
  177. package/dist/endpoints/restore/addon/backup.js +0 -36
  178. package/dist/endpoints/resume/addon.d.ts +0 -19
  179. package/dist/endpoints/resume/addon.js +0 -36
  180. package/dist/endpoints/resume/service.d.ts +0 -24
  181. package/dist/endpoints/resume/service.js +0 -36
  182. package/dist/endpoints/scale/addon.d.ts +0 -28
  183. package/dist/endpoints/scale/addon.js +0 -36
  184. package/dist/endpoints/scale/service.d.ts +0 -26
  185. package/dist/endpoints/scale/service.js +0 -36
  186. package/dist/endpoints/start/job/build.d.ts +0 -37
  187. package/dist/endpoints/start/job/build.js +0 -36
  188. package/dist/endpoints/start/job/run.d.ts +0 -37
  189. package/dist/endpoints/start/job/run.js +0 -36
  190. package/dist/endpoints/start/service/build.d.ts +0 -41
  191. package/dist/endpoints/start/service/build.js +0 -36
  192. package/dist/endpoints/unassign/subdomain.d.ts +0 -19
  193. package/dist/endpoints/unassign/subdomain.js +0 -36
  194. package/dist/endpoints/update/addon/networkSettings.d.ts +0 -26
  195. package/dist/endpoints/update/addon/networkSettings.js +0 -36
  196. package/dist/endpoints/update/addon/security.d.ts +0 -29
  197. package/dist/endpoints/update/addon/security.js +0 -36
  198. package/dist/endpoints/update/addon/version.d.ts +0 -24
  199. package/dist/endpoints/update/addon/version.js +0 -36
  200. package/dist/endpoints/update/job/buildArguments.d.ts +0 -24
  201. package/dist/endpoints/update/job/buildArguments.js +0 -36
  202. package/dist/endpoints/update/job/cmdOverride.d.ts +0 -24
  203. package/dist/endpoints/update/job/cmdOverride.js +0 -36
  204. package/dist/endpoints/update/job/deployment.d.ts +0 -37
  205. package/dist/endpoints/update/job/deployment.js +0 -36
  206. package/dist/endpoints/update/job/environment.d.ts +0 -24
  207. package/dist/endpoints/update/job/environment.js +0 -36
  208. package/dist/endpoints/update/job/healthChecks.d.ts +0 -45
  209. package/dist/endpoints/update/job/healthChecks.js +0 -36
  210. package/dist/endpoints/update/job/settings.d.ts +0 -30
  211. package/dist/endpoints/update/job/settings.js +0 -36
  212. package/dist/endpoints/update/registryCredentials.d.ts +0 -31
  213. package/dist/endpoints/update/registryCredentials.js +0 -36
  214. package/dist/endpoints/update/secret.d.ts +0 -54
  215. package/dist/endpoints/update/secret.js +0 -36
  216. package/dist/endpoints/update/secretLink.d.ts +0 -40
  217. package/dist/endpoints/update/secretLink.js +0 -36
  218. package/dist/endpoints/update/service/buildArguments.d.ts +0 -24
  219. package/dist/endpoints/update/service/buildArguments.js +0 -36
  220. package/dist/endpoints/update/service/buildOptions.d.ts +0 -52
  221. package/dist/endpoints/update/service/buildOptions.js +0 -36
  222. package/dist/endpoints/update/service/cmdOverride.d.ts +0 -24
  223. package/dist/endpoints/update/service/cmdOverride.js +0 -36
  224. package/dist/endpoints/update/service/deployment.d.ts +0 -37
  225. package/dist/endpoints/update/service/deployment.js +0 -36
  226. package/dist/endpoints/update/service/environmentVariables.d.ts +0 -29
  227. package/dist/endpoints/update/service/environmentVariables.js +0 -36
  228. package/dist/endpoints/update/service/healthChecks.d.ts +0 -45
  229. package/dist/endpoints/update/service/healthChecks.js +0 -36
  230. package/dist/endpoints/update/service/ports.d.ts +0 -55
  231. package/dist/endpoints/update/service/ports.js +0 -36
  232. package/dist/endpoints/verify/domain.d.ts +0 -17
  233. package/dist/endpoints/verify/domain.js +0 -36
  234. package/dist/endpoints/verify/subdomain.d.ts +0 -19
  235. package/dist/endpoints/verify/subdomain.js +0 -36
  236. package/dist/port-forward/client/api-helper.d.ts +0 -30
  237. package/dist/port-forward/client/api-helper.js +0 -102
  238. package/dist/port-forward/client/atomic-write.d.ts +0 -3
  239. package/dist/port-forward/client/atomic-write.js +0 -95
  240. package/dist/port-forward/client/host-file-ast.d.ts +0 -52
  241. package/dist/port-forward/client/host-file-ast.js +0 -279
  242. package/dist/port-forward/client/host-file.d.ts +0 -26
  243. package/dist/port-forward/client/host-file.js +0 -226
  244. package/dist/port-forward/client/loopback.d.ts +0 -4
  245. package/dist/port-forward/client/loopback.js +0 -219
  246. package/dist/port-forward/client/port-forwarder.d.ts +0 -86
  247. package/dist/port-forward/client/port-forwarder.js +0 -593
  248. package/dist/port-forward/client/port-tunnel-tcp.d.ts +0 -34
  249. package/dist/port-forward/client/port-tunnel-tcp.js +0 -209
  250. package/dist/port-forward/client/port-tunnel-udp.d.ts +0 -25
  251. package/dist/port-forward/client/port-tunnel-udp.js +0 -147
  252. package/dist/port-forward/client/port-tunnel.d.ts +0 -32
  253. package/dist/port-forward/client/port-tunnel.js +0 -2
  254. package/dist/port-forward/client/promise-mutex.d.ts +0 -4
  255. package/dist/port-forward/client/promise-mutex.js +0 -62
  256. package/dist/utils.d.ts +0 -8
  257. package/dist/utils.js +0 -97
@@ -1,63 +0,0 @@
1
- import { Response } from 'node-fetch';
2
- import { ApiClientContextProvider } from './context';
3
- import { ApiClientOpts } from './api-client';
4
- export declare type ApiCallError = {
5
- /** Http status response code */
6
- status: number;
7
- /** Error message */
8
- message: string;
9
- /** Northflank error id */
10
- id?: string;
11
- /** Error details */
12
- details?: any;
13
- };
14
- export interface ApiCallResponse<R> {
15
- data: R;
16
- rawResponse: Response;
17
- request: {
18
- url: string;
19
- method: string;
20
- headers: any;
21
- body: any;
22
- };
23
- error?: ApiCallError;
24
- pagination?: {
25
- /** Is there another page of results available? */
26
- 'hasNextPage': boolean;
27
- /** The cursor to access the next page of results. */
28
- 'cursor'?: string;
29
- /** The number of results returned by this request. Example: 1 */
30
- 'count': number;
31
- };
32
- }
33
- declare abstract class ApiEndpoint<T, R> {
34
- protected readonly opts: ApiClientOpts;
35
- protected contextProvider: ApiClientContextProvider;
36
- abstract description: string;
37
- abstract method: string;
38
- abstract body(opts: T): any;
39
- abstract endpointUrl(opts: T): string;
40
- abstract withAuth: boolean;
41
- constructor(contextProvider: ApiClientContextProvider, opts: ApiClientOpts);
42
- private getDefaultHeaders;
43
- call: (opts: T) => Promise<ApiCallResponse<R>>;
44
- }
45
- declare abstract class GetApiEndpoint<T, R> extends ApiEndpoint<T, R> {
46
- method: string;
47
- body: () => undefined;
48
- abstract endpointUrl(opts: T): string;
49
- abstract withAuth: boolean;
50
- }
51
- declare abstract class PostApiEndpoint<T, R> extends ApiEndpoint<T, R> {
52
- method: string;
53
- abstract body(opts: T): any;
54
- abstract endpointUrl(opts: T): string;
55
- abstract withAuth: boolean;
56
- }
57
- declare abstract class DeleteApiEndpoint<T, R> extends ApiEndpoint<T, R> {
58
- method: string;
59
- body: () => undefined;
60
- abstract endpointUrl(opts: T): string;
61
- abstract withAuth: boolean;
62
- }
63
- export { GetApiEndpoint, PostApiEndpoint, DeleteApiEndpoint, ApiEndpoint };
@@ -1,216 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
- return new (P || (P = Promise))(function (resolve, reject) {
31
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
- step((generator = generator.apply(thisArg, _arguments || [])).next());
35
- });
36
- };
37
- var __generator = (this && this.__generator) || function (thisArg, body) {
38
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
- function verb(n) { return function (v) { return step([n, v]); }; }
41
- function step(op) {
42
- if (f) throw new TypeError("Generator is already executing.");
43
- while (_) try {
44
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
- if (y = 0, t) op = [op[0] & 2, t.value];
46
- switch (op[0]) {
47
- case 0: case 1: t = op; break;
48
- case 4: _.label++; return { value: op[1], done: false };
49
- case 5: _.label++; y = op[1]; op = [0]; continue;
50
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
- default:
52
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
- if (t[2]) _.ops.pop();
57
- _.trys.pop(); continue;
58
- }
59
- op = body.call(thisArg, _);
60
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
- }
63
- };
64
- Object.defineProperty(exports, "__esModule", { value: true });
65
- exports.ApiEndpoint = exports.DeleteApiEndpoint = exports.PostApiEndpoint = exports.GetApiEndpoint = void 0;
66
- var utils_1 = require("./utils");
67
- // eslint-disable-next-line no-undef
68
- var fetch = utils_1.isNode ? require('node-fetch') : window.fetch;
69
- var pgk = require('../package.json');
70
- var ApiEndpoint = /** @class */ (function () {
71
- function ApiEndpoint(contextProvider, opts) {
72
- var _this = this;
73
- this.opts = opts;
74
- this.call = function (opts) { return __awaiter(_this, void 0, void 0, function () {
75
- var method, options, baseUrl, endpointUrl, body, request, rawResponse, responseText, getResponse, getError, jsonResponse, error;
76
- var _this = this;
77
- var _a;
78
- return __generator(this, function (_b) {
79
- switch (_b.label) {
80
- case 0:
81
- method = this.method;
82
- options = { method: method, headers: this.getDefaultHeaders() };
83
- baseUrl = (_a = this.contextProvider) === null || _a === void 0 ? void 0 : _a.getCurrentBaseUrl();
84
- if (!baseUrl)
85
- throw new Error('Api client context not correctly initialized, please provide a url to the context.');
86
- endpointUrl = "" + baseUrl + this.endpointUrl(opts);
87
- body = this.body(opts);
88
- request = __assign(__assign({ url: endpointUrl }, options), { body: body });
89
- return [4 /*yield*/, retryFetch(endpointUrl, __assign(__assign({}, options), { body: body }))];
90
- case 1:
91
- rawResponse = _b.sent();
92
- return [4 /*yield*/, rawResponse.text()];
93
- case 2:
94
- responseText = _b.sent();
95
- getResponse = function () {
96
- try {
97
- return JSON.parse(responseText);
98
- }
99
- catch (e) {
100
- throw Error("Failed reading api request result: \n\tStatus: " + rawResponse.statusText + " (" + rawResponse.status + ")\n\tMessage: " + responseText);
101
- }
102
- };
103
- getError = function () {
104
- if (rawResponse.status !== 200) {
105
- var errorPayload = jsonResponse === null || jsonResponse === void 0 ? void 0 : jsonResponse.error;
106
- var unauthorizedHint = rawResponse.status === 401
107
- ? ' (Make sure your API token has sufficient permissions)'
108
- : '';
109
- var errorMessage = "" + ((errorPayload === null || errorPayload === void 0 ? void 0 : errorPayload.message) || '') + unauthorizedHint;
110
- if (_this.opts.throwErrorOnHttpErrorCode) {
111
- throw Error(errorMessage);
112
- }
113
- else {
114
- return {
115
- status: rawResponse.status,
116
- message: errorMessage,
117
- id: errorPayload === null || errorPayload === void 0 ? void 0 : errorPayload.id,
118
- details: errorPayload === null || errorPayload === void 0 ? void 0 : errorPayload.details,
119
- };
120
- }
121
- }
122
- return undefined;
123
- };
124
- jsonResponse = getResponse();
125
- error = getError();
126
- return [2 /*return*/, {
127
- data: jsonResponse === null || jsonResponse === void 0 ? void 0 : jsonResponse.data,
128
- rawResponse: rawResponse,
129
- request: request,
130
- error: error,
131
- pagination: jsonResponse === null || jsonResponse === void 0 ? void 0 : jsonResponse.pagination,
132
- }];
133
- }
134
- });
135
- }); };
136
- this.contextProvider = contextProvider;
137
- }
138
- ApiEndpoint.prototype.getDefaultHeaders = function () {
139
- var _a;
140
- var token = this.contextProvider.getCurrentToken();
141
- var customUserAgent = ((_a = this.opts) === null || _a === void 0 ? void 0 : _a.customUserAgent) ? " (" + this.opts.customUserAgent + ")" : '';
142
- return {
143
- 'Authorization': this.withAuth ? "Bearer " + token : undefined,
144
- 'Content-Type': 'application/json',
145
- 'User-Agent': "northflank-js-client/" + (pgk === null || pgk === void 0 ? void 0 : pgk.version) + customUserAgent,
146
- };
147
- };
148
- return ApiEndpoint;
149
- }());
150
- exports.ApiEndpoint = ApiEndpoint;
151
- var GetApiEndpoint = /** @class */ (function (_super) {
152
- __extends(GetApiEndpoint, _super);
153
- function GetApiEndpoint() {
154
- var _this = _super !== null && _super.apply(this, arguments) || this;
155
- _this.method = 'get';
156
- _this.body = function () { return undefined; };
157
- return _this;
158
- }
159
- return GetApiEndpoint;
160
- }(ApiEndpoint));
161
- exports.GetApiEndpoint = GetApiEndpoint;
162
- var PostApiEndpoint = /** @class */ (function (_super) {
163
- __extends(PostApiEndpoint, _super);
164
- function PostApiEndpoint() {
165
- var _this = _super !== null && _super.apply(this, arguments) || this;
166
- _this.method = 'post';
167
- return _this;
168
- }
169
- return PostApiEndpoint;
170
- }(ApiEndpoint));
171
- exports.PostApiEndpoint = PostApiEndpoint;
172
- var DeleteApiEndpoint = /** @class */ (function (_super) {
173
- __extends(DeleteApiEndpoint, _super);
174
- function DeleteApiEndpoint() {
175
- var _this = _super !== null && _super.apply(this, arguments) || this;
176
- _this.method = 'delete';
177
- _this.body = function () { return undefined; };
178
- return _this;
179
- }
180
- return DeleteApiEndpoint;
181
- }(ApiEndpoint));
182
- exports.DeleteApiEndpoint = DeleteApiEndpoint;
183
- var delay = function (ms) {
184
- return new Promise(function (resolve) {
185
- setTimeout(function () {
186
- resolve();
187
- }, ms);
188
- });
189
- };
190
- var retryFetch = function (url, fetchOptions, retries, retryDelay) {
191
- if (fetchOptions === void 0) { fetchOptions = {}; }
192
- if (retries === void 0) { retries = 3; }
193
- if (retryDelay === void 0) { retryDelay = 500; }
194
- return new Promise(function (resolve, reject) {
195
- var wrapper = function (n) {
196
- return fetch(url, fetchOptions)
197
- .then(function (res) {
198
- resolve(res);
199
- })
200
- .catch(function (err) { return __awaiter(void 0, void 0, void 0, function () {
201
- return __generator(this, function (_a) {
202
- switch (_a.label) {
203
- case 0:
204
- if (!(n > 0)) return [3 /*break*/, 2];
205
- return [4 /*yield*/, delay(retryDelay)];
206
- case 1:
207
- _a.sent();
208
- return [2 /*return*/, wrapper(n - 1)];
209
- case 2: return [2 /*return*/, reject(err)];
210
- }
211
- });
212
- }); });
213
- };
214
- return wrapper(retries);
215
- });
216
- };
@@ -1,47 +0,0 @@
1
- declare type Optional<T, K extends keyof T> = Omit<T, K> & Partial<T>;
2
- export declare abstract class ApiClientContextProvider {
3
- private contextWrapper;
4
- constructor();
5
- protected loadContext(): void;
6
- getInfo(): string;
7
- storeContext(contextWrapper: ApiClientContextWrapper): Promise<void>;
8
- addContext(context: Optional<ApiClientContext, 'host'>, override?: boolean): Promise<void>;
9
- removeContext(name: string): Promise<void>;
10
- protected abstract writeContext(context: ApiClientContextWrapper): Promise<void>;
11
- abstract loadContextWrapper(): ApiClientContextWrapper;
12
- getCurrentContext(): ApiClientContext | undefined;
13
- private findContext;
14
- getCurrentBaseUrl(): string | undefined;
15
- getCurrentProjectName(): string | undefined;
16
- getCurrentName(): string | undefined;
17
- getCurrentToken(): string | undefined;
18
- getCurrentServiceName(): string | undefined;
19
- getCurrentJobName(): string | undefined;
20
- getCurrentPlanId(): string | undefined;
21
- getCurrentRegion(): string | undefined;
22
- useContext(name: string): Promise<void>;
23
- updateToken(token: string, name?: string): Promise<void>;
24
- useProjectId(id: string): Promise<void>;
25
- useServiceId(id: string): Promise<void>;
26
- useJobId(id: string): Promise<void>;
27
- usePlanId(id: string): Promise<void>;
28
- useRegion(region: string): Promise<void>;
29
- getLastUpdateCheck(): Date;
30
- setLastUpdateCheck(check: Date): Promise<any>;
31
- }
32
- export interface ApiClientContextWrapper {
33
- current?: string;
34
- contexts: ApiClientContext[];
35
- lastUpdateCheck?: Date;
36
- }
37
- export interface ApiClientContext {
38
- name: string;
39
- token: string;
40
- host: string;
41
- project?: string;
42
- service?: string;
43
- job?: string;
44
- plan?: string;
45
- region?: string;
46
- }
47
- export {};
@@ -1,332 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
50
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
51
- to[j] = from[i];
52
- return to;
53
- };
54
- Object.defineProperty(exports, "__esModule", { value: true });
55
- exports.ApiClientContextProvider = void 0;
56
- var ApiClientContextProvider = /** @class */ (function () {
57
- function ApiClientContextProvider() {
58
- this.loadContext();
59
- }
60
- ApiClientContextProvider.prototype.loadContext = function () {
61
- this.contextWrapper = this.loadContextWrapper();
62
- };
63
- // eslint-disable-next-line class-methods-use-this
64
- ApiClientContextProvider.prototype.getInfo = function () {
65
- return '';
66
- };
67
- ApiClientContextProvider.prototype.storeContext = function (contextWrapper) {
68
- return __awaiter(this, void 0, void 0, function () {
69
- return __generator(this, function (_a) {
70
- switch (_a.label) {
71
- case 0: return [4 /*yield*/, this.writeContext(contextWrapper)];
72
- case 1:
73
- _a.sent();
74
- this.contextWrapper = contextWrapper;
75
- return [2 /*return*/];
76
- }
77
- });
78
- });
79
- };
80
- ApiClientContextProvider.prototype.addContext = function (context, override) {
81
- if (override === void 0) { override = true; }
82
- return __awaiter(this, void 0, void 0, function () {
83
- var fullContext, contextWrapper, newContextWrapper;
84
- return __generator(this, function (_a) {
85
- switch (_a.label) {
86
- case 0:
87
- if (!(!override && this.findContext(context.name) !== undefined)) return [3 /*break*/, 1];
88
- throw new Error("Context with name " + context.name + " already exists");
89
- case 1: return [4 /*yield*/, this.removeContext(context.name)];
90
- case 2:
91
- _a.sent();
92
- _a.label = 3;
93
- case 3:
94
- fullContext = __assign({ host: 'https://api.northflank.com' }, context);
95
- contextWrapper = this.contextWrapper;
96
- newContextWrapper = {
97
- current: fullContext.name,
98
- contexts: __spreadArray(__spreadArray([], contextWrapper.contexts), [fullContext]),
99
- lastUpdateCheck: contextWrapper.lastUpdateCheck,
100
- };
101
- return [4 /*yield*/, this.storeContext(newContextWrapper)];
102
- case 4:
103
- _a.sent();
104
- return [2 /*return*/];
105
- }
106
- });
107
- });
108
- };
109
- ApiClientContextProvider.prototype.removeContext = function (name) {
110
- return __awaiter(this, void 0, void 0, function () {
111
- var contextWrapper, filteredContexts, current, newContextWrapper;
112
- return __generator(this, function (_a) {
113
- switch (_a.label) {
114
- case 0:
115
- contextWrapper = this.contextWrapper;
116
- filteredContexts = contextWrapper.contexts.filter(function (context) { return context.name !== name; });
117
- current = contextWrapper.current === name ? undefined : contextWrapper.current;
118
- newContextWrapper = {
119
- current: current,
120
- contexts: __spreadArray([], filteredContexts),
121
- lastUpdateCheck: contextWrapper.lastUpdateCheck,
122
- };
123
- return [4 /*yield*/, this.storeContext(newContextWrapper)];
124
- case 1:
125
- _a.sent();
126
- return [2 /*return*/];
127
- }
128
- });
129
- });
130
- };
131
- ApiClientContextProvider.prototype.getCurrentContext = function () {
132
- var currentContextName = this.contextWrapper.current;
133
- if (currentContextName === undefined) {
134
- return currentContextName;
135
- }
136
- return this.findContext(currentContextName);
137
- };
138
- ApiClientContextProvider.prototype.findContext = function (contextName) {
139
- return this.contextWrapper.contexts.find(function (ctx) { return ctx.name === contextName; });
140
- };
141
- ApiClientContextProvider.prototype.getCurrentBaseUrl = function () {
142
- var currentContext = this.getCurrentContext();
143
- return currentContext === null || currentContext === void 0 ? void 0 : currentContext.host;
144
- };
145
- ApiClientContextProvider.prototype.getCurrentProjectName = function () {
146
- var _a;
147
- return (_a = this.getCurrentContext()) === null || _a === void 0 ? void 0 : _a.project;
148
- };
149
- ApiClientContextProvider.prototype.getCurrentName = function () {
150
- var _a;
151
- return (_a = this.getCurrentContext()) === null || _a === void 0 ? void 0 : _a.name;
152
- };
153
- ApiClientContextProvider.prototype.getCurrentToken = function () {
154
- var _a;
155
- return (_a = this.getCurrentContext()) === null || _a === void 0 ? void 0 : _a.token;
156
- };
157
- ApiClientContextProvider.prototype.getCurrentServiceName = function () {
158
- var _a;
159
- return (_a = this.getCurrentContext()) === null || _a === void 0 ? void 0 : _a.service;
160
- };
161
- ApiClientContextProvider.prototype.getCurrentJobName = function () {
162
- var _a;
163
- return (_a = this.getCurrentContext()) === null || _a === void 0 ? void 0 : _a.job;
164
- };
165
- ApiClientContextProvider.prototype.getCurrentPlanId = function () {
166
- var _a;
167
- return (_a = this.getCurrentContext()) === null || _a === void 0 ? void 0 : _a.plan;
168
- };
169
- ApiClientContextProvider.prototype.getCurrentRegion = function () {
170
- var _a;
171
- return (_a = this.getCurrentContext()) === null || _a === void 0 ? void 0 : _a.region;
172
- };
173
- ApiClientContextProvider.prototype.useContext = function (name) {
174
- return __awaiter(this, void 0, void 0, function () {
175
- var contextWrapper, newContextWrapper;
176
- return __generator(this, function (_a) {
177
- switch (_a.label) {
178
- case 0:
179
- if (!this.findContext(name)) {
180
- throw new Error("Context with name " + name + " doesn't exist");
181
- }
182
- contextWrapper = this.contextWrapper;
183
- newContextWrapper = __assign(__assign({}, contextWrapper), { current: name });
184
- return [4 /*yield*/, this.storeContext(newContextWrapper)];
185
- case 1:
186
- _a.sent();
187
- return [2 /*return*/];
188
- }
189
- });
190
- });
191
- };
192
- ApiClientContextProvider.prototype.updateToken = function (token, name) {
193
- return __awaiter(this, void 0, void 0, function () {
194
- var nameCur, context, contextWrapper, updatedContexts, newContextWrapper;
195
- return __generator(this, function (_a) {
196
- switch (_a.label) {
197
- case 0:
198
- nameCur = name !== null && name !== void 0 ? name : this.getCurrentName();
199
- context = this.findContext(nameCur);
200
- if (!context) {
201
- throw new Error("Context with name " + name + " doesn't exist");
202
- }
203
- contextWrapper = this.contextWrapper;
204
- updatedContexts = contextWrapper.contexts.map(function (ctx) {
205
- return ctx.name === nameCur ? __assign(__assign({}, context), { token: token }) : ctx;
206
- });
207
- newContextWrapper = __assign(__assign({}, contextWrapper), { contexts: updatedContexts });
208
- return [4 /*yield*/, this.storeContext(newContextWrapper)];
209
- case 1:
210
- _a.sent();
211
- return [2 /*return*/];
212
- }
213
- });
214
- });
215
- };
216
- ApiClientContextProvider.prototype.useProjectId = function (id) {
217
- return __awaiter(this, void 0, void 0, function () {
218
- var currentContext, updatedContext;
219
- return __generator(this, function (_a) {
220
- switch (_a.label) {
221
- case 0:
222
- currentContext = this.getCurrentContext();
223
- if (currentContext === undefined) {
224
- throw new Error('Failed to set project id to current context, current context not defined');
225
- }
226
- updatedContext = __assign(__assign({}, currentContext), { project: id });
227
- return [4 /*yield*/, this.addContext(updatedContext)];
228
- case 1:
229
- _a.sent();
230
- return [2 /*return*/];
231
- }
232
- });
233
- });
234
- };
235
- ApiClientContextProvider.prototype.useServiceId = function (id) {
236
- return __awaiter(this, void 0, void 0, function () {
237
- var currentContext, updatedContext;
238
- return __generator(this, function (_a) {
239
- switch (_a.label) {
240
- case 0:
241
- currentContext = this.getCurrentContext();
242
- if (currentContext === undefined) {
243
- throw new Error('Failed to set service id to current context, current context not defined');
244
- }
245
- updatedContext = __assign(__assign({}, currentContext), { service: id });
246
- return [4 /*yield*/, this.addContext(updatedContext)];
247
- case 1:
248
- _a.sent();
249
- return [2 /*return*/];
250
- }
251
- });
252
- });
253
- };
254
- ApiClientContextProvider.prototype.useJobId = function (id) {
255
- return __awaiter(this, void 0, void 0, function () {
256
- var currentContext, updatedContext;
257
- return __generator(this, function (_a) {
258
- switch (_a.label) {
259
- case 0:
260
- currentContext = this.getCurrentContext();
261
- if (currentContext === undefined) {
262
- throw new Error('Failed to set job id to current context, current context not defined');
263
- }
264
- updatedContext = __assign(__assign({}, currentContext), { job: id });
265
- return [4 /*yield*/, this.addContext(updatedContext)];
266
- case 1:
267
- _a.sent();
268
- return [2 /*return*/];
269
- }
270
- });
271
- });
272
- };
273
- ApiClientContextProvider.prototype.usePlanId = function (id) {
274
- return __awaiter(this, void 0, void 0, function () {
275
- var currentContext, updatedContext;
276
- return __generator(this, function (_a) {
277
- switch (_a.label) {
278
- case 0:
279
- currentContext = this.getCurrentContext();
280
- if (currentContext === undefined) {
281
- throw new Error('Failed to set plan id to current context, current context not defined');
282
- }
283
- updatedContext = __assign(__assign({}, currentContext), { plan: id });
284
- return [4 /*yield*/, this.addContext(updatedContext)];
285
- case 1:
286
- _a.sent();
287
- return [2 /*return*/];
288
- }
289
- });
290
- });
291
- };
292
- ApiClientContextProvider.prototype.useRegion = function (region) {
293
- return __awaiter(this, void 0, void 0, function () {
294
- var currentContext, updatedContext;
295
- return __generator(this, function (_a) {
296
- switch (_a.label) {
297
- case 0:
298
- currentContext = this.getCurrentContext();
299
- if (currentContext === undefined) {
300
- throw new Error('Failed to set region id to current context, current context not defined');
301
- }
302
- updatedContext = __assign(__assign({}, currentContext), { region: region });
303
- return [4 /*yield*/, this.addContext(updatedContext)];
304
- case 1:
305
- _a.sent();
306
- return [2 /*return*/];
307
- }
308
- });
309
- });
310
- };
311
- ApiClientContextProvider.prototype.getLastUpdateCheck = function () {
312
- return this.contextWrapper.lastUpdateCheck || new Date();
313
- };
314
- ApiClientContextProvider.prototype.setLastUpdateCheck = function (check) {
315
- return __awaiter(this, void 0, void 0, function () {
316
- var contextWrapper, newContextWrapper;
317
- return __generator(this, function (_a) {
318
- switch (_a.label) {
319
- case 0:
320
- contextWrapper = this.contextWrapper;
321
- newContextWrapper = __assign(__assign({}, contextWrapper), { lastUpdateCheck: check });
322
- return [4 /*yield*/, this.storeContext(newContextWrapper)];
323
- case 1:
324
- _a.sent();
325
- return [2 /*return*/];
326
- }
327
- });
328
- });
329
- };
330
- return ApiClientContextProvider;
331
- }());
332
- exports.ApiClientContextProvider = ApiClientContextProvider;
@@ -1,11 +0,0 @@
1
- import { ApiClientContextProvider, ApiClientContextWrapper } from './api-client-context-provider';
2
- export declare class ApiClientFileContextProvider extends ApiClientContextProvider {
3
- configPath: string;
4
- configFile: string;
5
- constructor(configPath?: string);
6
- loadContextWrapper(): ApiClientContextWrapper;
7
- protected writeContext(context: ApiClientContextWrapper): Promise<void>;
8
- assertDir: (path: string) => Promise<string | undefined>;
9
- assertConfigDir(): Promise<void>;
10
- getInfo(): string;
11
- }