@gitpod/gitpod-protocol 0.1.5-test.6 → 0.1.5-tweak-workspaceconfig-origin-docs-fork.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 +28 -18
- package/data/gitpod-schema.json +17 -17
- 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 +22 -5
- package/lib/admin-protocol.d.ts.map +1 -1
- package/lib/admin-protocol.js +16 -1
- 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 +18 -0
- package/lib/context-url.d.ts.map +1 -0
- package/lib/context-url.js +49 -0
- package/lib/context-url.js.map +1 -0
- package/lib/context-url.spec.d.ts +12 -0
- package/lib/context-url.spec.d.ts.map +1 -0
- package/lib/context-url.spec.js +73 -0
- package/lib/context-url.spec.js.map +1 -0
- package/lib/email-protocol.d.ts +2 -2
- package/lib/email-protocol.d.ts.map +1 -1
- package/lib/email-protocol.js +6 -5
- package/lib/email-protocol.js.map +1 -1
- package/lib/encryption/container-module.d.ts +1 -1
- package/lib/encryption/container-module.js +7 -5
- package/lib/encryption/container-module.js.map +1 -1
- package/lib/encryption/encryption-engine.d.ts +1 -1
- package/lib/encryption/encryption-engine.js +21 -21
- package/lib/encryption/encryption-engine.js.map +1 -1
- package/lib/encryption/encryption-engine.spec.d.ts +2 -2
- package/lib/encryption/encryption-engine.spec.d.ts.map +1 -1
- package/lib/encryption/encryption-engine.spec.js +31 -37
- package/lib/encryption/encryption-engine.spec.js.map +1 -1
- package/lib/encryption/encryption-service.d.ts +1 -1
- package/lib/encryption/encryption-service.js +31 -44
- package/lib/encryption/encryption-service.js.map +1 -1
- package/lib/encryption/key-provider.d.ts +2 -2
- package/lib/encryption/key-provider.d.ts.map +1 -1
- package/lib/encryption/key-provider.js +27 -31
- package/lib/encryption/key-provider.js.map +1 -1
- package/lib/env.d.ts +2 -3
- package/lib/env.d.ts.map +1 -1
- package/lib/env.js +21 -21
- package/lib/env.js.map +1 -1
- package/lib/gitpod-file-parser.d.ts +1 -1
- package/lib/gitpod-file-parser.js +27 -42
- package/lib/gitpod-file-parser.js.map +1 -1
- package/lib/gitpod-file-parser.spec.d.ts +1 -1
- package/lib/gitpod-file-parser.spec.js +117 -117
- package/lib/gitpod-file-parser.spec.js.map +1 -1
- package/lib/gitpod-service.d.ts +186 -34
- package/lib/gitpod-service.d.ts.map +1 -1
- package/lib/gitpod-service.js +239 -116
- package/lib/gitpod-service.js.map +1 -1
- package/lib/headless-workspace-log.d.ts +9 -12
- package/lib/headless-workspace-log.d.ts.map +1 -1
- package/lib/headless-workspace-log.js +5 -7
- package/lib/headless-workspace-log.js.map +1 -1
- package/lib/ide-frontend-service.d.ts +26 -0
- package/lib/ide-frontend-service.d.ts.map +1 -0
- package/lib/ide-frontend-service.js +8 -0
- package/lib/ide-frontend-service.js.map +1 -0
- package/lib/ide-protocol.d.ts +81 -0
- package/lib/ide-protocol.d.ts.map +1 -0
- package/lib/{util/without.js → ide-protocol.js} +2 -2
- package/lib/ide-protocol.js.map +1 -0
- package/lib/index.d.ts +5 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +25 -12
- package/lib/index.js.map +1 -1
- package/lib/license-protocol.d.ts +1 -1
- package/lib/license-protocol.js +2 -1
- package/lib/license-protocol.js.map +1 -1
- package/lib/messaging/browser/connection.d.ts +6 -4
- package/lib/messaging/browser/connection.d.ts.map +1 -1
- package/lib/messaging/browser/connection.js +188 -48
- package/lib/messaging/browser/connection.js.map +1 -1
- package/lib/messaging/browser/window-connection.d.ts +26 -0
- package/lib/messaging/browser/window-connection.d.ts.map +1 -0
- package/lib/messaging/browser/window-connection.js +68 -0
- package/lib/messaging/browser/window-connection.js.map +1 -0
- 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/connection-error-handler.js +12 -23
- package/lib/messaging/connection-error-handler.js.map +1 -1
- package/lib/messaging/error.d.ts +6 -2
- package/lib/messaging/error.d.ts.map +1 -1
- package/lib/messaging/error.js +13 -4
- 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/handler.js +1 -0
- package/lib/messaging/handler.js.map +1 -1
- package/lib/messaging/node/connection.js +23 -22
- 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 +75 -169
- package/lib/messaging/proxy-factory.js.map +1 -1
- 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 +14 -12
- package/lib/permission.d.ts.map +1 -1
- package/lib/permission.js +21 -19
- 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 +123 -30
- package/lib/protocol.d.ts.map +1 -1
- package/lib/protocol.js +121 -117
- 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} +3 -4
- 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 +103 -0
- package/lib/teams-projects-protocol.d.ts.map +1 -0
- package/lib/teams-projects-protocol.js +23 -0
- package/lib/teams-projects-protocol.js.map +1 -0
- package/lib/theia-plugins.d.ts +1 -1
- package/lib/theia-plugins.js +1 -1
- package/lib/typings/globals.d.ts +12 -0
- package/lib/typings/globals.d.ts.map +1 -0
- package/lib/typings/globals.js +7 -0
- package/lib/typings/globals.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.d.ts +1 -1
- package/lib/util/async-iterator.js +57 -134
- package/lib/util/async-iterator.js.map +1 -1
- package/lib/util/cancelable.d.ts +1 -1
- package/lib/util/cancelable.js +19 -60
- package/lib/util/cancelable.js.map +1 -1
- package/lib/util/date-time.d.ts +1 -1
- package/lib/util/date-time.js +10 -9
- package/lib/util/date-time.js.map +1 -1
- package/lib/util/deep-partial.d.ts +1 -1
- package/lib/util/deep-partial.js +1 -1
- package/lib/util/deferred.d.ts +1 -1
- package/lib/util/deferred.js +12 -13
- package/lib/util/deferred.js.map +1 -1
- package/lib/util/disposable.d.ts +2 -2
- package/lib/util/disposable.d.ts.map +1 -1
- package/lib/util/disposable.js +27 -39
- package/lib/util/disposable.js.map +1 -1
- package/lib/util/event.d.ts +1 -1
- package/lib/util/event.d.ts.map +1 -1
- package/lib/util/event.js +59 -74
- package/lib/util/event.js.map +1 -1
- package/lib/util/garbage-collected-cache.d.ts +1 -1
- package/lib/util/garbage-collected-cache.js +24 -47
- 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 +470 -0
- package/lib/util/generate-workspace-id.js.map +1 -0
- package/lib/util/generate-workspace-id.spec.d.ts +7 -0
- package/lib/util/generate-workspace-id.spec.d.ts.map +1 -0
- package/lib/util/generate-workspace-id.spec.js +63 -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 +8 -3
- package/lib/util/gitpod-host-url.d.ts.map +1 -1
- package/lib/util/gitpod-host-url.js +106 -76
- package/lib/util/gitpod-host-url.js.map +1 -1
- package/lib/util/gitpod-host-url.spec.d.ts +16 -0
- package/lib/util/gitpod-host-url.spec.d.ts.map +1 -0
- package/lib/util/gitpod-host-url.spec.js +124 -0
- package/lib/util/gitpod-host-url.spec.js.map +1 -0
- 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/logging.d.ts +57 -34
- package/lib/util/logging.d.ts.map +1 -1
- package/lib/util/logging.js +119 -110
- package/lib/util/logging.js.map +1 -1
- package/lib/util/make-link.d.ts +1 -1
- package/lib/util/make-link.js +4 -3
- package/lib/util/make-link.js.map +1 -1
- package/lib/util/parse-workspace-id.d.ts +14 -4
- package/lib/util/parse-workspace-id.d.ts.map +1 -1
- package/lib/util/parse-workspace-id.js +39 -8
- package/lib/util/parse-workspace-id.js.map +1 -1
- package/lib/util/parse-workspace-id.spec.d.ts +9 -1
- package/lib/util/parse-workspace-id.spec.d.ts.map +1 -1
- package/lib/util/parse-workspace-id.spec.js +129 -48
- package/lib/util/parse-workspace-id.spec.js.map +1 -1
- package/lib/util/queue.d.ts +1 -1
- package/lib/util/queue.js +18 -56
- package/lib/util/queue.js.map +1 -1
- package/lib/util/queue.spec.d.ts +1 -1
- package/lib/util/queue.spec.js +145 -287
- package/lib/util/queue.spec.js.map +1 -1
- package/lib/util/repeater.d.ts +1 -1
- package/lib/util/repeater.js +37 -89
- package/lib/util/repeater.js.map +1 -1
- package/lib/util/safe-promise.d.ts +1 -1
- package/lib/util/safe-promise.js +11 -13
- package/lib/util/safe-promise.js.map +1 -1
- package/lib/util/semaphore.d.ts +1 -1
- package/lib/util/semaphore.js +17 -47
- package/lib/util/semaphore.js.map +1 -1
- package/lib/util/skip-if.d.ts +1 -1
- package/lib/util/skip-if.js +8 -7
- package/lib/util/skip-if.js.map +1 -1
- package/lib/util/timeutil.d.ts +1 -1
- package/lib/util/timeutil.d.ts.map +1 -1
- package/lib/util/timeutil.js +30 -17
- package/lib/util/timeutil.js.map +1 -1
- package/lib/util/timeutil.spec.d.ts +1 -1
- package/lib/util/timeutil.spec.js +23 -25
- package/lib/util/timeutil.spec.js.map +1 -1
- package/lib/util/tracing.d.ts +15 -2
- package/lib/util/tracing.d.ts.map +1 -1
- package/lib/util/tracing.js +86 -51
- package/lib/util/tracing.js.map +1 -1
- package/lib/util/workspace-port-authentication.d.ts +1 -1
- package/lib/util/workspace-port-authentication.d.ts.map +1 -1
- package/lib/util/workspace-port-authentication.js +5 -3
- package/lib/util/workspace-port-authentication.js.map +1 -1
- package/lib/workspace-cluster.d.ts +74 -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 +10 -4
- package/lib/workspace-instance.d.ts.map +1 -1
- package/lib/workspace-instance.js +1 -1
- package/lib/wsready.d.ts +1 -1
- package/lib/wsready.js +3 -2
- package/lib/wsready.js.map +1 -1
- package/package.json +32 -16
- package/pkg-yarn.lock +18 -9
- package/src/accounting-protocol.ts +229 -0
- package/src/admin-protocol.ts +41 -6
- package/src/analytics.ts +54 -0
- package/src/auth.ts +27 -0
- package/src/context-url.spec.ts +39 -0
- package/src/context-url.ts +51 -0
- package/src/email-protocol.ts +3 -4
- package/src/encryption/container-module.ts +1 -1
- package/src/encryption/encryption-engine.spec.ts +1 -1
- package/src/encryption/encryption-engine.ts +1 -1
- package/src/encryption/encryption-service.ts +1 -1
- package/src/encryption/key-provider.ts +1 -1
- package/src/env.ts +11 -11
- package/src/gitpod-file-parser.spec.ts +1 -1
- package/src/gitpod-file-parser.ts +1 -1
- package/src/gitpod-service.ts +386 -52
- package/src/headless-workspace-log.ts +8 -12
- package/src/ide-frontend-service.ts +28 -0
- package/src/ide-protocol.ts +92 -0
- package/src/index.ts +6 -2
- package/src/license-protocol.ts +1 -1
- package/src/messaging/browser/connection.ts +201 -23
- package/src/messaging/browser/window-connection.ts +72 -0
- package/src/messaging/client-call-metrics.ts +97 -0
- package/src/messaging/error.ts +16 -4
- package/src/messaging/handler.ts +12 -0
- package/src/messaging/node/connection.ts +2 -2
- package/src/messaging/proxy-factory.ts +16 -14
- package/src/payment-protocol.ts +20 -0
- package/src/permission.ts +9 -8
- package/src/plans.ts +632 -0
- package/src/protocol.ts +204 -61
- 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 +132 -0
- package/src/theia-plugins.ts +1 -1
- package/src/typings/globals.ts +12 -0
- package/src/util/analytics.ts +87 -0
- package/src/util/async-iterator.ts +1 -1
- package/src/util/cancelable.ts +1 -1
- package/src/util/date-time.ts +1 -1
- package/src/util/deep-partial.ts +1 -1
- package/src/util/deferred.ts +2 -2
- package/src/util/garbage-collected-cache.ts +3 -3
- package/src/util/generate-workspace-id.spec.ts +31 -0
- package/src/util/generate-workspace-id.ts +457 -0
- package/src/util/gitpod-cookie.ts +39 -0
- package/src/util/gitpod-host-url.spec.ts +49 -0
- package/src/util/gitpod-host-url.ts +58 -14
- package/src/util/grpc.ts +15 -0
- package/src/util/jaeger-client.d.ts +1 -1
- package/src/util/logging.ts +111 -39
- package/src/util/make-link.ts +1 -1
- package/src/util/parse-workspace-id.spec.ts +46 -5
- package/src/util/parse-workspace-id.ts +39 -8
- package/src/util/queue.spec.ts +2 -2
- package/src/util/queue.ts +1 -1
- package/src/util/repeater.ts +1 -1
- package/src/util/safe-promise.ts +1 -1
- package/src/util/semaphore.ts +3 -3
- package/src/util/skip-if.ts +2 -2
- package/src/util/timeutil.spec.ts +1 -1
- package/src/util/timeutil.ts +5 -5
- package/src/util/tracing.ts +66 -4
- package/src/util/workspace-port-authentication.ts +1 -1
- package/src/workspace-cluster.ts +96 -0
- package/src/workspace-instance.ts +38 -16
- package/src/wsready.ts +2 -2
- package/lib/util/without.d.ts +0 -7
- package/lib/util/without.d.ts.map +0 -1
- package/lib/util/without.js.map +0 -1
|
@@ -0,0 +1,229 @@
|
|
|
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 { User } from './protocol';
|
|
9
|
+
import { oneMonthLater } from './util/timeutil';
|
|
10
|
+
|
|
11
|
+
/*
|
|
12
|
+
* Subscription and acocunting data
|
|
13
|
+
*/
|
|
14
|
+
export interface AccountEntry {
|
|
15
|
+
uid: string;
|
|
16
|
+
|
|
17
|
+
userId: string;
|
|
18
|
+
|
|
19
|
+
/** [hours] */
|
|
20
|
+
amount: number;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* credit: start of validity,
|
|
24
|
+
* session: end of (split-) session
|
|
25
|
+
*/
|
|
26
|
+
date: string;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* debits (session, expiry, loss): relation to credit
|
|
30
|
+
*/
|
|
31
|
+
creditId?: string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* credit: end of validity
|
|
35
|
+
*/
|
|
36
|
+
expiryDate?: string; // exclusive
|
|
37
|
+
|
|
38
|
+
kind: AccountEntryKind;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* credit: amount - accounted debits
|
|
42
|
+
* [hours]
|
|
43
|
+
*/
|
|
44
|
+
remainingAmount?: number;
|
|
45
|
+
|
|
46
|
+
description?: object;
|
|
47
|
+
}
|
|
48
|
+
export namespace AccountEntry {
|
|
49
|
+
export function create<T extends AccountEntry>(entry: Omit<T, 'uid'>): T {
|
|
50
|
+
const result = entry as T;
|
|
51
|
+
result.uid = uuidv4();
|
|
52
|
+
return result;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type DebitAccountEntryKind = 'session' | 'expiry' | 'loss';
|
|
57
|
+
export type AccountEntryKind = 'credit' | DebitAccountEntryKind | 'carry' | 'open';
|
|
58
|
+
|
|
59
|
+
export interface Credit extends AccountEntry {
|
|
60
|
+
kind: 'credit';
|
|
61
|
+
expiryDate: string;
|
|
62
|
+
}
|
|
63
|
+
export type Debit = LossDebit | ExpiryDebit | SessionDebit;
|
|
64
|
+
export interface LossDebit extends AccountEntry {
|
|
65
|
+
kind: 'loss';
|
|
66
|
+
}
|
|
67
|
+
export interface ExpiryDebit extends AccountEntry {
|
|
68
|
+
kind: 'expiry';
|
|
69
|
+
creditId: undefined;
|
|
70
|
+
}
|
|
71
|
+
export interface SessionDebit extends AccountEntry {
|
|
72
|
+
kind: DebitAccountEntryKind;
|
|
73
|
+
creditId: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type AccountEntryDescription = SessionDescription | CreditDescription;
|
|
77
|
+
export interface CreditDescription {
|
|
78
|
+
subscriptionId: string;
|
|
79
|
+
planId: string;
|
|
80
|
+
}
|
|
81
|
+
export namespace CreditDescription {
|
|
82
|
+
export function is(obj: any): obj is CreditDescription {
|
|
83
|
+
return !!obj
|
|
84
|
+
&& obj.hasOwnProperty('subscriptionId')
|
|
85
|
+
&& obj.hasOwnProperty('planId');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export interface SessionDescription {
|
|
89
|
+
contextTitle: string;
|
|
90
|
+
contextUrl: string;
|
|
91
|
+
workspaceId: string;
|
|
92
|
+
workspaceInstanceId: string;
|
|
93
|
+
}
|
|
94
|
+
export namespace SessionDescription {
|
|
95
|
+
export function is(obj: any): obj is SessionDescription {
|
|
96
|
+
return !!obj
|
|
97
|
+
&& obj.hasOwnProperty('contextTitle')
|
|
98
|
+
&& obj.hasOwnProperty('contextUrl')
|
|
99
|
+
&& obj.hasOwnProperty('workspaceId')
|
|
100
|
+
&& obj.hasOwnProperty('workspaceInstanceId')
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* - The earliest subscription may start with User.creationDate
|
|
106
|
+
* - There may be multiple Gitpod subscriptions for a user at any given time
|
|
107
|
+
* - The dates form an interval of the form: [startDate, endDate)
|
|
108
|
+
* - Subscriptions that directly map to a Chargebee plan have their paymentReference set and MAY carry additional paymentData (UserPaidSubscription)
|
|
109
|
+
* - Subscriptions that are assigned to a user through a Team Subscription carry a teamSubscriptionSlotId (AssignedTeamSubscription)
|
|
110
|
+
*/
|
|
111
|
+
export interface Subscription {
|
|
112
|
+
uid: string;
|
|
113
|
+
userId: string;
|
|
114
|
+
startDate: string; // inclusive
|
|
115
|
+
/** When the subscription will end (must be >= cancellationDate!) */
|
|
116
|
+
endDate?: string; // exclusive
|
|
117
|
+
/** When the subscription was cancelled */
|
|
118
|
+
cancellationDate?: string; // exclusive
|
|
119
|
+
/** Number of granted hours */
|
|
120
|
+
amount: number;
|
|
121
|
+
/** Number of granted hours for the first month: If this is set, use this value for the first month */
|
|
122
|
+
firstMonthAmount?: number;
|
|
123
|
+
planId?: string;
|
|
124
|
+
paymentReference?: string;
|
|
125
|
+
paymentData?: PaymentData;
|
|
126
|
+
teamSubscriptionSlotId?: string;
|
|
127
|
+
/** marks the subscription as deleted */
|
|
128
|
+
deleted?: boolean;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface SubscriptionAndUser extends Subscription {
|
|
132
|
+
user: User;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface PaymentData {
|
|
136
|
+
/** Marks the date as of which the _switch_ is effective. */
|
|
137
|
+
downgradeDate?: string;
|
|
138
|
+
/** Determines the new plan the dowgrade is targeted against (optional for backwards compatibility) */
|
|
139
|
+
newPlan?: string;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface UserPaidSubscription extends Subscription {
|
|
143
|
+
paymentReference: string;
|
|
144
|
+
paymentData?: PaymentData;
|
|
145
|
+
}
|
|
146
|
+
export namespace UserPaidSubscription {
|
|
147
|
+
export function is(data: any): data is UserPaidSubscription {
|
|
148
|
+
return !!data
|
|
149
|
+
&& data.hasOwnProperty('paymentReference');
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface AssignedTeamSubscription extends Subscription {
|
|
154
|
+
teamSubscriptionSlotId: string;
|
|
155
|
+
}
|
|
156
|
+
export namespace AssignedTeamSubscription {
|
|
157
|
+
export function is(data: any): data is AssignedTeamSubscription {
|
|
158
|
+
return !!data
|
|
159
|
+
&& data.hasOwnProperty('teamSubscriptionSlotId');
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export namespace Subscription {
|
|
164
|
+
export function create(newSubscription: Omit<Subscription, 'uid'>) {
|
|
165
|
+
const subscription = newSubscription as Subscription;
|
|
166
|
+
subscription.uid = uuidv4();
|
|
167
|
+
return subscription;
|
|
168
|
+
};
|
|
169
|
+
export function cancelSubscription(s: Subscription, cancellationDate: string, endDate?: string) {
|
|
170
|
+
s.endDate = endDate || cancellationDate;
|
|
171
|
+
s.cancellationDate = cancellationDate;
|
|
172
|
+
};
|
|
173
|
+
export function isSame(s1: Subscription | undefined, s2: Subscription | undefined): boolean {
|
|
174
|
+
return !!s1 && !!s2
|
|
175
|
+
&& s1.userId === s2.userId
|
|
176
|
+
&& s1.planId === s2.planId
|
|
177
|
+
&& s1.startDate === s2.startDate
|
|
178
|
+
&& s1.endDate === s2.endDate
|
|
179
|
+
&& s1.amount === s2.amount
|
|
180
|
+
&& s1.cancellationDate === s2.cancellationDate
|
|
181
|
+
&& s1.deleted === s2.deleted
|
|
182
|
+
&& ((s1.paymentData === undefined && s2.paymentData === undefined)
|
|
183
|
+
|| (!!s1.paymentData && !!s2.paymentData
|
|
184
|
+
&& s1.paymentData.downgradeDate === s2.paymentData.downgradeDate
|
|
185
|
+
&& s1.paymentData.newPlan === s2.paymentData.newPlan));
|
|
186
|
+
};
|
|
187
|
+
export function isActive(s: Subscription, date: string): boolean {
|
|
188
|
+
return s.startDate <= date && (s.endDate === undefined || date < s.endDate);
|
|
189
|
+
};
|
|
190
|
+
export function isDowngraded(s: Subscription) {
|
|
191
|
+
return s.paymentData && s.paymentData.downgradeDate;
|
|
192
|
+
};
|
|
193
|
+
export function calculateCurrentPeriod(startDate: string, now: Date) {
|
|
194
|
+
let nextStartDate = startDate;
|
|
195
|
+
do {
|
|
196
|
+
startDate = nextStartDate;
|
|
197
|
+
nextStartDate = oneMonthLater(startDate, new Date(startDate).getDate());
|
|
198
|
+
} while (nextStartDate < now.toISOString());
|
|
199
|
+
return { startDate, endDate: nextStartDate };
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export type MaybeSubscription = Subscription | undefined;
|
|
204
|
+
|
|
205
|
+
export interface Period {
|
|
206
|
+
startDate: string; // inclusive
|
|
207
|
+
endDate: string; // exclusive
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export type MaybePeriod = Period | undefined;
|
|
211
|
+
|
|
212
|
+
export type AccountEntryFixedPeriod = Omit<AccountEntry, 'uid'> & { expiryDate: string };
|
|
213
|
+
export interface AccountStatement extends Period {
|
|
214
|
+
userId: string;
|
|
215
|
+
/**
|
|
216
|
+
* The subscriptions that have not been cancelled yet at the end of the period
|
|
217
|
+
*/
|
|
218
|
+
subscriptions: Subscription[];
|
|
219
|
+
credits: Credit[];
|
|
220
|
+
debits: Debit[];
|
|
221
|
+
/** Remaining valid hours (accumulated from credits) */
|
|
222
|
+
remainingHours: RemainingHours;
|
|
223
|
+
}
|
|
224
|
+
export type RemainingHours = number | 'unlimited';
|
|
225
|
+
|
|
226
|
+
export interface CreditAlert {
|
|
227
|
+
userId: string,
|
|
228
|
+
remainingUsageHours: number
|
|
229
|
+
}
|
package/src/admin-protocol.ts
CHANGED
|
@@ -1,26 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c) 2020
|
|
2
|
+
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
|
|
3
3
|
* Licensed under the GNU Affero General Public License (AGPL).
|
|
4
4
|
* See License-AGPL.txt in the project root for license information.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { User, Workspace, NamedWorkspaceFeatureFlag } from "./protocol";
|
|
8
|
-
import { Without } from "./util/without";
|
|
9
8
|
import { WorkspaceInstance, WorkspaceInstancePhase } from "./workspace-instance";
|
|
10
9
|
import { RoleOrPermission } from "./permission";
|
|
10
|
+
import { AccountStatement } from "./accounting-protocol";
|
|
11
11
|
|
|
12
12
|
export interface AdminServer {
|
|
13
13
|
adminGetUsers(req: AdminGetListRequest<User>): Promise<AdminGetListResult<User>>;
|
|
14
14
|
adminGetUser(id: string): Promise<User>;
|
|
15
15
|
adminBlockUser(req: AdminBlockUserRequest): Promise<User>;
|
|
16
|
+
adminDeleteUser(id: string): Promise<void>;
|
|
16
17
|
adminModifyRoleOrPermission(req: AdminModifyRoleOrPermissionRequest): Promise<User>;
|
|
17
18
|
adminModifyPermanentWorkspaceFeatureFlag(req: AdminModifyPermanentWorkspaceFeatureFlagRequest): Promise<User>;
|
|
18
19
|
|
|
19
20
|
adminGetWorkspaces(req: AdminGetWorkspacesRequest): Promise<AdminGetListResult<WorkspaceAndInstance>>;
|
|
20
21
|
adminGetWorkspace(id: string): Promise<WorkspaceAndInstance>;
|
|
21
22
|
adminForceStopWorkspace(id: string): Promise<void>;
|
|
23
|
+
adminRestoreSoftDeletedWorkspace(id: string): Promise<void>;
|
|
22
24
|
|
|
23
25
|
adminSetLicense(key: string): Promise<void>;
|
|
26
|
+
|
|
27
|
+
adminGetAccountStatement(userId: string): Promise<AccountStatement>;
|
|
28
|
+
adminSetProfessionalOpenSource(userId: string, shouldGetProfOSS: boolean): Promise<void>;
|
|
29
|
+
adminIsStudent(userId: string): Promise<boolean>;
|
|
30
|
+
adminAddStudentEmailDomain(userId: string, domain: string): Promise<void>;
|
|
31
|
+
adminGrantExtraHours(userId: string, extraHours: number): Promise<void>;
|
|
24
32
|
}
|
|
25
33
|
|
|
26
34
|
export interface AdminGetListRequest<T> {
|
|
@@ -57,7 +65,7 @@ export interface AdminModifyPermanentWorkspaceFeatureFlagRequest {
|
|
|
57
65
|
}[]
|
|
58
66
|
}
|
|
59
67
|
|
|
60
|
-
export interface WorkspaceAndInstance extends
|
|
68
|
+
export interface WorkspaceAndInstance extends Omit<Workspace, "id"|"creationTime">, Omit<WorkspaceInstance, "id"|"creationTime"> {
|
|
61
69
|
workspaceId: string;
|
|
62
70
|
workspaceCreationTime: string;
|
|
63
71
|
instanceId: string;
|
|
@@ -65,6 +73,33 @@ export interface WorkspaceAndInstance extends Without<Workspace, "id"|"creationT
|
|
|
65
73
|
phase: WorkspaceInstancePhase;
|
|
66
74
|
}
|
|
67
75
|
|
|
68
|
-
export
|
|
69
|
-
|
|
70
|
-
|
|
76
|
+
export namespace WorkspaceAndInstance {
|
|
77
|
+
export function toWorkspace(wai: WorkspaceAndInstance): Workspace {
|
|
78
|
+
return {
|
|
79
|
+
id: wai.workspaceId,
|
|
80
|
+
creationTime: wai.workspaceCreationTime,
|
|
81
|
+
... wai
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function toInstance(wai: WorkspaceAndInstance): WorkspaceInstance | undefined {
|
|
86
|
+
if (!wai.instanceId) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
id: wai.instanceId,
|
|
91
|
+
creationTime: wai.instanceCreationTime,
|
|
92
|
+
... wai
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export type AdminGetWorkspacesRequest = AdminGetListRequest<WorkspaceAndInstance> & AdminGetWorkspacesQuery;
|
|
98
|
+
/** The fields are meant to be used either OR (not combined) */
|
|
99
|
+
export type AdminGetWorkspacesQuery = {
|
|
100
|
+
/** we use this field in case we have a UUIDv4 and don't know whether it's an (old) workspace or instance id */
|
|
101
|
+
instanceIdOrWorkspaceId?: string;
|
|
102
|
+
instanceId?: string;
|
|
103
|
+
workspaceId?: string;
|
|
104
|
+
ownerId?: string;
|
|
105
|
+
};
|
package/src/analytics.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
|
|
8
|
+
export const IAnalyticsWriter = Symbol("IAnalyticsWriter");
|
|
9
|
+
|
|
10
|
+
type Identity =
|
|
11
|
+
| { userId: string | number }
|
|
12
|
+
| { userId?: string | number; anonymousId: string | number };
|
|
13
|
+
|
|
14
|
+
interface Message {
|
|
15
|
+
messageId?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type IdentifyMessage = Message & Identity & {
|
|
19
|
+
traits?: any;
|
|
20
|
+
timestamp?: Date;
|
|
21
|
+
context?: any;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type TrackMessage = Message & Identity & {
|
|
25
|
+
event: string;
|
|
26
|
+
properties?: any;
|
|
27
|
+
timestamp?: Date;
|
|
28
|
+
context?: any;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type PageMessage = Message & Identity & {
|
|
32
|
+
properties?: any;
|
|
33
|
+
timestamp?: Date;
|
|
34
|
+
context?: any;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type RemoteTrackMessage = Omit<TrackMessage, "timestamp" | "userId" | "anonymousId"> & {
|
|
38
|
+
anonymousId?: string | number;
|
|
39
|
+
};
|
|
40
|
+
export type RemotePageMessage = Omit<PageMessage, "timestamp" | "userId"> & {
|
|
41
|
+
anonymousId?: string | number;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type RemoteIdentifyMessage = Omit<IdentifyMessage, "timestamp" | "userId" | "anonymousId">;
|
|
45
|
+
|
|
46
|
+
export interface IAnalyticsWriter {
|
|
47
|
+
|
|
48
|
+
identify(msg: IdentifyMessage): void;
|
|
49
|
+
|
|
50
|
+
track(msg: TrackMessage): void;
|
|
51
|
+
|
|
52
|
+
page(msg: PageMessage): void;
|
|
53
|
+
|
|
54
|
+
}
|
package/src/auth.ts
ADDED
|
@@ -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 SelectAccountPayload {
|
|
8
|
+
currentUser: {
|
|
9
|
+
name: string;
|
|
10
|
+
avatarUrl: string;
|
|
11
|
+
authHost: string;
|
|
12
|
+
authName: string;
|
|
13
|
+
authProviderType: string;
|
|
14
|
+
},
|
|
15
|
+
otherUser: {
|
|
16
|
+
name: string;
|
|
17
|
+
avatarUrl: string;
|
|
18
|
+
authHost: string;
|
|
19
|
+
authName: string;
|
|
20
|
+
authProviderType: string;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export namespace SelectAccountPayload {
|
|
24
|
+
export function is(data: any): data is SelectAccountPayload {
|
|
25
|
+
return typeof data === "object" && "currentUser" in data && "otherUser" in data;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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 * as chai from 'chai';
|
|
8
|
+
import { suite, test } from 'mocha-typescript';
|
|
9
|
+
import { ContextURL } from './context-url';
|
|
10
|
+
const expect = chai.expect;
|
|
11
|
+
|
|
12
|
+
@suite
|
|
13
|
+
export class ContextUrlTest {
|
|
14
|
+
|
|
15
|
+
@test public parseContextUrl_withEnvVar() {
|
|
16
|
+
const actual = ContextURL.parseToURL("passedin=test%20value/https://github.com/gitpod-io/gitpod-test-repo");
|
|
17
|
+
expect(actual?.host).to.equal("github.com");
|
|
18
|
+
expect(actual?.pathname).to.equal("/gitpod-io/gitpod-test-repo");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@test public parseContextUrl_withEnvVar_withoutSchema() {
|
|
22
|
+
const actual = ContextURL.parseToURL("passedin=test%20value/github.com/gitpod-io/gitpod-test-repo");
|
|
23
|
+
expect(actual?.host).to.equal("github.com");
|
|
24
|
+
expect(actual?.pathname).to.equal("/gitpod-io/gitpod-test-repo");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@test public parseContextUrl_withPrebuild() {
|
|
28
|
+
const actual = ContextURL.parseToURL("prebuild/https://github.com/gitpod-io/gitpod-test-repo");
|
|
29
|
+
expect(actual?.host).to.equal("github.com");
|
|
30
|
+
expect(actual?.pathname).to.equal("/gitpod-io/gitpod-test-repo");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@test public parseContextUrl_withPrebuild_withoutSchema() {
|
|
34
|
+
const actual = ContextURL.parseToURL("prebuild/github.com/gitpod-io/gitpod-test-repo");
|
|
35
|
+
expect(actual?.host).to.equal("github.com");
|
|
36
|
+
expect(actual?.pathname).to.equal("/gitpod-io/gitpod-test-repo");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
module.exports = new ContextUrlTest()
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
export namespace ContextURL {
|
|
8
|
+
export const INCREMENTAL_PREBUILD_PREFIX = "incremental-prebuild";
|
|
9
|
+
export const PREBUILD_PREFIX = "prebuild";
|
|
10
|
+
export const IMAGEBUILD_PREFIX = "imagebuild";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The field "contextUrl" might contain prefixes like:
|
|
14
|
+
* - envvar1=value1/...
|
|
15
|
+
* - prebuild/...
|
|
16
|
+
* This is the analogon to the (Prefix)ContextParser structure in "server".
|
|
17
|
+
*/
|
|
18
|
+
export function parseToURL(contextUrl: string | undefined): URL | undefined {
|
|
19
|
+
if (contextUrl === undefined) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const segments = contextUrl.split("/");
|
|
24
|
+
if (segments.length === 1) {
|
|
25
|
+
return new URL(segments[0]); // this might be something, we just try
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const segmentsToURL = (offset: number): URL => {
|
|
29
|
+
let rest = segments.slice(offset).join("/");
|
|
30
|
+
if (!rest.startsWith("http")) {
|
|
31
|
+
rest = 'https://' + rest;
|
|
32
|
+
}
|
|
33
|
+
return new URL(rest);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
const firstSegment = segments[0];
|
|
38
|
+
if (firstSegment === PREBUILD_PREFIX ||
|
|
39
|
+
firstSegment === INCREMENTAL_PREBUILD_PREFIX ||
|
|
40
|
+
firstSegment === IMAGEBUILD_PREFIX) {
|
|
41
|
+
return segmentsToURL(1);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// check for env vars
|
|
45
|
+
if (firstSegment.indexOf("=") !== -1) {
|
|
46
|
+
return segmentsToURL(1);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return segmentsToURL(0);
|
|
50
|
+
}
|
|
51
|
+
}
|
package/src/email-protocol.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c) 2020
|
|
2
|
+
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
|
|
3
3
|
* Licensed under the GNU Affero General Public License (AGPL).
|
|
4
4
|
* See License-AGPL.txt in the project root for license information.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import uuidv4 = require("uuid/v4");
|
|
7
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
9
8
|
|
|
10
9
|
export type EMailState = "scheduledInternal"
|
|
11
10
|
| "scheduledSendgrid";
|
|
@@ -59,7 +58,7 @@ export type EMail = {
|
|
|
59
58
|
} & EMailStatus;
|
|
60
59
|
|
|
61
60
|
export namespace EMail {
|
|
62
|
-
export const create = (ts:
|
|
61
|
+
export const create = (ts: Omit<EMail, 'uid'>): EMail => {
|
|
63
62
|
const withId = ts as EMail;
|
|
64
63
|
withId.uid = uuidv4();
|
|
65
64
|
return withId;
|
package/src/env.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c) 2020
|
|
2
|
+
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
|
|
3
3
|
* Licensed under the GNU Affero General Public License (AGPL).
|
|
4
4
|
* See License-AGPL.txt in the project root for license information.
|
|
5
5
|
*/
|
|
@@ -13,18 +13,18 @@ const legacyStagenameTranslation: { [key: string]: KubeStage } = {
|
|
|
13
13
|
"dev": "dev"
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
export function translateLegacyStagename(kubeStage: string): KubeStage {
|
|
17
|
+
const stage = legacyStagenameTranslation[kubeStage];
|
|
18
|
+
if (!stage) {
|
|
19
|
+
throw new Error(`Invalid KUBE_STAGE: ${kubeStage}`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return stage;
|
|
23
|
+
}
|
|
24
|
+
|
|
16
25
|
@injectable()
|
|
17
26
|
export abstract class AbstractComponentEnv {
|
|
18
|
-
readonly kubeStage: KubeStage = getEnvVarParsed('KUBE_STAGE',
|
|
19
|
-
const stage = legacyStagenameTranslation[kubeStage];
|
|
20
|
-
if (!stage) {
|
|
21
|
-
throw new Error(`Environment variable invalid: KUBE_STAGE=${kubeStage}`);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return stage;
|
|
25
|
-
});
|
|
26
|
-
readonly kubeNamespace: string = getEnvVar('KUBE_NAMESPACE');
|
|
27
|
-
readonly version: string = getEnvVar('VERSION');
|
|
27
|
+
readonly kubeStage: KubeStage = getEnvVarParsed('KUBE_STAGE', translateLegacyStagename);
|
|
28
28
|
|
|
29
29
|
readonly installationLongname: string = getEnvVar("GITPOD_INSTALLATION_LONGNAME")
|
|
30
30
|
readonly installationShortname: string = getEnvVar("GITPOD_INSTALLATION_SHORTNAME")
|