hcloud-sdk 0.0.16 → 15.0.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 +1 -0
- package/changelog.md +45 -0
- package/index.d.ts +3 -2
- package/index.js +5 -2
- package/lib/Base.d.ts +26 -0
- package/lib/Base.js +12 -0
- package/lib/Hcloud.d.ts +90 -0
- package/lib/Hcloud.js +184 -0
- package/lib/helper/ErrorHelper.d.ts +7 -0
- package/lib/helper/ErrorHelper.js +19 -0
- package/lib/helper/paginatedResponseHelper.d.ts +3 -0
- package/lib/helper/paginatedResponseHelper.js +9 -0
- package/lib/helper/searchFilter.d.ts +9 -0
- package/lib/helper/searchFilter.js +12 -0
- package/lib/interfaces/agent/bundle/dev/index.d.ts +3 -0
- package/lib/interfaces/agent/context/index.d.ts +19 -0
- package/lib/interfaces/agent/index.d.ts +21 -0
- package/lib/interfaces/agent/index.js +2 -0
- package/lib/interfaces/{Auditor.d.ts → auditor/index.d.ts} +31 -5
- package/lib/interfaces/{Auditor.js → auditor/index.js} +15 -5
- package/lib/interfaces/axios/index.d.ts +5 -0
- package/lib/interfaces/axios/index.js +8 -0
- package/lib/interfaces/bouncer/features/index.d.ts +7 -0
- package/lib/interfaces/bouncer/features/index.js +2 -0
- package/lib/interfaces/bouncer/index.d.ts +6 -0
- package/lib/interfaces/bouncer/index.js +17 -0
- package/lib/interfaces/dali/index.d.ts +3 -0
- package/lib/interfaces/dali/index.js +2 -0
- package/lib/interfaces/frontend/config/index.d.ts +33 -0
- package/lib/interfaces/frontend/config/index.js +10 -0
- package/lib/interfaces/frontend/featureflags/index.d.ts +7 -0
- package/lib/interfaces/frontend/featureflags/index.js +2 -0
- package/lib/interfaces/fuse/index.d.ts +3 -0
- package/lib/interfaces/fuse/index.js +19 -0
- package/lib/interfaces/fuse/space/cronjob/Cronjob.d.ts +38 -0
- package/lib/interfaces/fuse/space/cronjob/Cronjob.js +8 -0
- package/lib/interfaces/fuse/space/cronjob/CronjobLog.d.ts +16 -0
- package/lib/interfaces/fuse/space/cronjob/CronjobLog.js +2 -0
- package/lib/interfaces/fuse/space/index.d.ts +21 -0
- package/lib/interfaces/fuse/space/index.js +11 -0
- package/lib/interfaces/global/HCloudError.d.ts +8 -0
- package/lib/interfaces/global/HCloudError.js +13 -0
- package/lib/interfaces/global/Header.d.ts +4 -0
- package/lib/interfaces/global/Header.js +2 -0
- package/lib/interfaces/global/HttpMethod.d.ts +7 -0
- package/lib/interfaces/global/HttpMethod.js +11 -0
- package/lib/interfaces/global/PaginatedResponse.d.ts +4 -0
- package/lib/interfaces/global/PaginatedResponse.js +2 -0
- package/lib/interfaces/global/Products.d.ts +11 -0
- package/lib/interfaces/global/Products.js +15 -0
- package/lib/interfaces/global/SearchFilters.d.ts +86 -0
- package/lib/interfaces/global/SearchFilters.js +49 -0
- package/lib/interfaces/global/Space.d.ts +20 -0
- package/lib/interfaces/global/Space.js +8 -0
- package/lib/interfaces/global/Version.d.ts +3 -0
- package/lib/interfaces/global/Version.js +2 -0
- package/lib/interfaces/global/Views.d.ts +8 -0
- package/lib/interfaces/global/Views.js +12 -0
- package/lib/interfaces/global/index.d.ts +9 -0
- package/lib/interfaces/global/index.js +25 -0
- package/lib/interfaces/high5/index.d.ts +16 -0
- package/lib/interfaces/high5/index.js +32 -0
- package/lib/interfaces/high5/joinToken/index.d.ts +10 -0
- package/lib/interfaces/high5/joinToken/index.js +2 -0
- package/lib/interfaces/high5/space/event/index.d.ts +15 -0
- package/lib/interfaces/high5/space/event/index.js +2 -0
- package/lib/interfaces/high5/space/event/stream/design/DesignOperation.d.ts +68 -0
- package/lib/interfaces/high5/space/event/stream/design/DesignOperation.js +20 -0
- package/lib/interfaces/high5/space/event/stream/design/StreamDesign.d.ts +92 -0
- package/lib/interfaces/high5/space/event/stream/design/StreamDesign.js +20 -0
- package/lib/interfaces/high5/space/event/stream/design/index.d.ts +22 -0
- package/lib/interfaces/high5/space/event/stream/design/index.js +2 -0
- package/lib/interfaces/high5/space/event/stream/design/snapshot/index.d.ts +30 -0
- package/lib/interfaces/high5/space/event/stream/design/snapshot/index.js +8 -0
- package/lib/interfaces/high5/space/event/stream/index.d.ts +77 -0
- package/lib/interfaces/high5/space/event/stream/index.js +13 -0
- package/lib/interfaces/high5/space/event/stream/node/index.d.ts +62 -0
- package/lib/interfaces/high5/space/event/stream/node/index.js +7 -0
- package/lib/interfaces/high5/space/execution/index.d.ts +148 -0
- package/lib/interfaces/high5/space/execution/index.js +21 -0
- package/lib/interfaces/high5/space/index.d.ts +23 -0
- package/lib/interfaces/high5/space/index.js +12 -0
- package/lib/interfaces/high5/space/secret/index.d.ts +12 -0
- package/lib/interfaces/high5/space/secret/index.js +2 -0
- package/lib/interfaces/high5/space/webhook/index.d.ts +75 -0
- package/lib/interfaces/high5/space/webhook/index.js +9 -0
- package/lib/interfaces/high5/wave/changelog.d.ts +30 -0
- package/lib/interfaces/high5/wave/changelog.js +18 -0
- package/lib/interfaces/high5/wave/index.d.ts +201 -0
- package/lib/interfaces/high5/wave/index.js +61 -0
- package/lib/interfaces/idp/index.d.ts +26 -0
- package/lib/interfaces/idp/index.js +38 -0
- package/lib/interfaces/idp/oauth/index.d.ts +19 -0
- package/lib/interfaces/idp/oauth/index.js +8 -0
- package/lib/interfaces/idp/organization/index.d.ts +32 -0
- package/lib/interfaces/idp/organization/index.js +25 -0
- package/lib/interfaces/idp/organization/license/index.d.ts +84 -0
- package/lib/interfaces/idp/organization/license/index.js +15 -0
- package/lib/interfaces/idp/organization/member/index.d.ts +15 -0
- package/lib/interfaces/idp/organization/member/index.js +2 -0
- package/lib/interfaces/idp/organization/member/invitations/index.d.ts +26 -0
- package/lib/interfaces/idp/organization/member/invitations/index.js +18 -0
- package/lib/interfaces/idp/organization/settings/domain/index.d.ts +19 -0
- package/lib/interfaces/idp/organization/settings/domain/index.js +8 -0
- package/lib/interfaces/idp/organization/settings/domain/saml/index.d.ts +10 -0
- package/lib/interfaces/idp/organization/settings/domain/saml/index.js +2 -0
- package/lib/interfaces/idp/organization/settings/oauthApp/index.d.ts +37 -0
- package/lib/interfaces/idp/organization/settings/oauthApp/index.js +2 -0
- package/lib/interfaces/idp/organization/team/index.d.ts +24 -0
- package/lib/interfaces/idp/organization/team/index.js +9 -0
- package/lib/interfaces/idp/user/ConnectionSettings.d.ts +6 -0
- package/lib/interfaces/idp/user/ConnectionSettings.js +2 -0
- package/lib/interfaces/idp/user/GeneralSettings.d.ts +45 -0
- package/lib/interfaces/idp/user/GeneralSettings.js +38 -0
- package/lib/interfaces/idp/user/NotificationSettings.d.ts +8 -0
- package/lib/interfaces/idp/user/NotificationSettings.js +2 -0
- package/lib/interfaces/idp/user/Pat.d.ts +19 -0
- package/lib/interfaces/idp/user/Pat.js +2 -0
- package/lib/interfaces/idp/user/Scopes.d.ts +40 -0
- package/lib/interfaces/idp/user/Scopes.js +50 -0
- package/lib/interfaces/idp/user/SuccessfulAuth.d.ts +5 -0
- package/lib/interfaces/idp/user/SuccessfulAuth.js +2 -0
- package/lib/interfaces/idp/user/Totp.d.ts +20 -0
- package/lib/interfaces/idp/user/Totp.js +2 -0
- package/lib/interfaces/idp/user/index.d.ts +23 -0
- package/lib/interfaces/idp/user/index.js +2 -0
- package/lib/interfaces/mailer/index.d.ts +66 -0
- package/lib/interfaces/mailer/index.js +81 -0
- package/lib/interfaces/mothership/index.d.ts +28 -0
- package/lib/interfaces/mothership/index.js +8 -0
- package/lib/interfaces/nats/index.d.ts +239 -0
- package/lib/interfaces/nats/index.js +316 -0
- package/lib/service/agent/bundle/dev/index.d.ts +17 -0
- package/lib/service/agent/bundle/dev/index.js +44 -0
- package/lib/service/agent/bundle/index.d.ts +11 -0
- package/lib/service/agent/bundle/index.js +55 -0
- package/lib/service/agent/context/index.d.ts +35 -0
- package/lib/service/agent/context/index.js +90 -0
- package/lib/service/agent/index.d.ts +16 -0
- package/lib/service/agent/index.js +37 -0
- package/lib/service/agent/installer/index.d.ts +15 -0
- package/lib/service/agent/installer/index.js +97 -0
- package/lib/service/auditor/index.d.ts +25 -0
- package/lib/service/auditor/index.js +55 -0
- package/lib/service/auditor/internal/index.d.ts +27 -0
- package/lib/service/auditor/internal/index.js +65 -0
- package/lib/service/bouncer/features/index.d.ts +8 -0
- package/lib/service/bouncer/features/index.js +27 -0
- package/lib/service/bouncer/index.d.ts +7 -0
- package/lib/service/bouncer/index.js +16 -0
- package/lib/service/dali/DaliAvatar.d.ts +40 -0
- package/lib/service/dali/DaliAvatar.js +70 -0
- package/lib/service/dali/avatar/DaliFuseSpace.d.ts +26 -0
- package/lib/service/dali/avatar/DaliFuseSpace.js +58 -0
- package/lib/service/dali/avatar/DaliHigh5Space.d.ts +26 -0
- package/lib/service/dali/avatar/DaliHigh5Space.js +58 -0
- package/lib/service/dali/avatar/DaliOAuthApp.d.ts +26 -0
- package/lib/service/dali/avatar/DaliOAuthApp.js +58 -0
- package/lib/service/dali/avatar/DaliOrganization.d.ts +23 -0
- package/lib/service/dali/avatar/DaliOrganization.js +55 -0
- package/lib/service/dali/avatar/DaliTeam.d.ts +26 -0
- package/lib/service/dali/avatar/DaliTeam.js +58 -0
- package/lib/service/dali/avatar/DaliUser.d.ts +20 -0
- package/lib/service/dali/avatar/DaliUser.js +52 -0
- package/lib/service/dali/index.d.ts +15 -0
- package/lib/service/dali/index.js +37 -0
- package/lib/service/fuse/index.d.ts +18 -0
- package/lib/service/fuse/index.js +48 -0
- package/lib/service/fuse/internal/index.d.ts +8 -0
- package/lib/service/fuse/internal/index.js +31 -0
- package/lib/service/fuse/internal/space/cronjob/index.d.ts +7 -0
- package/lib/service/fuse/internal/space/cronjob/index.js +17 -0
- package/lib/service/fuse/internal/space/cronjob/log/index.d.ts +15 -0
- package/lib/service/fuse/internal/space/cronjob/log/index.js +34 -0
- package/lib/service/fuse/internal/space/index.d.ts +22 -0
- package/lib/service/fuse/internal/space/index.js +49 -0
- package/lib/service/fuse/space/cronjob/index.d.ts +123 -0
- package/lib/service/fuse/space/cronjob/index.js +203 -0
- package/lib/service/fuse/space/cronjob/log/index.d.ts +31 -0
- package/lib/service/fuse/space/cronjob/log/index.js +58 -0
- package/lib/service/fuse/space/index.d.ts +81 -0
- package/lib/service/fuse/space/index.js +152 -0
- package/lib/service/high5/execution/index.d.ts +10 -0
- package/lib/service/high5/execution/index.js +24 -0
- package/lib/service/high5/execution/log/index.d.ts +19 -0
- package/lib/service/high5/execution/log/index.js +40 -0
- package/lib/service/high5/execution/status/index.d.ts +18 -0
- package/lib/service/high5/execution/status/index.js +40 -0
- package/lib/service/high5/index.d.ts +25 -0
- package/lib/service/high5/index.js +63 -0
- package/lib/service/high5/internal/index.d.ts +8 -0
- package/lib/service/high5/internal/index.js +31 -0
- package/lib/service/high5/internal/space/index.d.ts +21 -0
- package/lib/service/high5/internal/space/index.js +45 -0
- package/lib/service/high5/joinToken/index.d.ts +40 -0
- package/lib/service/high5/joinToken/index.js +72 -0
- package/lib/service/high5/space/event/index.d.ts +55 -0
- package/lib/service/high5/space/event/index.js +101 -0
- package/lib/service/high5/space/event/stream/design/DesignOperations.d.ts +31 -0
- package/lib/service/high5/space/event/stream/design/DesignOperations.js +117 -0
- package/lib/service/high5/space/event/stream/design/index.d.ts +53 -0
- package/lib/service/high5/space/event/stream/design/index.js +91 -0
- package/lib/service/high5/space/event/stream/design/snapshot/index.d.ts +62 -0
- package/lib/service/high5/space/event/stream/design/snapshot/index.js +107 -0
- package/lib/service/high5/space/event/stream/index.d.ts +113 -0
- package/lib/service/high5/space/event/stream/index.js +186 -0
- package/lib/service/high5/space/execution/index.d.ts +48 -0
- package/lib/service/high5/space/execution/index.js +89 -0
- package/lib/service/high5/space/execution/log/index.d.ts +29 -0
- package/lib/service/high5/space/execution/log/index.js +58 -0
- package/lib/service/high5/space/execution/status/index.d.ts +16 -0
- package/lib/service/high5/space/execution/status/index.js +36 -0
- package/lib/service/high5/space/index.d.ts +111 -0
- package/lib/service/high5/space/index.js +205 -0
- package/lib/service/high5/space/node/index.d.ts +58 -0
- package/lib/service/high5/space/node/index.js +116 -0
- package/lib/service/high5/space/secret/index.d.ts +60 -0
- package/lib/service/high5/space/secret/index.js +102 -0
- package/lib/service/high5/space/wave/index.d.ts +36 -0
- package/lib/service/high5/space/wave/index.js +73 -0
- package/lib/service/high5/space/webhook/index.d.ts +90 -0
- package/lib/service/high5/space/webhook/index.js +165 -0
- package/lib/service/high5/space/webhook/log/index.d.ts +16 -0
- package/lib/service/high5/space/webhook/log/index.js +37 -0
- package/lib/service/high5/wave/index.d.ts +8 -0
- package/lib/service/high5/wave/index.js +15 -0
- package/lib/service/high5/wave/s3/index.d.ts +48 -0
- package/lib/service/high5/wave/s3/index.js +100 -0
- package/lib/service/idp/index.d.ts +84 -0
- package/lib/service/idp/index.js +185 -0
- package/lib/service/idp/internal/index.d.ts +17 -0
- package/lib/service/idp/internal/index.js +33 -0
- package/lib/service/idp/oauth/index.d.ts +49 -0
- package/lib/service/idp/oauth/index.js +117 -0
- package/lib/service/idp/organization/index.d.ts +56 -0
- package/lib/service/idp/organization/index.js +114 -0
- package/lib/service/idp/organization/license/index.d.ts +7 -0
- package/lib/service/idp/organization/license/index.js +31 -0
- package/lib/service/idp/organization/member/index.d.ts +57 -0
- package/lib/service/idp/organization/member/index.js +110 -0
- package/lib/service/idp/organization/member/invitations/index.d.ts +79 -0
- package/lib/service/idp/organization/member/invitations/index.js +122 -0
- package/lib/service/idp/organization/settings/domain/index.d.ts +37 -0
- package/lib/service/idp/organization/settings/domain/index.js +76 -0
- package/lib/service/idp/organization/settings/domain/saml/index.d.ts +43 -0
- package/lib/service/idp/organization/settings/domain/saml/index.js +98 -0
- package/lib/service/idp/organization/settings/index.d.ts +16 -0
- package/lib/service/idp/organization/settings/index.js +29 -0
- package/lib/service/idp/organization/settings/oauth/index.d.ts +62 -0
- package/lib/service/idp/organization/settings/oauth/index.js +117 -0
- package/lib/service/idp/organization/team/index.d.ts +72 -0
- package/lib/service/idp/organization/team/index.js +124 -0
- package/lib/service/idp/registration/index.d.ts +37 -0
- package/lib/service/idp/registration/index.js +87 -0
- package/lib/service/idp/user/index.d.ts +83 -0
- package/lib/service/idp/user/index.js +160 -0
- package/lib/service/idp/user/license/index.d.ts +7 -0
- package/lib/service/idp/user/license/index.js +31 -0
- package/lib/service/idp/user/password/index.d.ts +19 -0
- package/lib/service/idp/user/password/index.js +51 -0
- package/lib/service/idp/user/settings/connections/index.d.ts +13 -0
- package/lib/service/idp/user/settings/connections/index.js +32 -0
- package/lib/service/idp/user/settings/general/index.d.ts +22 -0
- package/lib/service/idp/user/settings/general/index.js +51 -0
- package/lib/service/idp/user/settings/index.d.ts +40 -0
- package/lib/service/idp/user/settings/index.js +70 -0
- package/lib/service/idp/user/settings/notifications/index.d.ts +16 -0
- package/lib/service/idp/user/settings/notifications/index.js +40 -0
- package/lib/service/idp/user/settings/oauthApps/index.d.ts +20 -0
- package/lib/service/idp/user/settings/oauthApps/index.js +55 -0
- package/lib/service/idp/user/settings/pats/index.d.ts +48 -0
- package/lib/service/idp/user/settings/pats/index.js +104 -0
- package/lib/service/idp/user/settings/twoFactor/index.d.ts +10 -0
- package/lib/service/idp/user/settings/twoFactor/index.js +20 -0
- package/lib/service/idp/user/settings/twoFactor/totp/index.d.ts +32 -0
- package/lib/service/idp/user/settings/twoFactor/totp/index.js +72 -0
- package/lib/service/mailer/index.d.ts +13 -0
- package/lib/service/{Mailer.js → mailer/index.js} +17 -16
- package/lib/service/mailer/internal/index.d.ts +36 -0
- package/lib/service/mailer/internal/index.js +69 -0
- package/lib/service/mothership/index.d.ts +97 -0
- package/lib/service/mothership/index.js +149 -0
- package/lib/service/nats/index.d.ts +49 -0
- package/lib/service/nats/index.js +138 -0
- package/lib/utils/Types.d.ts +1 -0
- package/lib/utils/Types.js +2 -0
- package/lib/utils/bouncer/features/Provider.d.ts +19 -0
- package/lib/utils/bouncer/features/Provider.js +101 -0
- package/package.json +37 -29
- package/lib/base.d.ts +0 -12
- package/lib/base.js +0 -8
- package/lib/hcloud.d.ts +0 -13
- package/lib/hcloud.js +0 -29
- package/lib/interfaces/Global.d.ts +0 -8
- package/lib/interfaces/IDP.d.ts +0 -9
- package/lib/interfaces/Mail.d.ts +0 -29
- package/lib/interfaces/Mail.js +0 -8
- package/lib/service/Auditor.d.ts +0 -22
- package/lib/service/Auditor.js +0 -61
- package/lib/service/AuditorInternal.d.ts +0 -28
- package/lib/service/AuditorInternal.js +0 -65
- package/lib/service/High5.d.ts +0 -4
- package/lib/service/High5.js +0 -9
- package/lib/service/IDP.d.ts +0 -39
- package/lib/service/IDP.js +0 -84
- package/lib/service/Mailer.d.ts +0 -13
- package/lib/service/MailerInternal.d.ts +0 -32
- package/lib/service/MailerInternal.js +0 -64
- /package/lib/interfaces/{Global.js → agent/bundle/dev/index.js} +0 -0
- /package/lib/interfaces/{IDP.js → agent/context/index.js} +0 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import Base from "../../Base";
|
|
2
|
+
import { PaginatedResponse, SearchParams, Version } from "../../interfaces/global";
|
|
3
|
+
import { Agent, TargetAgent } from "../../interfaces/mothership";
|
|
4
|
+
type RecurrentInfo = Pick<Agent, "uptime" | "cpuUtilization" | "memoryUsed" | "status">;
|
|
5
|
+
type HelloInfo = RecurrentInfo & {
|
|
6
|
+
nickname?: string;
|
|
7
|
+
bundleVersion: string;
|
|
8
|
+
installerVersion?: string;
|
|
9
|
+
ip?: string;
|
|
10
|
+
};
|
|
11
|
+
export default class MothershipService extends Base {
|
|
12
|
+
/**
|
|
13
|
+
* Requests the endpoint version
|
|
14
|
+
* @returns Version object
|
|
15
|
+
*/
|
|
16
|
+
version(): Promise<Version>;
|
|
17
|
+
/**
|
|
18
|
+
* Say hello as an agent to the mothership
|
|
19
|
+
*
|
|
20
|
+
* @param uuid Agent's UUID
|
|
21
|
+
* @param uuidSignature HMAC-SHA256 hash of the Agent's UUID using the Agent's secret as the key
|
|
22
|
+
* @param info Information about the agent's uuid, hardware and nickname
|
|
23
|
+
* @return an Agent object
|
|
24
|
+
*/
|
|
25
|
+
hello(uuid: string, uuidSignature: string, info: HelloInfo): Promise<{
|
|
26
|
+
agent: Agent;
|
|
27
|
+
token: string;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Say hello again as an agent to the mothership.
|
|
31
|
+
*
|
|
32
|
+
* This call should only be made after an initial hello.
|
|
33
|
+
*
|
|
34
|
+
* The session token obtained in the hello endpoint must be used here. Use the setAuthToken method to do so.
|
|
35
|
+
*
|
|
36
|
+
* @param info Information about the agent's system resources.
|
|
37
|
+
* @return an Agent object
|
|
38
|
+
*/
|
|
39
|
+
helloAgain(info: RecurrentInfo): Promise<Agent>;
|
|
40
|
+
/**
|
|
41
|
+
* Register an agent to the mothership.
|
|
42
|
+
*
|
|
43
|
+
* This call should only be made once per agent, not once per agent session.
|
|
44
|
+
*
|
|
45
|
+
* @param uuid UUID of the Agent
|
|
46
|
+
* @param info Information about the agent's hardware and nickname.
|
|
47
|
+
* @param publicKey the public key of the agent that will be used for cryptography. The agent should remember its private key.
|
|
48
|
+
* @return an object holding a secret encrypted with the public key. The agent must decrypt it using its private key in order to use the /hello endpoint.
|
|
49
|
+
*/
|
|
50
|
+
register(uuid: string, info: Pick<Agent, Exclude<keyof Agent, "uuid" | "createDate" | "modifyDate" | "_id" | "ip">>, publicKey: string | Buffer): Promise<{
|
|
51
|
+
secret: string;
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* Connect to an organization.
|
|
55
|
+
*
|
|
56
|
+
* This call should only be made after an initial hello.
|
|
57
|
+
*
|
|
58
|
+
* The session token obtained in the hello endpoint must be used here. Use the setAuthToken method to do so.
|
|
59
|
+
*
|
|
60
|
+
* @param orgName Name of the organization
|
|
61
|
+
* @param memberToken JWT assigned to a member of the organization
|
|
62
|
+
* @param email Email of the user owner of the JWT
|
|
63
|
+
*/
|
|
64
|
+
connect(orgName: string, memberToken: string, email: string): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Disconnect from an organization.
|
|
67
|
+
*
|
|
68
|
+
* This call should only be made after an initial hello.
|
|
69
|
+
*
|
|
70
|
+
* The session token obtained in the hello endpoint must be used here. Use the setAuthToken method to do so.
|
|
71
|
+
*
|
|
72
|
+
* @param orgName Name of the organization
|
|
73
|
+
* @param email Email of the user
|
|
74
|
+
*/
|
|
75
|
+
disconnect(orgName: string, email: string): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Disconnect as a target.
|
|
78
|
+
*
|
|
79
|
+
* This call should only be made after an initial hello.
|
|
80
|
+
*
|
|
81
|
+
* The session token obtained in the hello endpoint must be used here. Use the setAuthToken method to do so.
|
|
82
|
+
*
|
|
83
|
+
* @param email Email of the target
|
|
84
|
+
*/
|
|
85
|
+
disconnectTarget(email: string): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Search among the available targets for a given organization.
|
|
88
|
+
*
|
|
89
|
+
* @param orgName Name of the organization
|
|
90
|
+
* @returns Object containing an array of retrieved agents and the total number of available found in the database (independent of limit and page)
|
|
91
|
+
*/
|
|
92
|
+
searchAvailableTargets({ orgName, filters, sorting, limit, page, }: SearchParams & {
|
|
93
|
+
orgName: string;
|
|
94
|
+
}): Promise<PaginatedResponse<TargetAgent>>;
|
|
95
|
+
protected getEndpoint(endpoint: string): string;
|
|
96
|
+
}
|
|
97
|
+
export {};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const Base_1 = require("../../Base");
|
|
13
|
+
const paginatedResponseHelper_1 = require("../../helper/paginatedResponseHelper");
|
|
14
|
+
const searchFilter_1 = require("../../helper/searchFilter");
|
|
15
|
+
class MothershipService extends Base_1.default {
|
|
16
|
+
/**
|
|
17
|
+
* Requests the endpoint version
|
|
18
|
+
* @returns Version object
|
|
19
|
+
*/
|
|
20
|
+
version() {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const resp = yield this.axios.get(this.getEndpoint("/v1/version"));
|
|
23
|
+
return resp.data;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Say hello as an agent to the mothership
|
|
28
|
+
*
|
|
29
|
+
* @param uuid Agent's UUID
|
|
30
|
+
* @param uuidSignature HMAC-SHA256 hash of the Agent's UUID using the Agent's secret as the key
|
|
31
|
+
* @param info Information about the agent's uuid, hardware and nickname
|
|
32
|
+
* @return an Agent object
|
|
33
|
+
*/
|
|
34
|
+
hello(uuid, uuidSignature, info) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
const resp = yield this.axios.post(this.getEndpoint("/v1/hello"), info, {
|
|
37
|
+
headers: {
|
|
38
|
+
Authorization: `Bearer ${uuid}.${uuidSignature}`,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
return { agent: resp.data, token: resp.headers.authorization };
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Say hello again as an agent to the mothership.
|
|
46
|
+
*
|
|
47
|
+
* This call should only be made after an initial hello.
|
|
48
|
+
*
|
|
49
|
+
* The session token obtained in the hello endpoint must be used here. Use the setAuthToken method to do so.
|
|
50
|
+
*
|
|
51
|
+
* @param info Information about the agent's system resources.
|
|
52
|
+
* @return an Agent object
|
|
53
|
+
*/
|
|
54
|
+
helloAgain(info) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const resp = yield this.axios.patch(this.getEndpoint("/v1/hello/again"), info);
|
|
57
|
+
return resp.data;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Register an agent to the mothership.
|
|
62
|
+
*
|
|
63
|
+
* This call should only be made once per agent, not once per agent session.
|
|
64
|
+
*
|
|
65
|
+
* @param uuid UUID of the Agent
|
|
66
|
+
* @param info Information about the agent's hardware and nickname.
|
|
67
|
+
* @param publicKey the public key of the agent that will be used for cryptography. The agent should remember its private key.
|
|
68
|
+
* @return an object holding a secret encrypted with the public key. The agent must decrypt it using its private key in order to use the /hello endpoint.
|
|
69
|
+
*/
|
|
70
|
+
// eslint-disable-next-line complexity
|
|
71
|
+
register(uuid, info, publicKey) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
if (typeof publicKey !== "string") {
|
|
74
|
+
publicKey = publicKey.toString("hex");
|
|
75
|
+
}
|
|
76
|
+
const resp = yield this.axios.post(this.getEndpoint("/v1/register"), Object.assign({ uuid, publicKey }, info));
|
|
77
|
+
return resp.data;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Connect to an organization.
|
|
82
|
+
*
|
|
83
|
+
* This call should only be made after an initial hello.
|
|
84
|
+
*
|
|
85
|
+
* The session token obtained in the hello endpoint must be used here. Use the setAuthToken method to do so.
|
|
86
|
+
*
|
|
87
|
+
* @param orgName Name of the organization
|
|
88
|
+
* @param memberToken JWT assigned to a member of the organization
|
|
89
|
+
* @param email Email of the user owner of the JWT
|
|
90
|
+
*/
|
|
91
|
+
connect(orgName, memberToken, email) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
yield this.axios.post(this.getEndpoint(`/v1/org/${orgName}/connect`), { memberToken, email });
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Disconnect from an organization.
|
|
98
|
+
*
|
|
99
|
+
* This call should only be made after an initial hello.
|
|
100
|
+
*
|
|
101
|
+
* The session token obtained in the hello endpoint must be used here. Use the setAuthToken method to do so.
|
|
102
|
+
*
|
|
103
|
+
* @param orgName Name of the organization
|
|
104
|
+
* @param email Email of the user
|
|
105
|
+
*/
|
|
106
|
+
disconnect(orgName, email) {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
yield this.axios.delete(this.getEndpoint(`/v1/org/${orgName}/connect/${email}`));
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Disconnect as a target.
|
|
113
|
+
*
|
|
114
|
+
* This call should only be made after an initial hello.
|
|
115
|
+
*
|
|
116
|
+
* The session token obtained in the hello endpoint must be used here. Use the setAuthToken method to do so.
|
|
117
|
+
*
|
|
118
|
+
* @param email Email of the target
|
|
119
|
+
*/
|
|
120
|
+
disconnectTarget(email) {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
yield this.axios.delete(this.getEndpoint(`/v1/connect/${email}`));
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Search among the available targets for a given organization.
|
|
127
|
+
*
|
|
128
|
+
* @param orgName Name of the organization
|
|
129
|
+
* @returns Object containing an array of retrieved agents and the total number of available found in the database (independent of limit and page)
|
|
130
|
+
*/
|
|
131
|
+
searchAvailableTargets(_a) {
|
|
132
|
+
return __awaiter(this, arguments, void 0, function* ({ orgName, filters, sorting, limit = 25, page = 0, }) {
|
|
133
|
+
const filtersDTO = filters === null || filters === void 0 ? void 0 : filters.map((f) => {
|
|
134
|
+
return new searchFilter_1.SearchFilterDTO(f);
|
|
135
|
+
});
|
|
136
|
+
const resp = yield this.axios.post(this.getEndpoint(`/v1/org/${orgName}/connect/search`), {
|
|
137
|
+
filters: filtersDTO,
|
|
138
|
+
sorting,
|
|
139
|
+
}, {
|
|
140
|
+
params: { limit, page },
|
|
141
|
+
});
|
|
142
|
+
return (0, paginatedResponseHelper_1.createPaginatedResponse)(resp);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
getEndpoint(endpoint) {
|
|
146
|
+
return `${this.options.server}/api/mothership${endpoint}`;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.default = MothershipService;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Msg, NatsConnection, PublishOptions, RequestOptions, Subscription, SubscriptionOptions } from "nats";
|
|
2
|
+
import Base from "../../Base";
|
|
3
|
+
import { NatsCallback, NatsMessageType, NatsObject, NatsObjectType, RawMsg } from "../../interfaces/nats";
|
|
4
|
+
/**
|
|
5
|
+
* Connect and authenticate using email and jwt
|
|
6
|
+
*
|
|
7
|
+
* to use websocket from within node, forceWebsocket can be used.
|
|
8
|
+
* A websocket library is required to be pre-installed and needs to be set as global:
|
|
9
|
+
* import WebSocket from "ws";
|
|
10
|
+
* Object.assign(global, { WebSocket: WebSocket });
|
|
11
|
+
*/
|
|
12
|
+
type ConnectParamsJwt = {
|
|
13
|
+
email: string;
|
|
14
|
+
jwt: string;
|
|
15
|
+
servers?: string[];
|
|
16
|
+
debug?: boolean;
|
|
17
|
+
forceWebsocket?: boolean;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Connect and authenticate using username and password
|
|
21
|
+
* Can only be used with the CUSTOM_AUTH admin!
|
|
22
|
+
*
|
|
23
|
+
* to use websocket from within node, forceWebsocket can be used.
|
|
24
|
+
* A websocket library is required to be pre-installed and needs to be set as global:
|
|
25
|
+
* import WebSocket from "ws";
|
|
26
|
+
* Object.assign(global, { WebSocket: WebSocket });
|
|
27
|
+
*/
|
|
28
|
+
type ConnectParamsPassword = {
|
|
29
|
+
username: string;
|
|
30
|
+
password: string;
|
|
31
|
+
servers?: string[];
|
|
32
|
+
debug?: boolean;
|
|
33
|
+
forceWebsocket?: boolean;
|
|
34
|
+
};
|
|
35
|
+
declare class Nats extends Base {
|
|
36
|
+
private natsConnection;
|
|
37
|
+
private subMap;
|
|
38
|
+
private connection;
|
|
39
|
+
connect(params: ConnectParamsJwt | ConnectParamsPassword): Promise<NatsConnection>;
|
|
40
|
+
getConnection: () => NatsConnection | undefined;
|
|
41
|
+
sub(subject: string, callback: NatsCallback, options?: SubscriptionOptions): Promise<Subscription>;
|
|
42
|
+
unsub(subject: string | Subscription): void;
|
|
43
|
+
publish(subject: string, type: NatsMessageType, objectType: NatsObjectType, object: NatsObject, options?: PublishOptions): void;
|
|
44
|
+
request(subject: string, type: NatsMessageType, objectType: NatsObjectType, object: unknown, options?: RequestOptions): void;
|
|
45
|
+
requestAndWaitForResponse(subject: string, type: NatsMessageType, objectType: NatsObjectType, object: unknown, options?: RequestOptions): Promise<Msg | undefined>;
|
|
46
|
+
respond(msg: Msg | RawMsg, data: unknown): void;
|
|
47
|
+
protected getEndpoint(endpoint: string): string;
|
|
48
|
+
}
|
|
49
|
+
export default Nats;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const nats_1 = require("nats");
|
|
13
|
+
const nats_ws_1 = require("nats.ws");
|
|
14
|
+
const Base_1 = require("../../Base");
|
|
15
|
+
const isBrowser = typeof window !== "undefined";
|
|
16
|
+
class Nats extends Base_1.default {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...arguments);
|
|
19
|
+
this.subMap = [];
|
|
20
|
+
this.connection = isBrowser ? nats_ws_1.connect : nats_1.connect;
|
|
21
|
+
this.getConnection = () => {
|
|
22
|
+
return this.natsConnection;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
// eslint-disable-next-line complexity
|
|
26
|
+
connect(params) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
if (params.forceWebsocket) {
|
|
29
|
+
this.connection = nats_ws_1.connect;
|
|
30
|
+
}
|
|
31
|
+
if (!params.servers) {
|
|
32
|
+
// set defaults if servers array is empty
|
|
33
|
+
if (isBrowser) {
|
|
34
|
+
// default via traefik exposed servers
|
|
35
|
+
params.servers = [this.getEndpoint("/v1/0"), this.getEndpoint("/v1/1"), this.getEndpoint("/v1/2")];
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
// default kubernetes internal servers
|
|
39
|
+
params.servers = ["hcloud-nats-0.hcloud-nats:4222", "hcloud-nats-1.hcloud-nats:4222", "hcloud-nats-2.hcloud-nats:4222"];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
this.natsConnection = yield this.connection({
|
|
43
|
+
debug: params.debug,
|
|
44
|
+
maxReconnectAttempts: -1,
|
|
45
|
+
servers: params.servers,
|
|
46
|
+
pingInterval: 55 * 1000, //ping every 55 seconds
|
|
47
|
+
user: params.email !== undefined ? params.email : params.username,
|
|
48
|
+
pass: params.jwt !== undefined ? params.jwt : params.password,
|
|
49
|
+
});
|
|
50
|
+
return this.natsConnection;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
sub(subject, callback, options) {
|
|
54
|
+
var _a;
|
|
55
|
+
let delay = 0;
|
|
56
|
+
if (!this.getConnection() || ((_a = this.getConnection()) === null || _a === void 0 ? void 0 : _a.isClosed())) {
|
|
57
|
+
delay = 3000;
|
|
58
|
+
}
|
|
59
|
+
// add delay just in case the connection has not been established yet
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
const newOptions = Object.assign(Object.assign({}, options), { callback: (err, msg) => {
|
|
62
|
+
if (err !== null) {
|
|
63
|
+
try {
|
|
64
|
+
callback(err);
|
|
65
|
+
}
|
|
66
|
+
catch (ignored) {
|
|
67
|
+
// ignore callback errors
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
let parsedData;
|
|
72
|
+
try {
|
|
73
|
+
const data = new TextDecoder("utf-8").decode(msg.data);
|
|
74
|
+
parsedData = JSON.parse(data);
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
callback(e);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
callback(null, parsedData, msg);
|
|
82
|
+
}
|
|
83
|
+
catch (ignored) {
|
|
84
|
+
// ignore callback errors
|
|
85
|
+
}
|
|
86
|
+
} });
|
|
87
|
+
setTimeout(() => {
|
|
88
|
+
var _a, _b;
|
|
89
|
+
if (!this.getConnection() || !((_a = this.getConnection()) === null || _a === void 0 ? void 0 : _a.isClosed)) {
|
|
90
|
+
reject(new Error("connection not established, can not subscribe"));
|
|
91
|
+
}
|
|
92
|
+
const sub = (_b = this.getConnection()) === null || _b === void 0 ? void 0 : _b.subscribe(subject, newOptions);
|
|
93
|
+
if (sub) {
|
|
94
|
+
this.subMap.push({ subject, sub: sub });
|
|
95
|
+
return resolve(sub);
|
|
96
|
+
}
|
|
97
|
+
return reject(new Error("could not subscribe"));
|
|
98
|
+
}, delay);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
unsub(subject) {
|
|
102
|
+
if (typeof subject === "string") {
|
|
103
|
+
this.subMap.forEach((s) => {
|
|
104
|
+
if (s.subject === subject) {
|
|
105
|
+
s.sub.unsubscribe();
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
subject === null || subject === void 0 ? void 0 : subject.unsubscribe();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
publish(subject, type, objectType, object, options) {
|
|
114
|
+
var _a;
|
|
115
|
+
const data = new TextEncoder().encode(JSON.stringify({ type: type, objectType: objectType, object: object }));
|
|
116
|
+
(_a = this.getConnection()) === null || _a === void 0 ? void 0 : _a.publish(subject, data, options);
|
|
117
|
+
}
|
|
118
|
+
request(subject, type, objectType, object, options) {
|
|
119
|
+
var _a;
|
|
120
|
+
const data = new TextEncoder().encode(JSON.stringify({ type: type, objectType: objectType, object: object }));
|
|
121
|
+
(_a = this.getConnection()) === null || _a === void 0 ? void 0 : _a.request(subject, data, options);
|
|
122
|
+
}
|
|
123
|
+
requestAndWaitForResponse(subject, type, objectType, object, options) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
var _a;
|
|
126
|
+
const data = new TextEncoder().encode(JSON.stringify({ type: type, objectType: objectType, object: object }));
|
|
127
|
+
return ((_a = this.getConnection()) === null || _a === void 0 ? void 0 : _a.request(subject, data, options)) || undefined;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
respond(msg, data) {
|
|
131
|
+
const encodedData = new TextEncoder().encode(JSON.stringify(data));
|
|
132
|
+
msg.respond(encodedData);
|
|
133
|
+
}
|
|
134
|
+
getEndpoint(endpoint) {
|
|
135
|
+
return `${this.options.server}/ws/nats${endpoint}`;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.default = Nats;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Select<T, Mandatory extends keyof T, Optional extends keyof T> = Pick<T, Mandatory> & Partial<Pick<T, Optional>>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BouncerContext, HcloudFeature } from "../../../interfaces/bouncer";
|
|
2
|
+
export type BouncerProviderLogger = (featureName: string, defaultValue: boolean, result: boolean, context?: BouncerContext, feature?: HcloudFeature) => void;
|
|
3
|
+
export declare class BouncerProvider {
|
|
4
|
+
private features;
|
|
5
|
+
private context?;
|
|
6
|
+
private logger?;
|
|
7
|
+
private refs;
|
|
8
|
+
constructor(features: HcloudFeature[], context?: BouncerContext, logger?: BouncerProviderLogger);
|
|
9
|
+
isEnabled(featureName: string, defaultValue: boolean, context?: BouncerContext): boolean;
|
|
10
|
+
isEnabledFn(featureName: string, defaultValue: boolean, fn: (val: boolean) => void, context?: BouncerContext): boolean;
|
|
11
|
+
processRefs(): void;
|
|
12
|
+
addFeature(feature: HcloudFeature): void;
|
|
13
|
+
setFeatures(features: HcloudFeature[]): void;
|
|
14
|
+
setContext(context: BouncerContext): void;
|
|
15
|
+
updateContext({ region, email, organization }: BouncerContext): void;
|
|
16
|
+
private doesMatchRegion;
|
|
17
|
+
private doesMatchUser;
|
|
18
|
+
private doesMatchOrganization;
|
|
19
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BouncerProvider = void 0;
|
|
4
|
+
class BouncerProvider {
|
|
5
|
+
constructor(features, context, logger) {
|
|
6
|
+
// refs holds a list of previous isEnabledFn requests
|
|
7
|
+
// with their according callback function (fn)
|
|
8
|
+
// that is being called whenever features or the context has changed
|
|
9
|
+
this.refs = [];
|
|
10
|
+
this.features = features;
|
|
11
|
+
this.context = context;
|
|
12
|
+
this.logger = logger;
|
|
13
|
+
}
|
|
14
|
+
/* eslint-disable complexity */
|
|
15
|
+
isEnabled(featureName, defaultValue, context) {
|
|
16
|
+
const feature = this.features.find(f => f.name === featureName);
|
|
17
|
+
let result = defaultValue;
|
|
18
|
+
if (feature) {
|
|
19
|
+
result =
|
|
20
|
+
feature.enabled &&
|
|
21
|
+
this.doesMatchOrganization(feature, context !== null && context !== void 0 ? context : this.context) &&
|
|
22
|
+
this.doesMatchUser(feature, context !== null && context !== void 0 ? context : this.context) &&
|
|
23
|
+
this.doesMatchRegion(feature, context !== null && context !== void 0 ? context : this.context);
|
|
24
|
+
}
|
|
25
|
+
if (this.logger) {
|
|
26
|
+
this.logger(featureName, defaultValue, result, context !== null && context !== void 0 ? context : this.context, feature);
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
isEnabledFn(featureName, defaultValue, fn, context) {
|
|
31
|
+
this.refs.push({ featureName, defaultValue, fn, context });
|
|
32
|
+
return this.isEnabled(featureName, defaultValue, context);
|
|
33
|
+
}
|
|
34
|
+
// processRefs iterates over all refs and calls their callback function with the result of isEnabled
|
|
35
|
+
processRefs() {
|
|
36
|
+
this.refs.forEach(ref => {
|
|
37
|
+
ref.fn(this.isEnabled(ref.featureName, ref.defaultValue, ref.context));
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
addFeature(feature) {
|
|
41
|
+
this.features.push(feature);
|
|
42
|
+
this.processRefs();
|
|
43
|
+
}
|
|
44
|
+
setFeatures(features) {
|
|
45
|
+
this.features = features;
|
|
46
|
+
this.processRefs();
|
|
47
|
+
}
|
|
48
|
+
setContext(context) {
|
|
49
|
+
this.context = context;
|
|
50
|
+
this.processRefs();
|
|
51
|
+
}
|
|
52
|
+
updateContext({ region, email, organization }) {
|
|
53
|
+
if (!this.context) {
|
|
54
|
+
this.context = {
|
|
55
|
+
email,
|
|
56
|
+
organization,
|
|
57
|
+
region,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
this.context.email = email !== null && email !== void 0 ? email : this.context.email;
|
|
62
|
+
this.context.organization = organization !== null && organization !== void 0 ? organization : this.context.organization;
|
|
63
|
+
this.context.region = region !== null && region !== void 0 ? region : this.context.region;
|
|
64
|
+
}
|
|
65
|
+
this.processRefs();
|
|
66
|
+
}
|
|
67
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion*/
|
|
68
|
+
doesMatchRegion(feature, context) {
|
|
69
|
+
if (feature.regions.length) {
|
|
70
|
+
if (context === null || context === void 0 ? void 0 : context.region) {
|
|
71
|
+
return (feature.regions.map(r => r.replace("*", "(.+)")).find(r => r === (context === null || context === void 0 ? void 0 : context.region) || new RegExp(r).test(context.region)) !==
|
|
72
|
+
undefined);
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion*/
|
|
79
|
+
doesMatchUser(feature, context) {
|
|
80
|
+
if (feature.users.length) {
|
|
81
|
+
if (context === null || context === void 0 ? void 0 : context.email) {
|
|
82
|
+
return (feature.users.map(u => u.replace("*", "(.+)")).find(u => u === context.email || new RegExp(u).test(context.email)) !== undefined);
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion*/
|
|
89
|
+
doesMatchOrganization(feature, context) {
|
|
90
|
+
if (feature.organizations.length) {
|
|
91
|
+
if (context === null || context === void 0 ? void 0 : context.organization) {
|
|
92
|
+
return (feature.organizations
|
|
93
|
+
.map(o => o.replace("*", "(.+)"))
|
|
94
|
+
.find(o => o === context.organization || new RegExp(o).test(context.organization)) !== undefined);
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.BouncerProvider = BouncerProvider;
|
package/package.json
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hcloud-sdk",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "15.0.0",
|
|
4
4
|
"description": "hcloud platform sdk",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "mocha -r ts-node/register tests/**/*.test.ts",
|
|
9
|
+
"format": "prettier --write \"src/**/*.ts\" \"tests/**/*.test.ts\"",
|
|
10
|
+
"lint": "eslint --max-warnings=0 --fix src/ tests/ --ext .ts",
|
|
11
|
+
"doc:build": "vuepress build _docs/src",
|
|
12
|
+
"doc:dev": "vuepress dev _docs/src",
|
|
13
|
+
"doc:export": "vuepress export _docs/src",
|
|
14
|
+
"build": "tsc"
|
|
15
|
+
},
|
|
7
16
|
"repository": {
|
|
8
17
|
"type": "git",
|
|
9
18
|
"url": "git+https://github.com/moovit-sp-gmbh/hcloud-sdk-js.git"
|
|
@@ -19,33 +28,32 @@
|
|
|
19
28
|
"author": "moovit-sp-gmbh",
|
|
20
29
|
"homepage": "https://github.com/moovit-sp-gmbh/hcloud-sdk-js#readme",
|
|
21
30
|
"devDependencies": {
|
|
22
|
-
"@
|
|
23
|
-
"@
|
|
24
|
-
"@
|
|
25
|
-
"@
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"mocha": "^10.0.
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
31
|
+
"@commitlint/cli": "^18.6.1",
|
|
32
|
+
"@commitlint/config-conventional": "^18.6.3",
|
|
33
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
34
|
+
"@semantic-release/git": "^10.0.1",
|
|
35
|
+
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
|
|
36
|
+
"@types/chai": "^4.3.17",
|
|
37
|
+
"@types/mocha": "^10.0.7",
|
|
38
|
+
"@types/node": "^20.14.8",
|
|
39
|
+
"@typescript-eslint/eslint-plugin": "^7.0.2",
|
|
40
|
+
"@typescript-eslint/parser": "^7.0.2",
|
|
41
|
+
"chai": "^4.5.0",
|
|
42
|
+
"conventional-changelog-conventionalcommits": "^8.0.0",
|
|
43
|
+
"dayjs": "^1.11.12",
|
|
44
|
+
"eslint": "^8.57.0",
|
|
45
|
+
"eslint-config-prettier": "^8.10.0",
|
|
46
|
+
"eslint-plugin-import": "^2.29.1",
|
|
47
|
+
"mocha": "^10.7.3",
|
|
48
|
+
"prettier": "^3.3.3",
|
|
49
|
+
"semantic-release": "^23.1.1",
|
|
50
|
+
"semantic-release-telegram": "^1.6.2",
|
|
51
|
+
"ts-node": "^10.9.2",
|
|
52
|
+
"typescript": "^5.5.4"
|
|
37
53
|
},
|
|
38
54
|
"dependencies": {
|
|
39
|
-
"axios": "^
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"lint": "tslint -p tsconfig.json",
|
|
45
|
-
"doc:build": "vuepress build _docs/src",
|
|
46
|
-
"doc:dev": "vuepress dev _docs/src",
|
|
47
|
-
"doc:export": "vuepress export _docs/src",
|
|
48
|
-
"build": "tsc"
|
|
49
|
-
},
|
|
50
|
-
"readme": "# hcloud-sdk\n[](https://opensource.org/licenses/MIT)\n[](https://www.npmjs.com/package/hcloud-sdk)\n"
|
|
51
|
-
}
|
|
55
|
+
"axios": "^1.7.3",
|
|
56
|
+
"nats": "^2.28.2",
|
|
57
|
+
"nats.ws": "^1.29.2"
|
|
58
|
+
}
|
|
59
|
+
}
|
package/lib/base.d.ts
DELETED