@gitpod/gitpod-protocol 0.1.5-v0.6.0-beta4 → 0.1.5-vn-implement-jetbrains-terminals.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/data/builtin-theia-plugins.json +9 -9
- package/data/gitpod-schema.json +25 -24
- package/lib/accounting-protocol.d.ts +155 -0
- package/lib/accounting-protocol.d.ts.map +1 -0
- package/lib/accounting-protocol.js +109 -0
- package/lib/accounting-protocol.js.map +1 -0
- package/lib/admin-protocol.d.ts +31 -4
- package/lib/admin-protocol.d.ts.map +1 -1
- package/lib/admin-protocol.js +15 -0
- package/lib/admin-protocol.js.map +1 -1
- package/lib/analytics.d.ts +45 -0
- package/lib/analytics.d.ts.map +1 -0
- package/lib/analytics.js +10 -0
- package/lib/analytics.js.map +1 -0
- package/lib/auth.d.ts +25 -0
- package/lib/auth.d.ts.map +1 -0
- package/lib/auth.js +16 -0
- package/lib/auth.js.map +1 -0
- package/lib/context-url.d.ts +31 -0
- package/lib/context-url.d.ts.map +1 -0
- package/lib/context-url.js +102 -0
- package/lib/context-url.js.map +1 -0
- package/lib/context-url.spec.d.ts +14 -0
- package/lib/context-url.spec.d.ts.map +1 -0
- package/lib/context-url.spec.js +94 -0
- package/lib/context-url.spec.js.map +1 -0
- package/lib/email-protocol.d.ts +1 -2
- package/lib/email-protocol.d.ts.map +1 -1
- package/lib/email-protocol.js +4 -4
- package/lib/email-protocol.js.map +1 -1
- package/lib/encryption/container-module.js +5 -4
- package/lib/encryption/container-module.js.map +1 -1
- package/lib/encryption/encryption-engine.js +19 -20
- package/lib/encryption/encryption-engine.js.map +1 -1
- package/lib/encryption/encryption-engine.spec.js +29 -36
- package/lib/encryption/encryption-engine.spec.js.map +1 -1
- package/lib/encryption/encryption-service.js +29 -43
- package/lib/encryption/encryption-service.js.map +1 -1
- package/lib/encryption/key-provider.js +25 -30
- package/lib/encryption/key-provider.js.map +1 -1
- package/lib/env.d.ts +1 -2
- package/lib/env.d.ts.map +1 -1
- package/lib/env.js +20 -21
- package/lib/env.js.map +1 -1
- package/lib/gitpod-file-parser.js +25 -41
- package/lib/gitpod-file-parser.js.map +1 -1
- package/lib/gitpod-file-parser.spec.js +116 -116
- package/lib/gitpod-file-parser.spec.js.map +1 -1
- package/lib/gitpod-service.d.ts +162 -20
- package/lib/gitpod-service.d.ts.map +1 -1
- package/lib/gitpod-service.js +170 -256
- package/lib/gitpod-service.js.map +1 -1
- package/lib/headless-workspace-log.d.ts +8 -11
- package/lib/headless-workspace-log.d.ts.map +1 -1
- package/lib/headless-workspace-log.js +4 -7
- package/lib/headless-workspace-log.js.map +1 -1
- package/lib/ide-frontend-service.d.ts +4 -0
- package/lib/ide-frontend-service.d.ts.map +1 -1
- package/lib/ide-protocol.d.ts +105 -0
- package/lib/ide-protocol.d.ts.map +1 -0
- package/lib/ide-protocol.js +8 -0
- package/lib/ide-protocol.js.map +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +7 -1
- package/lib/index.js.map +1 -1
- package/lib/installation-admin-protocol.d.ts +21 -0
- package/lib/installation-admin-protocol.d.ts.map +1 -0
- package/lib/installation-admin-protocol.js +30 -0
- package/lib/installation-admin-protocol.js.map +1 -0
- package/lib/messaging/browser/connection.d.ts +5 -3
- package/lib/messaging/browser/connection.d.ts.map +1 -1
- package/lib/messaging/browser/connection.js +183 -33
- package/lib/messaging/browser/connection.js.map +1 -1
- package/lib/messaging/browser/window-connection.js +35 -55
- package/lib/messaging/browser/window-connection.js.map +1 -1
- package/lib/messaging/client-call-metrics.d.ts +35 -0
- package/lib/messaging/client-call-metrics.d.ts.map +1 -0
- package/lib/messaging/client-call-metrics.js +83 -0
- package/lib/messaging/client-call-metrics.js.map +1 -0
- package/lib/messaging/error.d.ts +5 -1
- package/lib/messaging/error.d.ts.map +1 -1
- package/lib/messaging/error.js +10 -2
- package/lib/messaging/error.js.map +1 -1
- package/lib/messaging/handler.d.ts +10 -0
- package/lib/messaging/handler.d.ts.map +1 -1
- package/lib/messaging/node/connection.d.ts +1 -17
- package/lib/messaging/node/connection.d.ts.map +1 -1
- package/lib/messaging/node/connection.js +23 -59
- package/lib/messaging/node/connection.js.map +1 -1
- package/lib/messaging/proxy-factory.d.ts +2 -0
- package/lib/messaging/proxy-factory.d.ts.map +1 -1
- package/lib/messaging/proxy-factory.js +74 -159
- package/lib/messaging/proxy-factory.js.map +1 -1
- package/lib/oss-allowlist.d.ts +14 -0
- package/lib/oss-allowlist.d.ts.map +1 -0
- package/lib/oss-allowlist.js +8 -0
- package/lib/oss-allowlist.js.map +1 -0
- package/lib/payment-protocol.d.ts +18 -0
- package/lib/payment-protocol.d.ts.map +1 -0
- package/lib/payment-protocol.js +13 -0
- package/lib/payment-protocol.js.map +1 -0
- package/lib/permission.d.ts +5 -3
- package/lib/permission.d.ts.map +1 -1
- package/lib/permission.js +18 -17
- package/lib/permission.js.map +1 -1
- package/lib/plans.d.ts +210 -0
- package/lib/plans.d.ts.map +1 -0
- package/lib/plans.js +570 -0
- package/lib/plans.js.map +1 -0
- package/lib/protocol.d.ts +120 -58
- package/lib/protocol.d.ts.map +1 -1
- package/lib/protocol.js +116 -130
- package/lib/protocol.js.map +1 -1
- package/lib/snapshot-url.d.ts +14 -0
- package/lib/snapshot-url.d.ts.map +1 -0
- package/lib/snapshot-url.js +26 -0
- package/lib/snapshot-url.js.map +1 -0
- package/{src/util/without.ts → lib/snapshot-url.spec.d.ts} +2 -3
- package/lib/snapshot-url.spec.d.ts.map +1 -0
- package/lib/snapshot-url.spec.js +41 -0
- package/lib/snapshot-url.spec.js.map +1 -0
- package/lib/team-subscription-protocol.d.ts +73 -0
- package/lib/team-subscription-protocol.d.ts.map +1 -0
- package/lib/team-subscription-protocol.js +63 -0
- package/lib/team-subscription-protocol.js.map +1 -0
- package/lib/teams-projects-protocol.d.ts +113 -0
- package/lib/teams-projects-protocol.d.ts.map +1 -0
- package/lib/teams-projects-protocol.js +30 -0
- package/lib/teams-projects-protocol.js.map +1 -0
- package/lib/util/analytics.d.ts +8 -0
- package/lib/util/analytics.d.ts.map +1 -0
- package/lib/util/analytics.js +79 -0
- package/lib/util/analytics.js.map +1 -0
- package/lib/util/async-iterator.js +55 -133
- package/lib/util/async-iterator.js.map +1 -1
- package/lib/util/cancelable.js +17 -59
- package/lib/util/cancelable.js.map +1 -1
- package/lib/util/date-time.js +8 -8
- package/lib/util/date-time.js.map +1 -1
- package/lib/util/deferred.js +10 -12
- package/lib/util/deferred.js.map +1 -1
- package/lib/util/disposable.js +26 -39
- package/lib/util/disposable.js.map +1 -1
- package/lib/util/event.js +58 -74
- package/lib/util/event.js.map +1 -1
- package/lib/util/garbage-collected-cache.d.ts +1 -0
- package/lib/util/garbage-collected-cache.d.ts.map +1 -1
- package/lib/util/garbage-collected-cache.js +26 -46
- package/lib/util/garbage-collected-cache.js.map +1 -1
- package/lib/util/generate-workspace-id.d.ts +4 -0
- package/lib/util/generate-workspace-id.d.ts.map +1 -0
- package/lib/util/generate-workspace-id.js +487 -0
- package/lib/util/generate-workspace-id.js.map +1 -0
- package/lib/util/{without.d.ts → generate-workspace-id.spec.d.ts} +2 -2
- package/lib/util/generate-workspace-id.spec.d.ts.map +1 -0
- package/lib/util/generate-workspace-id.spec.js +87 -0
- package/lib/util/generate-workspace-id.spec.js.map +1 -0
- package/lib/util/gitpod-cookie.d.ts +20 -0
- package/lib/util/gitpod-cookie.d.ts.map +1 -0
- package/lib/util/gitpod-cookie.js +44 -0
- package/lib/util/gitpod-cookie.js.map +1 -0
- package/lib/util/gitpod-host-url.d.ts +2 -2
- package/lib/util/gitpod-host-url.d.ts.map +1 -1
- package/lib/util/gitpod-host-url.js +96 -95
- package/lib/util/gitpod-host-url.js.map +1 -1
- package/lib/util/gitpod-host-url.spec.d.ts +8 -1
- package/lib/util/gitpod-host-url.spec.d.ts.map +1 -1
- package/lib/util/gitpod-host-url.spec.js +104 -22
- package/lib/util/gitpod-host-url.spec.js.map +1 -1
- package/lib/util/grpc.d.ts +15 -0
- package/lib/util/grpc.d.ts.map +1 -0
- package/lib/util/grpc.js +18 -0
- package/lib/util/grpc.js.map +1 -0
- package/lib/util/jaeger-client-types.d.ts +68 -0
- package/lib/util/jaeger-client-types.d.ts.map +1 -0
- package/lib/util/{without.js → jaeger-client-types.js} +1 -1
- package/lib/util/jaeger-client-types.js.map +1 -0
- package/lib/util/logging.d.ts +49 -33
- package/lib/util/logging.d.ts.map +1 -1
- package/lib/util/logging.js +107 -110
- package/lib/util/logging.js.map +1 -1
- package/lib/util/make-link.js +2 -2
- package/lib/util/make-link.js.map +1 -1
- package/lib/util/parse-workspace-id.d.ts +13 -3
- package/lib/util/parse-workspace-id.d.ts.map +1 -1
- package/lib/util/parse-workspace-id.js +38 -8
- package/lib/util/parse-workspace-id.js.map +1 -1
- package/lib/util/parse-workspace-id.spec.d.ts +8 -0
- package/lib/util/parse-workspace-id.spec.d.ts.map +1 -1
- package/lib/util/parse-workspace-id.spec.js +127 -47
- package/lib/util/parse-workspace-id.spec.js.map +1 -1
- package/lib/util/queue.js +16 -55
- package/lib/util/queue.js.map +1 -1
- package/lib/util/queue.spec.js +144 -288
- package/lib/util/queue.spec.js.map +1 -1
- package/lib/util/repeat.d.ts +15 -0
- package/lib/util/repeat.d.ts.map +1 -0
- package/lib/util/repeat.js +55 -0
- package/lib/util/repeat.js.map +1 -0
- package/lib/util/semaphore.js +15 -46
- package/lib/util/semaphore.js.map +1 -1
- package/lib/util/skip-if.js +6 -6
- package/lib/util/skip-if.js.map +1 -1
- package/lib/util/timeutil.js +28 -16
- package/lib/util/timeutil.js.map +1 -1
- package/lib/util/timeutil.spec.js +21 -24
- package/lib/util/timeutil.spec.js.map +1 -1
- package/lib/util/tracing.d.ts +51 -5
- package/lib/util/tracing.d.ts.map +1 -1
- package/lib/util/tracing.js +197 -62
- package/lib/util/tracing.js.map +1 -1
- package/lib/util/tracing.spec.d.ts +7 -0
- package/lib/util/tracing.spec.d.ts.map +1 -0
- package/lib/util/tracing.spec.js +121 -0
- package/lib/util/tracing.spec.js.map +1 -0
- package/lib/util/workspace-port-authentication.js +3 -2
- package/lib/util/workspace-port-authentication.js.map +1 -1
- package/lib/workspace-cluster.d.ts +71 -0
- package/lib/workspace-cluster.d.ts.map +1 -0
- package/lib/workspace-cluster.js +16 -0
- package/lib/workspace-cluster.js.map +1 -0
- package/lib/workspace-instance.d.ts +26 -2
- package/lib/workspace-instance.d.ts.map +1 -1
- package/lib/wsready.d.ts +1 -1
- package/lib/wsready.js +2 -2
- package/package.json +33 -17
- package/pkg-yarn.lock +18 -9
- package/provenance-bundle.jsonl +2 -0
- package/src/accounting-protocol.ts +229 -0
- package/src/admin-protocol.ts +53 -5
- package/src/analytics.ts +54 -0
- package/src/auth.ts +27 -0
- package/src/context-url.spec.ts +53 -0
- package/src/context-url.ts +107 -0
- package/src/email-protocol.ts +2 -3
- package/src/env.ts +10 -10
- package/src/gitpod-service.ts +237 -38
- package/src/headless-workspace-log.ts +7 -11
- package/src/ide-frontend-service.ts +5 -1
- package/src/ide-protocol.ts +119 -0
- package/src/index.ts +7 -1
- package/src/installation-admin-protocol.ts +35 -0
- package/src/messaging/browser/connection.ts +195 -14
- package/src/messaging/client-call-metrics.ts +97 -0
- package/src/messaging/error.ts +14 -2
- package/src/messaging/handler.ts +12 -0
- package/src/messaging/node/connection.ts +21 -68
- package/src/messaging/proxy-factory.ts +14 -6
- package/src/oss-allowlist.ts +15 -0
- package/src/payment-protocol.ts +20 -0
- package/src/permission.ts +7 -6
- package/src/plans.ts +632 -0
- package/src/protocol.ts +194 -87
- package/src/snapshot-url.spec.ts +25 -0
- package/src/snapshot-url.ts +27 -0
- package/src/team-subscription-protocol.ts +113 -0
- package/src/teams-projects-protocol.ts +147 -0
- package/src/util/analytics.ts +87 -0
- package/src/util/deferred.ts +1 -1
- package/src/util/garbage-collected-cache.ts +9 -3
- package/src/util/generate-workspace-id.spec.ts +48 -0
- package/src/util/generate-workspace-id.ts +475 -0
- package/src/util/gitpod-cookie.ts +39 -0
- package/src/util/gitpod-host-url.spec.ts +30 -1
- package/src/util/gitpod-host-url.ts +27 -13
- package/src/util/grpc.ts +15 -0
- package/src/util/jaeger-client-types.ts +102 -0
- package/src/util/logging.ts +102 -38
- package/src/util/parse-workspace-id.spec.ts +45 -4
- package/src/util/parse-workspace-id.ts +38 -7
- package/src/util/queue.spec.ts +1 -1
- package/src/util/repeat.ts +45 -0
- package/src/util/semaphore.ts +2 -2
- package/src/util/skip-if.ts +1 -1
- package/src/util/timeutil.ts +4 -4
- package/src/util/tracing.spec.ts +83 -0
- package/src/util/tracing.ts +183 -17
- package/src/workspace-cluster.ts +91 -0
- package/src/workspace-instance.ts +51 -13
- package/src/wsready.ts +2 -2
- package/lib/messaging/connection-error-handler.d.ts +0 -27
- package/lib/messaging/connection-error-handler.d.ts.map +0 -1
- package/lib/messaging/connection-error-handler.js +0 -46
- package/lib/messaging/connection-error-handler.js.map +0 -1
- package/lib/util/repeater.d.ts +0 -22
- package/lib/util/repeater.d.ts.map +0 -1
- package/lib/util/repeater.js +0 -118
- package/lib/util/repeater.js.map +0 -1
- package/lib/util/safe-promise.d.ts +0 -11
- package/lib/util/safe-promise.d.ts.map +0 -1
- package/lib/util/safe-promise.js +0 -34
- package/lib/util/safe-promise.js.map +0 -1
- package/lib/util/without.d.ts.map +0 -1
- package/lib/util/without.js.map +0 -1
- package/src/messaging/connection-error-handler.ts +0 -62
- package/src/util/jaeger-client.d.ts +0 -105
- package/src/util/repeater.ts +0 -49
- package/src/util/safe-promise.ts +0 -26
package/src/protocol.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import { WorkspaceInstance, PortVisibility } from "./workspace-instance";
|
|
8
8
|
import { RoleOrPermission } from "./permission";
|
|
9
|
+
import { Project } from "./teams-projects-protocol";
|
|
9
10
|
|
|
10
11
|
export interface UserInfo {
|
|
11
12
|
name?: string
|
|
@@ -27,19 +28,12 @@ export interface User {
|
|
|
27
28
|
|
|
28
29
|
identities: Identity[]
|
|
29
30
|
|
|
30
|
-
allowsMarketingCommunication: boolean;
|
|
31
|
-
|
|
32
31
|
/**
|
|
33
32
|
* Whether the user has been blocked to use our service, because of TOS violation for example.
|
|
34
33
|
* Optional for backwards compatibility.
|
|
35
34
|
*/
|
|
36
35
|
blocked?: boolean;
|
|
37
36
|
|
|
38
|
-
/**
|
|
39
|
-
* whether this user can run workspaces in privileged mode
|
|
40
|
-
*/
|
|
41
|
-
privileged?: boolean;
|
|
42
|
-
|
|
43
37
|
/** A map of random settings that alter the behaviour of Gitpod on a per-user basis */
|
|
44
38
|
featureFlags?: UserFeatureSettings;
|
|
45
39
|
|
|
@@ -103,14 +97,29 @@ export interface AdditionalUserData {
|
|
|
103
97
|
emailNotificationSettings?: EmailNotificationSettings;
|
|
104
98
|
featurePreview?: boolean;
|
|
105
99
|
ideSettings?: IDESettings;
|
|
100
|
+
// key is the name of the news, string the iso date when it was seen
|
|
101
|
+
whatsNewSeen?: { [key: string]: string }
|
|
102
|
+
// key is the name of the OAuth client i.e. local app, string the iso date when it was approved
|
|
103
|
+
// TODO(rl): provide a management UX to allow rescinding of approval
|
|
104
|
+
oauthClientsApproved?: { [key: string]: string }
|
|
105
|
+
// to remember GH Orgs the user installed/updated the GH App for
|
|
106
|
+
knownGitHubOrgs?: string[];
|
|
107
|
+
|
|
108
|
+
// Git clone URL pointing to the user's dotfile repo
|
|
109
|
+
dotfileRepo?: string;
|
|
106
110
|
}
|
|
107
111
|
|
|
108
112
|
export interface EmailNotificationSettings {
|
|
109
|
-
|
|
113
|
+
allowsChangelogMail?: boolean;
|
|
114
|
+
allowsDevXMail?: boolean;
|
|
115
|
+
allowsOnboardingMail?: boolean;
|
|
110
116
|
}
|
|
111
117
|
|
|
112
118
|
export type IDESettings = {
|
|
113
119
|
defaultIde?: string
|
|
120
|
+
useDesktopIde?: boolean
|
|
121
|
+
defaultDesktopIde?: string
|
|
122
|
+
useLatestVersion?: boolean
|
|
114
123
|
}
|
|
115
124
|
|
|
116
125
|
export interface UserPlatform {
|
|
@@ -132,14 +141,6 @@ export interface UserPlatform {
|
|
|
132
141
|
}
|
|
133
142
|
|
|
134
143
|
export interface UserFeatureSettings {
|
|
135
|
-
/**
|
|
136
|
-
* This field is used as marker to grant users a free trial for using private repositories,
|
|
137
|
-
* independent of any subscription or Chargebee.
|
|
138
|
-
* - it is set when the user uses their first private repo
|
|
139
|
-
* - whether the trial is expired or not is juged by the UserService
|
|
140
|
-
*/
|
|
141
|
-
privateRepoTrialStartDate?: string;
|
|
142
|
-
|
|
143
144
|
/**
|
|
144
145
|
* Permanent feature flags are added to each and every workspace instance
|
|
145
146
|
* this user starts.
|
|
@@ -151,15 +152,26 @@ export interface UserFeatureSettings {
|
|
|
151
152
|
* The values of this type MUST MATCH enum values in WorkspaceFeatureFlag from ws-manager/client/core_pb.d.ts
|
|
152
153
|
* If they don't we'll break things during workspace startup.
|
|
153
154
|
*/
|
|
154
|
-
export const WorkspaceFeatureFlags = { "
|
|
155
|
+
export const WorkspaceFeatureFlags = { "full_workspace_backup": undefined, "fixed_resources": undefined };
|
|
155
156
|
export type NamedWorkspaceFeatureFlag = keyof (typeof WorkspaceFeatureFlags);
|
|
156
157
|
|
|
157
|
-
export interface
|
|
158
|
-
id?: string;
|
|
158
|
+
export interface EnvVarWithValue {
|
|
159
159
|
name: string;
|
|
160
|
-
repositoryPattern: string;
|
|
161
160
|
value: string;
|
|
162
161
|
}
|
|
162
|
+
|
|
163
|
+
export interface ProjectEnvVarWithValue extends EnvVarWithValue {
|
|
164
|
+
id: string;
|
|
165
|
+
projectId: string;
|
|
166
|
+
censored: boolean;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export type ProjectEnvVar = Omit<ProjectEnvVarWithValue, 'value'>;
|
|
170
|
+
|
|
171
|
+
export interface UserEnvVarValue extends EnvVarWithValue {
|
|
172
|
+
id?: string;
|
|
173
|
+
repositoryPattern: string; // DEPRECATED: Use ProjectEnvVar instead of repositoryPattern - https://github.com/gitpod-com/gitpod/issues/5322
|
|
174
|
+
}
|
|
163
175
|
export interface UserEnvVar extends UserEnvVarValue {
|
|
164
176
|
id: string;
|
|
165
177
|
userId: string;
|
|
@@ -168,10 +180,35 @@ export interface UserEnvVar extends UserEnvVarValue {
|
|
|
168
180
|
|
|
169
181
|
export namespace UserEnvVar {
|
|
170
182
|
|
|
183
|
+
// DEPRECATED: Use ProjectEnvVar instead of repositoryPattern - https://github.com/gitpod-com/gitpod/issues/5322
|
|
171
184
|
export function normalizeRepoPattern(pattern: string) {
|
|
172
185
|
return pattern.toLocaleLowerCase();
|
|
173
186
|
}
|
|
174
187
|
|
|
188
|
+
// DEPRECATED: Use ProjectEnvVar instead of repositoryPattern - https://github.com/gitpod-com/gitpod/issues/5322
|
|
189
|
+
export function score(value: UserEnvVarValue): number {
|
|
190
|
+
// We use a score to enforce precedence:
|
|
191
|
+
// value/value = 0
|
|
192
|
+
// value/* = 1
|
|
193
|
+
// */value = 2
|
|
194
|
+
// */* = 3
|
|
195
|
+
// #/# = 4 (used for env vars passed through the URL)
|
|
196
|
+
// the lower the score, the higher the precedence.
|
|
197
|
+
const [ownerPattern, repoPattern] = splitRepositoryPattern(value.repositoryPattern);
|
|
198
|
+
let score = 0;
|
|
199
|
+
if (repoPattern == "*") {
|
|
200
|
+
score += 1;
|
|
201
|
+
}
|
|
202
|
+
if (ownerPattern == '*') {
|
|
203
|
+
score += 2;
|
|
204
|
+
}
|
|
205
|
+
if (ownerPattern == "#" || repoPattern == "#") {
|
|
206
|
+
score = 4;
|
|
207
|
+
}
|
|
208
|
+
return score;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// DEPRECATED: Use ProjectEnvVar instead of repositoryPattern - https://github.com/gitpod-com/gitpod/issues/5322
|
|
175
212
|
export function filter<T extends UserEnvVarValue>(vars: T[], owner: string, repo: string): T[] {
|
|
176
213
|
let result = vars.filter(e => {
|
|
177
214
|
const [ownerPattern, repoPattern] = splitRepositoryPattern(e.repositoryPattern);
|
|
@@ -207,25 +244,7 @@ export namespace UserEnvVar {
|
|
|
207
244
|
let minscore = 10;
|
|
208
245
|
let bestCandidate: T | undefined;
|
|
209
246
|
for (const e of candidates) {
|
|
210
|
-
|
|
211
|
-
// value/value = 0
|
|
212
|
-
// value/* = 1
|
|
213
|
-
// */value = 2
|
|
214
|
-
// */* = 3
|
|
215
|
-
// #/# = 4 (used for env vars passed through the URL)
|
|
216
|
-
// the lower the score, the higher the precedence.
|
|
217
|
-
const [ownerPattern, repoPattern] = splitRepositoryPattern(e.repositoryPattern);
|
|
218
|
-
let score = 0;
|
|
219
|
-
if (repoPattern == "*") {
|
|
220
|
-
score += 1;
|
|
221
|
-
}
|
|
222
|
-
if (ownerPattern == '*') {
|
|
223
|
-
score += 2;
|
|
224
|
-
}
|
|
225
|
-
if (ownerPattern == "#" || repoPattern == "#") {
|
|
226
|
-
score = 4;
|
|
227
|
-
}
|
|
228
|
-
|
|
247
|
+
const score = UserEnvVar.score(e);
|
|
229
248
|
if (!bestCandidate || score < minscore) {
|
|
230
249
|
minscore = score;
|
|
231
250
|
bestCandidate = e;
|
|
@@ -237,10 +256,11 @@ export namespace UserEnvVar {
|
|
|
237
256
|
return result;
|
|
238
257
|
}
|
|
239
258
|
|
|
240
|
-
|
|
259
|
+
// DEPRECATED: Use ProjectEnvVar instead of repositoryPattern - https://github.com/gitpod-com/gitpod/issues/5322
|
|
260
|
+
export function splitRepositoryPattern(repositoryPattern: string): string[] {
|
|
241
261
|
const patterns = repositoryPattern.split('/');
|
|
242
|
-
const repoPattern = patterns.
|
|
243
|
-
const ownerPattern = patterns
|
|
262
|
+
const repoPattern = patterns.slice(1).join('/')
|
|
263
|
+
const ownerPattern = patterns[0];
|
|
244
264
|
return [ownerPattern, repoPattern];
|
|
245
265
|
}
|
|
246
266
|
}
|
|
@@ -371,11 +391,16 @@ export interface PendingGithubEvent {
|
|
|
371
391
|
export interface Snapshot {
|
|
372
392
|
id: string;
|
|
373
393
|
creationTime: string;
|
|
394
|
+
availableTime?: string;
|
|
374
395
|
originalWorkspaceId: string;
|
|
375
396
|
bucketId: string;
|
|
376
397
|
layoutData?: string;
|
|
398
|
+
state: SnapshotState;
|
|
399
|
+
message?: string;
|
|
377
400
|
}
|
|
378
401
|
|
|
402
|
+
export type SnapshotState = 'pending' | 'available' | 'error';
|
|
403
|
+
|
|
379
404
|
export interface LayoutData {
|
|
380
405
|
workspaceId: string;
|
|
381
406
|
lastUpdatedTime: string;
|
|
@@ -388,6 +413,7 @@ export interface Workspace {
|
|
|
388
413
|
contextURL: string;
|
|
389
414
|
description: string;
|
|
390
415
|
ownerId: string;
|
|
416
|
+
projectId?: string;
|
|
391
417
|
context: WorkspaceContext;
|
|
392
418
|
config: WorkspaceConfig;
|
|
393
419
|
|
|
@@ -507,6 +533,24 @@ export interface UninstallPluginParams {
|
|
|
507
533
|
pluginId: string;
|
|
508
534
|
}
|
|
509
535
|
|
|
536
|
+
export interface GuessGitTokenScopesParams {
|
|
537
|
+
host: string
|
|
538
|
+
repoUrl: string
|
|
539
|
+
gitCommand: string
|
|
540
|
+
currentToken: GitToken
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
export interface GitToken {
|
|
544
|
+
token: string
|
|
545
|
+
user: string
|
|
546
|
+
scopes: string[]
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
export interface GuessedGitTokenScopes {
|
|
550
|
+
message?: string
|
|
551
|
+
scopes?: string[]
|
|
552
|
+
}
|
|
553
|
+
|
|
510
554
|
export type ResolvedPluginKind = 'user' | 'workspace' | 'builtin';
|
|
511
555
|
|
|
512
556
|
export interface ResolvedPlugins {
|
|
@@ -532,16 +576,21 @@ export interface WorkspaceConfig {
|
|
|
532
576
|
gitConfig?: { [config: string]: string };
|
|
533
577
|
github?: GithubAppConfig;
|
|
534
578
|
vscode?: VSCodeConfig;
|
|
535
|
-
|
|
579
|
+
|
|
580
|
+
/** deprecated. Enabled by default **/
|
|
581
|
+
experimentalNetwork?: boolean;
|
|
582
|
+
|
|
536
583
|
/**
|
|
537
584
|
* Where the config object originates from.
|
|
538
|
-
*
|
|
585
|
+
*
|
|
539
586
|
* repo - from the repository
|
|
587
|
+
* project-db - from the "Project" stored in the database
|
|
540
588
|
* definitly-gp - from github.com/gitpod-io/definitely-gp
|
|
541
589
|
* derived - computed based on analyzing the repository
|
|
590
|
+
* additional-content - config comes from additional content, usually provided through the project's configuration
|
|
542
591
|
* default - our static catch-all default config
|
|
543
592
|
*/
|
|
544
|
-
_origin?: 'repo' | 'definitely-gp' | 'derived' | 'default';
|
|
593
|
+
_origin?: 'repo' | 'project-db' | 'definitely-gp' | 'derived' | 'additional-content' | 'default';
|
|
545
594
|
|
|
546
595
|
/**
|
|
547
596
|
* Set of automatically infered feature flags. That's not something the user can set, but
|
|
@@ -558,7 +607,7 @@ export interface GithubAppPrebuildConfig {
|
|
|
558
607
|
branches?: boolean
|
|
559
608
|
pullRequests?: boolean
|
|
560
609
|
pullRequestsFromForks?: boolean
|
|
561
|
-
addCheck?: boolean
|
|
610
|
+
addCheck?: boolean | 'prevent-merge-on-error'
|
|
562
611
|
addBadge?: boolean
|
|
563
612
|
addLabel?: boolean | string
|
|
564
613
|
addComment?: boolean
|
|
@@ -571,16 +620,13 @@ export namespace GithubAppPrebuildConfig {
|
|
|
571
620
|
|
|
572
621
|
export type WorkspaceImageSource = WorkspaceImageSourceDocker | WorkspaceImageSourceReference;
|
|
573
622
|
export interface WorkspaceImageSourceDocker {
|
|
574
|
-
// TODO: clean this up. We should have the commit and an ImageSource in here, not duplicate the whole thing again.
|
|
575
|
-
// We have a ton of those objects in the database, thus cleaning this up means lengthy DB migrations. Yuck.
|
|
576
|
-
dockerFileHash: string
|
|
577
|
-
dockerFileSource: Commit
|
|
578
623
|
dockerFilePath: string
|
|
624
|
+
dockerFileHash: string
|
|
625
|
+
dockerFileSource?: Commit
|
|
579
626
|
}
|
|
580
627
|
export namespace WorkspaceImageSourceDocker {
|
|
581
628
|
export function is(obj: object): obj is WorkspaceImageSourceDocker {
|
|
582
629
|
return 'dockerFileHash' in obj
|
|
583
|
-
&& 'dockerFileSource' in obj
|
|
584
630
|
&& 'dockerFilePath' in obj;
|
|
585
631
|
}
|
|
586
632
|
}
|
|
@@ -609,6 +655,8 @@ export type PrebuiltWorkspaceState
|
|
|
609
655
|
export interface PrebuiltWorkspace {
|
|
610
656
|
id: string;
|
|
611
657
|
cloneURL: string;
|
|
658
|
+
branch?: string;
|
|
659
|
+
projectId?: string;
|
|
612
660
|
commit: string;
|
|
613
661
|
buildWorkspaceId: string;
|
|
614
662
|
creationTime: string;
|
|
@@ -619,7 +667,7 @@ export interface PrebuiltWorkspace {
|
|
|
619
667
|
|
|
620
668
|
export namespace PrebuiltWorkspace {
|
|
621
669
|
export function isDone(pws: PrebuiltWorkspace) {
|
|
622
|
-
return pws.state === "available" || pws.state === "timeout" ||
|
|
670
|
+
return pws.state === "available" || pws.state === "timeout" || pws.state === 'aborted';
|
|
623
671
|
}
|
|
624
672
|
|
|
625
673
|
export function isAvailable(pws: PrebuiltWorkspace) {
|
|
@@ -655,6 +703,8 @@ export interface PortConfig {
|
|
|
655
703
|
port: number;
|
|
656
704
|
onOpen?: PortOnOpen;
|
|
657
705
|
visibility?: PortVisibility;
|
|
706
|
+
description?: string;
|
|
707
|
+
name?: string;
|
|
658
708
|
}
|
|
659
709
|
export namespace PortConfig {
|
|
660
710
|
export function is(config: any): config is PortConfig {
|
|
@@ -678,7 +728,7 @@ export interface TaskConfig {
|
|
|
678
728
|
init?: string;
|
|
679
729
|
prebuild?: string;
|
|
680
730
|
command?: string;
|
|
681
|
-
env?: { [env: string]:
|
|
731
|
+
env?: { [env: string]: any };
|
|
682
732
|
openIn?: 'bottom' | 'main' | 'left' | 'right';
|
|
683
733
|
openMode?: 'split-top' | 'split-left' | 'split-right' | 'split-bottom' | 'tab-before' | 'tab-after';
|
|
684
734
|
}
|
|
@@ -742,8 +792,10 @@ export namespace ExternalImageConfigFile {
|
|
|
742
792
|
|
|
743
793
|
export interface WorkspaceContext {
|
|
744
794
|
title: string;
|
|
795
|
+
/** This contains the URL portion of the contextURL (which might contain other modifiers as well). It's optional because it's not set for older workspaces. */
|
|
745
796
|
normalizedContextURL?: string;
|
|
746
797
|
forceCreateNewWorkspace?: boolean;
|
|
798
|
+
forceImageBuild?: boolean;
|
|
747
799
|
}
|
|
748
800
|
|
|
749
801
|
export namespace WorkspaceContext {
|
|
@@ -777,6 +829,29 @@ export namespace WithPrebuild {
|
|
|
777
829
|
}
|
|
778
830
|
}
|
|
779
831
|
|
|
832
|
+
/**
|
|
833
|
+
* WithDefaultConfig contexts disable the download of the gitpod.yml from the repository
|
|
834
|
+
* and fall back to the built-in configuration.
|
|
835
|
+
*/
|
|
836
|
+
export interface WithDefaultConfig {
|
|
837
|
+
withDefaultConfig: true;
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
export namespace WithDefaultConfig {
|
|
841
|
+
export function is(context: any): context is WithDefaultConfig {
|
|
842
|
+
return context
|
|
843
|
+
&& 'withDefaultConfig' in context
|
|
844
|
+
&& context.withDefaultConfig;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
export function mark(ctx: WorkspaceContext): WorkspaceContext & WithDefaultConfig {
|
|
848
|
+
return {
|
|
849
|
+
...ctx,
|
|
850
|
+
withDefaultConfig: true
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
|
|
780
855
|
export interface SnapshotContext extends WorkspaceContext, WithSnapshot {
|
|
781
856
|
snapshotId: string;
|
|
782
857
|
}
|
|
@@ -791,6 +866,9 @@ export namespace SnapshotContext {
|
|
|
791
866
|
|
|
792
867
|
export interface StartPrebuildContext extends WorkspaceContext {
|
|
793
868
|
actual: WorkspaceContext;
|
|
869
|
+
commitHistory?: string[];
|
|
870
|
+
project?: Project;
|
|
871
|
+
branch?: string;
|
|
794
872
|
}
|
|
795
873
|
|
|
796
874
|
export namespace StartPrebuildContext {
|
|
@@ -814,8 +892,20 @@ export namespace PrebuiltWorkspaceContext {
|
|
|
814
892
|
}
|
|
815
893
|
}
|
|
816
894
|
|
|
895
|
+
export interface WithReferrerContext extends WorkspaceContext {
|
|
896
|
+
referrer: string
|
|
897
|
+
referrerIde?: string
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
export namespace WithReferrerContext {
|
|
901
|
+
export function is(context: any): context is WithReferrerContext {
|
|
902
|
+
return context
|
|
903
|
+
&& 'referrer' in context;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
|
|
817
907
|
export interface WithEnvvarsContext extends WorkspaceContext {
|
|
818
|
-
envvars:
|
|
908
|
+
envvars: EnvVarWithValue[];
|
|
819
909
|
}
|
|
820
910
|
|
|
821
911
|
export namespace WithEnvvarsContext {
|
|
@@ -860,6 +950,25 @@ export interface Commit {
|
|
|
860
950
|
refType?: RefType
|
|
861
951
|
}
|
|
862
952
|
|
|
953
|
+
export interface AdditionalContentContext extends WorkspaceContext {
|
|
954
|
+
|
|
955
|
+
/**
|
|
956
|
+
* utf-8 encoded contents that will be copied on top of the workspace's filesystem
|
|
957
|
+
*/
|
|
958
|
+
additionalFiles: {[filePath: string]: string};
|
|
959
|
+
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
export namespace AdditionalContentContext {
|
|
963
|
+
export function is(ctx: any): ctx is AdditionalContentContext {
|
|
964
|
+
return 'additionalFiles' in ctx;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
export function hasDockerConfig(ctx: any, config: WorkspaceConfig): boolean {
|
|
968
|
+
return is(ctx) && ImageConfigFile.is(config.image) && !!ctx.additionalFiles[config.image.file];
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
|
|
863
972
|
export interface CommitContext extends WorkspaceContext, Commit {
|
|
864
973
|
/** @deprecated Moved to .repository.cloneUrl, left here for backwards-compatibility for old workspace contextes in the DB */
|
|
865
974
|
cloneUrl?: string
|
|
@@ -935,6 +1044,19 @@ export interface Repository {
|
|
|
935
1044
|
parent: Repository
|
|
936
1045
|
}
|
|
937
1046
|
}
|
|
1047
|
+
export interface Branch {
|
|
1048
|
+
name: string;
|
|
1049
|
+
commit: CommitInfo;
|
|
1050
|
+
htmlUrl: string;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
export interface CommitInfo {
|
|
1054
|
+
author: string;
|
|
1055
|
+
sha: string;
|
|
1056
|
+
commitMessage: string;
|
|
1057
|
+
authorAvatarUrl?: string;
|
|
1058
|
+
authorDate?: string;
|
|
1059
|
+
}
|
|
938
1060
|
|
|
939
1061
|
export namespace Repository {
|
|
940
1062
|
export function fullRepoName(repo: Repository): string {
|
|
@@ -962,6 +1084,12 @@ export interface WorkspaceInfo {
|
|
|
962
1084
|
latestInstance?: WorkspaceInstance
|
|
963
1085
|
}
|
|
964
1086
|
|
|
1087
|
+
export namespace WorkspaceInfo {
|
|
1088
|
+
export function lastActiveISODate(info: WorkspaceInfo): string {
|
|
1089
|
+
return info.latestInstance?.creationTime || info.workspace.creationTime;
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
|
|
965
1093
|
export type RunningWorkspaceInfo = WorkspaceInfo & { latestInstance: WorkspaceInstance };
|
|
966
1094
|
|
|
967
1095
|
export interface WorkspaceCreationResult {
|
|
@@ -971,6 +1099,7 @@ export interface WorkspaceCreationResult {
|
|
|
971
1099
|
runningWorkspacePrebuild?: {
|
|
972
1100
|
prebuildID: string
|
|
973
1101
|
workspaceID: string
|
|
1102
|
+
instanceID: string
|
|
974
1103
|
starting: RunningWorkspacePrebuildStarting
|
|
975
1104
|
sameCluster: boolean
|
|
976
1105
|
}
|
|
@@ -1042,6 +1171,8 @@ export interface AuthProviderEntry {
|
|
|
1042
1171
|
readonly status: AuthProviderEntry.Status;
|
|
1043
1172
|
|
|
1044
1173
|
readonly oauth: OAuth2Config;
|
|
1174
|
+
/** A random string that is to change whenever oauth changes (enforced on DB level) */
|
|
1175
|
+
readonly oauthRevision?: string;
|
|
1045
1176
|
}
|
|
1046
1177
|
|
|
1047
1178
|
export interface OAuth2Config {
|
|
@@ -1061,40 +1192,16 @@ export interface OAuth2Config {
|
|
|
1061
1192
|
export namespace AuthProviderEntry {
|
|
1062
1193
|
export type Type = "GitHub" | "GitLab" | string;
|
|
1063
1194
|
export type Status = "pending" | "verified";
|
|
1064
|
-
export type NewEntry = Pick<AuthProviderEntry, "ownerId" | "host" | "type"
|
|
1195
|
+
export type NewEntry = Pick<AuthProviderEntry, "ownerId" | "host" | "type"> & { clientId?: string, clientSecret?: string };
|
|
1065
1196
|
export type UpdateEntry = Pick<AuthProviderEntry, "id" | "ownerId"> & Pick<OAuth2Config, "clientId" | "clientSecret">;
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
readonly showProductivityTips: boolean;
|
|
1075
|
-
readonly redirectUrlIfNotAuthenticated?: string;
|
|
1076
|
-
readonly redirectUrlAfterLogout?: string;
|
|
1077
|
-
readonly homepage: string;
|
|
1078
|
-
readonly ide?: {
|
|
1079
|
-
readonly logo: string;
|
|
1080
|
-
readonly showReleaseNotes: boolean;
|
|
1081
|
-
readonly helpMenu: Branding.Link[];
|
|
1082
|
-
}
|
|
1083
|
-
readonly links: {
|
|
1084
|
-
readonly header: Branding.Link[];
|
|
1085
|
-
readonly footer: Branding.Link[];
|
|
1086
|
-
readonly social: Branding.SocialLink[];
|
|
1087
|
-
readonly legal: Branding.Link[];
|
|
1088
|
-
}
|
|
1089
|
-
}
|
|
1090
|
-
export namespace Branding {
|
|
1091
|
-
export interface Link {
|
|
1092
|
-
readonly name: string;
|
|
1093
|
-
readonly url: string;
|
|
1094
|
-
}
|
|
1095
|
-
export interface SocialLink {
|
|
1096
|
-
readonly type: string;
|
|
1097
|
-
readonly url: string;
|
|
1197
|
+
export function redact(entry: AuthProviderEntry): AuthProviderEntry {
|
|
1198
|
+
return {
|
|
1199
|
+
...entry,
|
|
1200
|
+
oauth: {
|
|
1201
|
+
...entry.oauth,
|
|
1202
|
+
clientSecret: "redacted"
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1098
1205
|
}
|
|
1099
1206
|
}
|
|
1100
1207
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
|
|
3
|
+
* Licensed under the GNU Affero General Public License (AGPL).
|
|
4
|
+
* See License-AGPL.txt in the project root for license information.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { suite, test } from "mocha-typescript"
|
|
8
|
+
import * as chai from "chai"
|
|
9
|
+
import { SnapshotUrl } from ".";
|
|
10
|
+
|
|
11
|
+
const expect = chai.expect
|
|
12
|
+
|
|
13
|
+
@suite class TestSnapshotUrlParser {
|
|
14
|
+
|
|
15
|
+
@test public testPositive() {
|
|
16
|
+
const actual = SnapshotUrl.parse("workspaces/c362d434-6faa-4ce0-9ad4-91b4a87c4abe/3f0556f7-4afa-11e9-98d5-52f8983b9279.tar@gitpod-prodcopy-user-e1e28f18-0354-4a5d-b6b4-8879a2ff73fd");
|
|
17
|
+
|
|
18
|
+
expect(actual).to.deep.equal(<SnapshotUrl>{
|
|
19
|
+
bucketId: "gitpod-prodcopy-user-e1e28f18-0354-4a5d-b6b4-8879a2ff73fd",
|
|
20
|
+
filename: "3f0556f7-4afa-11e9-98d5-52f8983b9279.tar",
|
|
21
|
+
fullPath: "workspaces/c362d434-6faa-4ce0-9ad4-91b4a87c4abe/3f0556f7-4afa-11e9-98d5-52f8983b9279.tar",
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
module.exports = new TestSnapshotUrlParser() // Only to circumvent no usage warning :-/
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2021 Gitpod GmbH. All rights reserved.
|
|
3
|
+
* Licensed under the GNU Affero General Public License (AGPL).
|
|
4
|
+
* See License-AGPL.txt in the project root for license information.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export interface SnapshotUrl {
|
|
8
|
+
bucketId: string;
|
|
9
|
+
fullPath: string;
|
|
10
|
+
filename: string;
|
|
11
|
+
}
|
|
12
|
+
export namespace SnapshotUrl {
|
|
13
|
+
export function parse(url: string): SnapshotUrl {
|
|
14
|
+
const parts = url.split("@");
|
|
15
|
+
if (parts.length !== 2) {
|
|
16
|
+
throw new Error(`cannot parse snapshot URL: ${url}`);
|
|
17
|
+
}
|
|
18
|
+
const [fullPath, bucketId] = parts;
|
|
19
|
+
|
|
20
|
+
const pathParts = fullPath.split("/");
|
|
21
|
+
if (pathParts.length < 1) {
|
|
22
|
+
throw new Error(`cannot parse snapshot URL: ${url}`);
|
|
23
|
+
}
|
|
24
|
+
const filename = pathParts[pathParts.length - 1];
|
|
25
|
+
return { bucketId, fullPath, filename };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2021 Gitpod GmbH. All rights reserved.
|
|
3
|
+
* Licensed under the GNU Affero General Public License (AGPL).
|
|
4
|
+
* See License-AGPL.txt in the project root for license information.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
8
|
+
import { Subscription } from "./accounting-protocol";
|
|
9
|
+
|
|
10
|
+
export interface TeamSubscription {
|
|
11
|
+
id: string;
|
|
12
|
+
userId: string;
|
|
13
|
+
planId: string;
|
|
14
|
+
startDate: string;
|
|
15
|
+
endDate?: string;
|
|
16
|
+
quantity: number;
|
|
17
|
+
/** The Chargebee subscription id */
|
|
18
|
+
paymentReference: string;
|
|
19
|
+
cancellationDate?: string;
|
|
20
|
+
deleted?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export namespace TeamSubscription {
|
|
24
|
+
export const create = (ts: Omit<TeamSubscription, 'id'>): TeamSubscription => {
|
|
25
|
+
const withId = ts as TeamSubscription;
|
|
26
|
+
withId.id = uuidv4();
|
|
27
|
+
return withId;
|
|
28
|
+
}
|
|
29
|
+
export const isActive = (ts: TeamSubscription, date: string): boolean => {
|
|
30
|
+
return ts.startDate <= date && (ts.endDate === undefined || date < ts.endDate);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A slot represents one unit of a TeamSubscription that gets assigned to one user at a time
|
|
36
|
+
*/
|
|
37
|
+
export interface TeamSubscriptionSlot {
|
|
38
|
+
id: string;
|
|
39
|
+
teamSubscriptionId: string;
|
|
40
|
+
assigneeId?: string;
|
|
41
|
+
assigneeIdentifier?: AssigneeIdentifier;
|
|
42
|
+
subscriptionId?: string;
|
|
43
|
+
cancellationDate?: string;
|
|
44
|
+
}
|
|
45
|
+
export type TeamSubscriptionSlotDeactivated = TeamSubscriptionSlot & { assigneeId: string, assigneeIdentifier: AssigneeIdentifier };
|
|
46
|
+
export type TeamSubscriptionSlotAssigned = TeamSubscriptionSlot & TeamSubscriptionSlotDeactivated & { subscriptionId: string };
|
|
47
|
+
|
|
48
|
+
export type TeamSubscriptionSlotState = 'unassigned' | 'assigned' | 'deactivated' | 'cancelled';
|
|
49
|
+
|
|
50
|
+
export namespace TeamSubscriptionSlot {
|
|
51
|
+
export const create = (ts: Omit<TeamSubscriptionSlot, 'id'>): TeamSubscriptionSlot => {
|
|
52
|
+
const withId = ts as TeamSubscriptionSlot;
|
|
53
|
+
withId.id = uuidv4();
|
|
54
|
+
return withId;
|
|
55
|
+
}
|
|
56
|
+
export const assign = (slot: TeamSubscriptionSlot, assigneeId: string, subscriptionId: string, assigneeIdentifier: AssigneeIdentifier) => {
|
|
57
|
+
slot.assigneeId = assigneeId;
|
|
58
|
+
slot.subscriptionId = subscriptionId;
|
|
59
|
+
slot.assigneeIdentifier = assigneeIdentifier;
|
|
60
|
+
}
|
|
61
|
+
export const deactivate = (slot: TeamSubscriptionSlot, cancellationDate: string) => {
|
|
62
|
+
slot.subscriptionId = undefined;
|
|
63
|
+
slot.cancellationDate = cancellationDate;
|
|
64
|
+
}
|
|
65
|
+
export const reactivate = (slot: TeamSubscriptionSlot, subscriptionId?: string) => {
|
|
66
|
+
slot.subscriptionId = subscriptionId;
|
|
67
|
+
slot.cancellationDate = undefined;
|
|
68
|
+
}
|
|
69
|
+
export const status = (slot: TeamSubscriptionSlot, now: string): TeamSubscriptionSlotState => {
|
|
70
|
+
if (slot.cancellationDate) {
|
|
71
|
+
if (slot.cancellationDate < now) {
|
|
72
|
+
return 'cancelled';
|
|
73
|
+
} else {
|
|
74
|
+
return 'deactivated';
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
if (slot.subscriptionId) {
|
|
78
|
+
return 'assigned';
|
|
79
|
+
} else {
|
|
80
|
+
return 'unassigned';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
}
|
|
85
|
+
export const isActive = (slot: TeamSubscriptionSlot): boolean => {
|
|
86
|
+
return !slot.cancellationDate;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The mapping between a TeamSubscription and a resulting Subscription, resolved
|
|
92
|
+
*/
|
|
93
|
+
export interface TeamSubscriptionSlotResolved {
|
|
94
|
+
id: string;
|
|
95
|
+
teamSubscription: TeamSubscription;
|
|
96
|
+
state: TeamSubscriptionSlotState;
|
|
97
|
+
assigneeId?: string;
|
|
98
|
+
assigneeIdentifier?: AssigneeIdentifier;
|
|
99
|
+
subscription?: Subscription;
|
|
100
|
+
cancellationDate?: string;
|
|
101
|
+
hoursLeft?: number;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Contains the data structure that the assigner used to identify the assignee.
|
|
106
|
+
*/
|
|
107
|
+
export type AssigneeIdentifier = AssigneeIdentityIdentifier;
|
|
108
|
+
export interface AssigneeIdentityIdentifier {
|
|
109
|
+
identity: {
|
|
110
|
+
authHost: string,
|
|
111
|
+
authName: string
|
|
112
|
+
}
|
|
113
|
+
}
|