@serve.zone/interfaces 32.84.0 → 32.86.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.
@@ -20,10 +20,12 @@ import {
20
20
  } from '../private/canonicaljson.js';
21
21
  import { hasExactKeys, readDataElements, readDataProperties } from '../private/dataproperties.js';
22
22
  import type { TCompleteKeyList } from '../private/keylist.js';
23
+ import { appStoreDefaultHostRoles, appStoreHostRolesFeatureId } from './types.js';
23
24
  import { validateAppStoreVersionConfig } from './versionconfig.js';
24
25
  import type {
25
26
  IAppStoreVersionConfig,
26
27
  IServezoneAppStoreAppInfo,
28
+ TAppStoreHostRole,
27
29
  TAppStoreUpgradeStrategy,
28
30
  } from './types.js';
29
31
 
@@ -91,6 +93,7 @@ const versionConfigKeyList = [
91
93
  'publishedPorts',
92
94
  'platformRequirements',
93
95
  'platformOidc',
96
+ 'hostRoles',
94
97
  'minOneboxVersion',
95
98
  'minCloudlyVersion',
96
99
  'changelog',
@@ -911,10 +914,31 @@ const consumerMinimumVersionKeys = Object.freeze({
911
914
  cloudly: 'minCloudlyVersion',
912
915
  } as const);
913
916
 
917
+ /**
918
+ * The host role each consumer installs as (`IAppStoreVersionConfig.hostRoles`): Onebox is the
919
+ * controller host, Cloudly installs workloads on its cluster.
920
+ */
921
+ export const appStoreCatalogConsumerHostRoles: Readonly<Record<TAppStoreCatalogConsumerKind, TAppStoreHostRole>> =
922
+ Object.freeze({
923
+ onebox: 'controllerHost',
924
+ cloudly: 'cluster',
925
+ });
926
+
927
+ /** The host roles a version is installed as: its `hostRoles`, or `appStoreDefaultHostRoles` when absent. */
928
+ export const getAppStoreCatalogVersionHostRoles = (
929
+ configArg: TAppStoreCatalogVersionConfig,
930
+ ): readonly TAppStoreHostRole[] => configArg.hostRoles ?? appStoreDefaultHostRoles;
931
+
914
932
  /** Why a listed version is not an install or upgrade target for this consumer. */
915
933
  export type TAppStoreCatalogInstallTargetRefusal =
916
934
  | { reason: 'versionWithdrawn'; withdrawal: IAppStoreCatalogWithdrawal }
917
935
  | { reason: 'featuresUnsupported'; missingFeatureIds: string[] }
936
+ /** The version's host roles (`getAppStoreCatalogVersionHostRoles`) do not include this host's role. */
937
+ | {
938
+ reason: 'hostRoleUnsupported';
939
+ consumerKind: TAppStoreCatalogConsumerKind;
940
+ hostRole: TAppStoreHostRole;
941
+ }
918
942
  /** The version names a minimum release of this host (`minOneboxVersion`, `minCloudlyVersion`) newer than it runs. */
919
943
  | {
920
944
  reason: 'consumerVersionTooOld';
@@ -925,12 +949,18 @@ export type TAppStoreCatalogInstallTargetRefusal =
925
949
 
926
950
  /**
927
951
  * Whether a consumer may install a listed version, or upgrade a service to it; `null` when it may.
928
- * A withdrawn version, a version requiring a feature the consumer does not fulfil and a version
929
- * requiring a newer release of the consumer stay listed and are refused here, in that order, and
930
- * nowhere else is a second answer needed.
952
+ * A withdrawn version, a version requiring a feature the consumer does not fulfil, a version not
953
+ * naming the consumer's host role and a version requiring a newer release of the consumer stay
954
+ * listed and are refused here, in that order, and nowhere else is a second answer needed.
931
955
  *
932
- * A host passes `consumerArg` on every call; without it the minimum release is not judged. A
933
- * consumer version that is not `MAJOR.MINOR.PATCH` throws: it is the host's own constant.
956
+ * The host role is judged for a consumer that fulfils `appStoreHostRolesFeatureId`: its role is
957
+ * `appStoreCatalogConsumerHostRoles[consumer.kind]`, and a version without `hostRoles` is a
958
+ * `cluster` version (`getAppStoreCatalogVersionHostRoles`). A consumer that does not advertise the
959
+ * feature is judged as before the member existed, and never installs a version declaring it.
960
+ *
961
+ * A host passes `consumerArg` on every call; without it neither the host role nor the minimum
962
+ * release is judged. A consumer version that is not `MAJOR.MINOR.PATCH` throws: it is the host's
963
+ * own constant.
934
964
  */
935
965
  export const judgeAppStoreCatalogInstallTarget = (
936
966
  versionArg: IAppStoreCatalogVersion,
@@ -942,9 +972,15 @@ export const judgeAppStoreCatalogInstallTarget = (
942
972
  throw new Error('App Store catalog consumer version must be MAJOR.MINOR.PATCH');
943
973
  }
944
974
  if (versionArg.withdrawn !== undefined) return { reason: 'versionWithdrawn', withdrawal: versionArg.withdrawn };
945
- const missingFeatureIds = getAppStoreCatalogMissingFeatureIds(versionArg.config, supportedFeatureIdsArg);
975
+ const supportedFeatureIds = new Set(supportedFeatureIdsArg);
976
+ const missingFeatureIds = getAppStoreCatalogMissingFeatureIds(versionArg.config, supportedFeatureIds);
946
977
  if (missingFeatureIds.length > 0) return { reason: 'featuresUnsupported', missingFeatureIds };
947
978
  if (consumerArg === undefined || consumerVersion === null) return null;
979
+ const hostRole = appStoreCatalogConsumerHostRoles[consumerArg.kind];
980
+ if (supportedFeatureIds.has(appStoreHostRolesFeatureId)
981
+ && !getAppStoreCatalogVersionHostRoles(versionArg.config).includes(hostRole)) {
982
+ return { reason: 'hostRoleUnsupported', consumerKind: consumerArg.kind, hostRole };
983
+ }
948
984
  const minimumVersion = versionArg.config[consumerMinimumVersionKeys[consumerArg.kind]];
949
985
  if (minimumVersion === undefined) return null;
950
986
  const minimum = parseReleaseVersion(minimumVersion);
@@ -74,6 +74,29 @@ export const appStoreStorageFeatureIds = {
74
74
  export type TAppStoreStorageFeatureId =
75
75
  typeof appStoreStorageFeatureIds[keyof typeof appStoreStorageFeatureIds];
76
76
 
77
+ /**
78
+ * The host roles a version can be installed as (`IAppStoreVersionConfig.hostRoles`):
79
+ * `controllerHost` is the host that runs the controller itself (Onebox, the base host of Cloudly);
80
+ * `cluster` is a workload a controller places on its cluster (Cloudly's App Store).
81
+ */
82
+ export const appStoreHostRoles = ['cluster', 'controllerHost'] as const;
83
+
84
+ export type TAppStoreHostRole = typeof appStoreHostRoles[number];
85
+
86
+ /**
87
+ * The roles of a version that states no `hostRoles`: every version published before the member
88
+ * existed is a cluster workload template, never a controller-host one.
89
+ */
90
+ export const appStoreDefaultHostRoles: readonly TAppStoreHostRole[] = Object.freeze(['cluster']);
91
+
92
+ /**
93
+ * The feature id a version declaring `hostRoles` names in `requiresFeatures`. A consumer that
94
+ * advertises it has its host role judged on every version (`judgeAppStoreCatalogInstallTarget`); a
95
+ * consumer that does not, including every one built before the member, skips the config of a
96
+ * version declaring it and never installs that version.
97
+ */
98
+ export const appStoreHostRolesFeatureId = 'host.roles' as const;
99
+
77
100
  export type TAppStoreStoragePurpose =
78
101
  | 'runtime'
79
102
  | 'database'
@@ -391,7 +414,8 @@ export interface IAppStoreAppVersionState {
391
414
  /**
392
415
  * `null` when the host may install the version or upgrade a service to it; otherwise
393
416
  * `versionWithdrawn` with the withdrawal, `featuresUnsupported` with the feature ids the host
394
- * does not fulfil or `consumerVersionTooOld` with the host release the version requires, as
417
+ * does not fulfil, `hostRoleUnsupported` with the host role the version does not name or
418
+ * `consumerVersionTooOld` with the host release the version requires, as
395
419
  * `judgeAppStoreCatalogInstallTarget` answers it.
396
420
  */
397
421
  installRefusal: TAppStoreCatalogInstallTargetRefusal | null;
@@ -494,6 +518,14 @@ export interface IAppStoreVersionConfig {
494
518
  * creates a client, injects credentials, or emits app-scoped role claims.
495
519
  */
496
520
  platformOidc?: IAppStorePlatformOidcCapability;
521
+ /**
522
+ * The host roles this version is installed as, as a non-empty strictly increasing list of
523
+ * `appStoreHostRoles` values; absent means `appStoreDefaultHostRoles`. A host that advertises
524
+ * `appStoreHostRolesFeatureId` and whose role (`appStoreCatalogConsumerHostRoles`) is not listed
525
+ * refuses the version as an install or upgrade target (`hostRoleUnsupported`). A version
526
+ * declaring it names `appStoreHostRolesFeatureId` in `requiresFeatures`.
527
+ */
528
+ hostRoles?: TAppStoreHostRole[];
497
529
  minOneboxVersion?: string;
498
530
  minCloudlyVersion?: string;
499
531
  appStoreVersion?: string;
@@ -35,6 +35,8 @@ import type { TObjectStorageDelivery } from '../platform/storage.js';
35
35
  import {
36
36
  appStoreBackupExclusionLimits,
37
37
  appStoreDatabaseBackupExclusionLimits,
38
+ appStoreHostRoles,
39
+ appStoreHostRolesFeatureId,
38
40
  appStoreStorageFeatureIds,
39
41
  validateAppStoreEnvironmentDeclarations,
40
42
  validateAppStoreVersionPlatformOidc,
@@ -63,6 +65,7 @@ const versionConfigMemberList = [
63
65
  'publishedPorts',
64
66
  'platformRequirements',
65
67
  'platformOidc',
68
+ 'hostRoles',
66
69
  'minOneboxVersion',
67
70
  'minCloudlyVersion',
68
71
  'appStoreVersion',
@@ -103,6 +106,7 @@ const legacyFilesystemClassKey = 'legacyFilesystem';
103
106
  const legacyObjectStorageClassKey = 'legacyObjectStorage';
104
107
  const legacyObjectStorageRequestId = 'legacy-s3';
105
108
  const knownStorageFeatureIds: readonly string[] = Object.values(appStoreStorageFeatureIds);
109
+ const knownHostFeatureIds: readonly string[] = [appStoreHostRolesFeatureId];
106
110
  const platformRequirementKeys = ['mongodb', 's3', 'clickhouse', 'valkey', 'mariadb', 'mail'] as const;
107
111
  const controlCharacterPattern = /[\u0000-\u001f\u007f]/;
108
112
  /** The C0 and C1 controls and DEL: what the database engine refuses in a namespace component. */
@@ -623,6 +627,7 @@ function checkFeatureDeclaration(
623
627
  explicitRequestsArg: readonly TAppStoreStorageRequest[],
624
628
  backupExclusionsArg: readonly IAppStoreBackupExclusion[],
625
629
  databaseBackupExclusionsArg: readonly IAppStoreDatabaseBackupExclusion[],
630
+ hostRolesDeclaredArg: boolean,
626
631
  labelArg: string,
627
632
  ): void {
628
633
  const derivedFeatures = new Set<string>();
@@ -642,6 +647,7 @@ function checkFeatureDeclaration(
642
647
  if (databaseBackupExclusionsArg.length > 0) {
643
648
  derivedFeatures.add(appStoreStorageFeatureIds.databaseBackupExclusions);
644
649
  }
650
+ if (hostRolesDeclaredArg) derivedFeatures.add(appStoreHostRolesFeatureId);
645
651
 
646
652
  const declaredEntries = requiresFeaturesArg === undefined
647
653
  ? []
@@ -666,6 +672,12 @@ function checkFeatureDeclaration(
666
672
  if (knownStorageFeatureIds.includes(declaredFeature) && !derivedFeatures.has(declaredFeature)) {
667
673
  reject(`Invalid ${labelArg}: storage feature '${declaredFeature}' is not used`);
668
674
  }
675
+ if (declaredFeature.startsWith('host.') && !knownHostFeatureIds.includes(declaredFeature)) {
676
+ reject(`Invalid ${labelArg}: unknown host feature '${declaredFeature}'`);
677
+ }
678
+ if (knownHostFeatureIds.includes(declaredFeature) && !derivedFeatures.has(declaredFeature)) {
679
+ reject(`Invalid ${labelArg}: host feature '${declaredFeature}' is not used`);
680
+ }
669
681
  }
670
682
  }
671
683
 
@@ -958,6 +970,7 @@ function checkStorage(configArg: Record<string, unknown>, labelArg: string): voi
958
970
  explicitRequests,
959
971
  backupExclusions,
960
972
  databaseBackupExclusions,
973
+ configArg.hostRoles !== undefined,
961
974
  labelArg,
962
975
  );
963
976
  checkDatabaseBackupExclusionTargets(databaseBackupExclusions, platformRequirements, labelArg);
@@ -1024,6 +1037,25 @@ function checkStorage(configArg: Record<string, unknown>, labelArg: string): voi
1024
1037
  }
1025
1038
  }
1026
1039
 
1040
+ // ---------------------------------------------------------------------------------------------
1041
+ // Host roles
1042
+
1043
+ function checkHostRoles(hostRolesArg: unknown, labelArg: string): void {
1044
+ if (hostRolesArg === undefined) return;
1045
+ const entries = readDataElements(hostRolesArg, appStoreHostRoles.length);
1046
+ if (entries === null || entries.length === 0) {
1047
+ reject(`Invalid ${labelArg}: hostRoles must list between 1 and ${appStoreHostRoles.length} host roles`);
1048
+ }
1049
+ let previous: string | null = null;
1050
+ entries.forEach((entryArg, indexArg) => {
1051
+ assertMember(entryArg, appStoreHostRoles, `${labelArg} hostRoles[${indexArg}]`);
1052
+ if (previous !== null && compareWireTokens(previous, entryArg) >= 0) {
1053
+ reject(`Invalid ${labelArg}: hostRoles must be in strictly increasing order`);
1054
+ }
1055
+ previous = entryArg;
1056
+ });
1057
+ }
1058
+
1027
1059
  // ---------------------------------------------------------------------------------------------
1028
1060
  // Exported validators
1029
1061
 
@@ -1072,9 +1104,13 @@ export const validateAppStoreDatabaseBackupExclusionCollections = (
1072
1104
  labelArg = 'collections',
1073
1105
  ): string[] => firstRejection(() => checkDatabaseBackupExclusionCollections(valueArg, labelArg));
1074
1106
 
1107
+ /** `hostRoles`: absent, or a non-empty strictly increasing list of `appStoreHostRoles` values. */
1108
+ export const validateAppStoreVersionHostRoles = (hostRolesArg: unknown, labelArg = defaultLabel): string[] =>
1109
+ firstRejection(() => checkHostRoles(hostRolesArg, labelArg));
1110
+
1075
1111
  /**
1076
1112
  * Every member rule of a version config, in the order a host applies them: image, port model,
1077
- * container arguments, environment declarations, storage, platform OIDC, published ports.
1113
+ * container arguments, environment declarations, storage, platform OIDC, published ports, host roles.
1078
1114
  */
1079
1115
  export const validateAppStoreVersionConfig = (configArg: unknown, labelArg = defaultLabel): string[] =>
1080
1116
  firstRejection(() => {
@@ -1089,4 +1125,5 @@ export const validateAppStoreVersionConfig = (configArg: unknown, labelArg = def
1089
1125
  const platformOidcErrors = validateAppStoreVersionPlatformOidc(config);
1090
1126
  if (platformOidcErrors.length > 0) reject(`Invalid ${labelArg}: ${platformOidcErrors.join('; ')}`);
1091
1127
  checkPublishedPorts(config.publishedPorts, labelArg);
1128
+ checkHostRoles(config.hostRoles, labelArg);
1092
1129
  });
package/ts/data/index.ts CHANGED
@@ -93,6 +93,7 @@ export * from './serviceports.js';
93
93
  export * from './serviceruntime.js';
94
94
  export * from './launchersecretowner.js';
95
95
  export * from './location.js';
96
+ export * from './log.js';
96
97
  export * from './servicevolumeinitialization.js';
97
98
  export * from './status.js';
98
99
  export * from './taskexecution.js';
package/ts/data/log.ts ADDED
@@ -0,0 +1,86 @@
1
+ import * as plugins from '../plugins.js';
2
+
3
+ /**
4
+ * The log package contract `requests.log.IRequest_Log` carries. It is owned here and has exactly the
5
+ * members `@push.rocks/smartlog` 4.0.4 gave it, so a log package typed by smartlog 3, 4 or 5 is
6
+ * assignable to `ILogPackage`. Narrowing a vocabulary (dropping `'deno'` from `TLogRuntime`) is a
7
+ * breaking change of this package.
8
+ */
9
+
10
+ /**
11
+ * the kind of a log package
12
+ */
13
+ export type TLogType = 'log' | 'increment' | 'gauge' | 'error' | 'success' | 'value' | 'finance' | 'compliance';
14
+
15
+ /**
16
+ * the level of a log package
17
+ */
18
+ export type TLogLevel = 'silly' | 'info' | 'debug' | 'note' | 'ok' | 'success' | 'warn' | 'error' | 'lifecycle';
19
+
20
+ /**
21
+ * the environment a sender states for itself
22
+ */
23
+ export type TLogEnvironment = 'local' | 'test' | 'staging' | 'production';
24
+
25
+ /**
26
+ * the runtime a sender states for itself; a label, not a list of supported runtimes
27
+ */
28
+ export type TLogRuntime = 'node' | 'chrome' | 'rust' | 'deno' | 'cloudflare_workers';
29
+
30
+ /**
31
+ * the context of a log package, e.g. which app in which version on which server
32
+ */
33
+ export interface ILogContext {
34
+ commitinfo?: plugins.tsclass.code.ICommitInfo;
35
+ company?: string;
36
+ companyunit?: string;
37
+ containerName?: string;
38
+ environment?: TLogEnvironment;
39
+ runtime?: TLogRuntime;
40
+ zone?: string;
41
+ }
42
+
43
+ export interface ILogCorrelation {
44
+ /**
45
+ * a unique id for this log
46
+ */
47
+ id: string;
48
+ /**
49
+ * the type of this log
50
+ */
51
+ type: 'none' | 'service' | 'build' | 'infrastructure' | 'cdn';
52
+ /**
53
+ * the instance on which the log is created, for pinning logs to an instance in a cluster
54
+ */
55
+ instance?: string;
56
+ /**
57
+ * a series of logs
58
+ */
59
+ group?: string;
60
+ /**
61
+ * a transaction the log belongs to, e.g. a payment or a request travelling through several backend instances
62
+ */
63
+ transaction?: string;
64
+ }
65
+
66
+ /**
67
+ * one log package
68
+ */
69
+ export interface ILogPackage<T = unknown> {
70
+ /**
71
+ * a unix timestamp in milliseconds
72
+ */
73
+ timestamp: number;
74
+ type: TLogType;
75
+ context: ILogContext;
76
+ level: TLogLevel;
77
+ /**
78
+ * allows grouping of log messages
79
+ */
80
+ correlation: ILogCorrelation;
81
+ /**
82
+ * the message to log
83
+ */
84
+ message: string;
85
+ data?: T;
86
+ }
package/ts/plugins.ts CHANGED
@@ -7,11 +7,9 @@ export {
7
7
 
8
8
  // @push.rocks scope
9
9
  import * as smartcrypto from '@push.rocks/smartcrypto';
10
- import * as smartlogInterfaces from '@push.rocks/smartlog/interfaces';
11
10
 
12
11
  export {
13
12
  smartcrypto,
14
- smartlogInterfaces,
15
13
  }
16
14
 
17
15
  // tsclass scope
@@ -1,4 +1,5 @@
1
1
  import * as plugins from '../plugins.js';
2
+ import * as logInterfaces from '../data/log.js';
2
3
 
3
4
  export interface IRequest_Log extends plugins.typedrequestInterfaces.implementsTR<
4
5
  plugins.typedrequestInterfaces.ITypedRequest,
@@ -7,7 +8,7 @@ export interface IRequest_Log extends plugins.typedrequestInterfaces.implementsT
7
8
  method: 'log';
8
9
  request: {
9
10
  authToken: string;
10
- logPackages: plugins.smartlogInterfaces.ILogPackage[];
11
+ logPackages: logInterfaces.ILogPackage[];
11
12
  },
12
13
  response: {};
13
14
  }