@forge/runtime 6.0.0-next.0-experimental-97e4b11 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/out/index.d.ts +1 -25
  3. package/out/index.d.ts.map +1 -1
  4. package/out/index.js +1 -37
  5. package/out/request.d.ts +91 -338
  6. package/out/request.d.ts.map +1 -1
  7. package/out/request.js +0 -130
  8. package/out/result.d.ts +1 -2
  9. package/out/result.d.ts.map +1 -1
  10. package/out/sandbox/index.d.ts +0 -2
  11. package/out/sandbox/index.d.ts.map +1 -1
  12. package/out/sandbox/index.js +0 -2
  13. package/out/sandbox/invocation-event.d.ts +7 -49
  14. package/out/sandbox/invocation-event.d.ts.map +1 -1
  15. package/out/sandbox/invocation-event.js +9 -50
  16. package/out/sandbox/sandbox.d.ts +2 -10
  17. package/out/sandbox/sandbox.d.ts.map +1 -1
  18. package/package.json +2 -34
  19. package/out/app-manifest.d.ts +0 -71
  20. package/out/app-manifest.d.ts.map +0 -1
  21. package/out/app-manifest.js +0 -83
  22. package/out/config.d.ts +0 -6
  23. package/out/config.d.ts.map +0 -1
  24. package/out/config.js +0 -2
  25. package/out/context.d.ts +0 -37
  26. package/out/context.d.ts.map +0 -1
  27. package/out/context.js +0 -48
  28. package/out/feature-flag.d.ts +0 -15
  29. package/out/feature-flag.d.ts.map +0 -1
  30. package/out/feature-flag.js +0 -23
  31. package/out/limits/index.d.ts +0 -2
  32. package/out/limits/index.d.ts.map +0 -1
  33. package/out/limits/index.js +0 -4
  34. package/out/limits/tracker.d.ts +0 -30
  35. package/out/limits/tracker.d.ts.map +0 -1
  36. package/out/limits/tracker.js +0 -34
  37. package/out/logger.d.ts +0 -65
  38. package/out/logger.d.ts.map +0 -1
  39. package/out/logger.js +0 -19
  40. package/out/metrics/index.d.ts +0 -2
  41. package/out/metrics/index.d.ts.map +0 -1
  42. package/out/metrics/index.js +0 -4
  43. package/out/metrics/metrics.d.ts +0 -29
  44. package/out/metrics/metrics.d.ts.map +0 -1
  45. package/out/metrics/metrics.js +0 -78
  46. package/out/sandbox/inspector.d.ts +0 -39
  47. package/out/sandbox/inspector.d.ts.map +0 -1
  48. package/out/sandbox/inspector.js +0 -258
  49. package/out/sandbox/invocation-request.d.ts +0 -114
  50. package/out/sandbox/invocation-request.d.ts.map +0 -1
  51. package/out/sandbox/invocation-request.js +0 -271
  52. package/out/snapshot.d.ts +0 -17
  53. package/out/snapshot.d.ts.map +0 -1
  54. package/out/snapshot.js +0 -6
@@ -1,15 +0,0 @@
1
- import { Metadata } from './request';
2
- export declare const SHOULD_ATTACH_TOKEN_FOR_ATLASSIAN_ACCOUNT = "should-attach-token-for-atlassian-account";
3
- export declare const SHOULD_ATTACH_TOKEN_FOR_APP = "should-attach-token-for-app";
4
- export declare const XEN_RUNTIME_ENABLE_EGRESS_FILTER = "xen-runtime-enable-egress-filter";
5
- export declare const XEN_RUNTIME_EGRESS_DISCLOSURE_ENABLED = "xen-runtime-egress-disclosure-enabled";
6
- export declare const XEN_RUNTIME_ENABLE_NETWORK_LIMITS = "xen-runtime-enable-network-limits";
7
- export declare const XEN_RUNTIME_SHOULD_BLOCK_EXTERNAL_FETCH = "xen-runtime-should-block-external-fetch";
8
- export declare const XEN_RUNTIME_SHOULD_REPORT_METRICS = "xen-runtime-should-report-metrics";
9
- export declare class FeatureFlags {
10
- private flags;
11
- static fromRequestMetaData(metaData: Metadata): FeatureFlags;
12
- constructor(flags: string[]);
13
- isFeatureFlagEnabled(flag: string): boolean;
14
- }
15
- //# sourceMappingURL=feature-flag.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"feature-flag.d.ts","sourceRoot":"","sources":["../src/feature-flag.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAGrC,eAAO,MAAM,yCAAyC,8CAA8C,CAAC;AACrG,eAAO,MAAM,2BAA2B,gCAAgC,CAAC;AACzE,eAAO,MAAM,gCAAgC,qCAAqC,CAAC;AACnF,eAAO,MAAM,qCAAqC,0CAA0C,CAAC;AAC7F,eAAO,MAAM,iCAAiC,sCAAsC,CAAC;AACrF,eAAO,MAAM,uCAAuC,4CAA4C,CAAC;AACjG,eAAO,MAAM,iCAAiC,sCAAsC,CAAC;AACrF,qBAAa,YAAY;IAIX,OAAO,CAAC,KAAK;WAHX,mBAAmB,CAAC,QAAQ,EAAE,QAAQ;gBAGhC,KAAK,EAAE,MAAM,EAAE;IAC5B,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAGnD"}
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FeatureFlags = exports.XEN_RUNTIME_SHOULD_REPORT_METRICS = exports.XEN_RUNTIME_SHOULD_BLOCK_EXTERNAL_FETCH = exports.XEN_RUNTIME_ENABLE_NETWORK_LIMITS = exports.XEN_RUNTIME_EGRESS_DISCLOSURE_ENABLED = exports.XEN_RUNTIME_ENABLE_EGRESS_FILTER = exports.SHOULD_ATTACH_TOKEN_FOR_APP = exports.SHOULD_ATTACH_TOKEN_FOR_ATLASSIAN_ACCOUNT = void 0;
4
- exports.SHOULD_ATTACH_TOKEN_FOR_ATLASSIAN_ACCOUNT = 'should-attach-token-for-atlassian-account';
5
- exports.SHOULD_ATTACH_TOKEN_FOR_APP = 'should-attach-token-for-app';
6
- exports.XEN_RUNTIME_ENABLE_EGRESS_FILTER = 'xen-runtime-enable-egress-filter';
7
- exports.XEN_RUNTIME_EGRESS_DISCLOSURE_ENABLED = 'xen-runtime-egress-disclosure-enabled';
8
- exports.XEN_RUNTIME_ENABLE_NETWORK_LIMITS = 'xen-runtime-enable-network-limits';
9
- exports.XEN_RUNTIME_SHOULD_BLOCK_EXTERNAL_FETCH = 'xen-runtime-should-block-external-fetch';
10
- exports.XEN_RUNTIME_SHOULD_REPORT_METRICS = 'xen-runtime-should-report-metrics';
11
- class FeatureFlags {
12
- flags;
13
- static fromRequestMetaData(metaData) {
14
- return new FeatureFlags(metaData.featureFlags || []);
15
- }
16
- constructor(flags) {
17
- this.flags = flags;
18
- }
19
- isFeatureFlagEnabled(flag) {
20
- return this.flags.includes(flag);
21
- }
22
- }
23
- exports.FeatureFlags = FeatureFlags;
@@ -1,2 +0,0 @@
1
- export * from './tracker';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/limits/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./tracker"), exports);
@@ -1,30 +0,0 @@
1
- import { BaseInvocationRequest } from '../sandbox/invocation-request';
2
- export declare const Limit: {
3
- readonly InvocationLogEntryCount: "forge-invocation-log-entry-count";
4
- readonly FetchRequestLimit: "forge-fetch-request-count";
5
- };
6
- export interface LimitsTracker {
7
- incrementCount(limitKey: LimitKey, by?: number): void;
8
- getCount(limitKey: LimitKey): number;
9
- getLimit(limitKey: LimitKey): number | undefined;
10
- hasCountRemaining(limitKey: LimitKey): boolean;
11
- }
12
- export declare type LimitKey = (typeof Limit)[keyof typeof Limit];
13
- declare type LimitType = {
14
- [x in LimitKey]?: number;
15
- };
16
- declare type LimitCounter = {
17
- [x in LimitKey]?: number;
18
- };
19
- declare class PerInvocationLimitsTracker implements LimitsTracker {
20
- limits: LimitType;
21
- limitCount: LimitCounter;
22
- constructor(limits: LimitType | undefined);
23
- incrementCount(limitKey: LimitKey, by?: number): void;
24
- getCount(limitKey: LimitKey): number;
25
- getLimit(limitKey: LimitKey): number | undefined;
26
- hasCountRemaining(limitKey: LimitKey): boolean;
27
- }
28
- export declare const perInvocationLimitsTrackerFactory: (request: BaseInvocationRequest) => PerInvocationLimitsTracker;
29
- export {};
30
- //# sourceMappingURL=tracker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tracker.d.ts","sourceRoot":"","sources":["../../src/limits/tracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAItE,eAAO,MAAM,KAAK;;;CAGR,CAAC;AAEX,MAAM,WAAW,aAAa;IAC5B,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAAC;IACrC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC;IACjD,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC;CAChD;AAED,oBAAY,QAAQ,GAAG,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,OAAO,KAAK,CAAC,CAAC;AAC1D,aAAK,SAAS,GAAG;KAAG,CAAC,IAAI,QAAQ,CAAC,CAAC,EAAE,MAAM;CAAE,CAAC;AAC9C,aAAK,YAAY,GAAG;KAAG,CAAC,IAAI,QAAQ,CAAC,CAAC,EAAE,MAAM;CAAE,CAAC;AAEjD,cAAM,0BAA2B,YAAW,aAAa;IACvD,MAAM,EAAE,SAAS,CAAM;IACvB,UAAU,EAAE,YAAY,CAAM;gBAElB,MAAM,EAAE,SAAS,GAAG,SAAS;IAIzC,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,SAAI;IAIzC,QAAQ,CAAC,QAAQ,EAAE,QAAQ;IAI3B,QAAQ,CAAC,QAAQ,EAAE,QAAQ;IAQ3B,iBAAiB,CAAC,QAAQ,EAAE,QAAQ;CAOrC;AAED,eAAO,MAAM,iCAAiC,YAAa,qBAAqB,KAAG,0BAElF,CAAC"}
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.perInvocationLimitsTrackerFactory = exports.Limit = void 0;
4
- exports.Limit = {
5
- InvocationLogEntryCount: 'forge-invocation-log-entry-count',
6
- FetchRequestLimit: 'forge-fetch-request-count'
7
- };
8
- class PerInvocationLimitsTracker {
9
- limits = {};
10
- limitCount = {};
11
- constructor(limits) {
12
- this.limits = limits || {};
13
- }
14
- incrementCount(limitKey, by = 1) {
15
- this.limitCount[limitKey] = this.getCount(limitKey) + by;
16
- }
17
- getCount(limitKey) {
18
- return this.limitCount[limitKey] || 0;
19
- }
20
- getLimit(limitKey) {
21
- return this.limits[limitKey];
22
- }
23
- hasCountRemaining(limitKey) {
24
- const limit = this.limits[limitKey];
25
- if (limit) {
26
- return this.getCount(limitKey) < limit;
27
- }
28
- return true;
29
- }
30
- }
31
- const perInvocationLimitsTrackerFactory = (request) => {
32
- return new PerInvocationLimitsTracker(request.getLimits());
33
- };
34
- exports.perInvocationLimitsTrackerFactory = perInvocationLimitsTrackerFactory;
package/out/logger.d.ts DELETED
@@ -1,65 +0,0 @@
1
- export declare enum LogLevel {
2
- DEBUG = 20,
3
- INFO = 30,
4
- WARN = 40,
5
- ERROR = 50,
6
- FATAL = 60
7
- }
8
- export declare const CONSOLE_LEVEL_METHODS: readonly ["debug", "info", "warn", "error"];
9
- export declare const CONSOLE_METHODS: readonly ["debug", "info", "warn", "error", "log"];
10
- export declare type ConsoleMethod = (typeof CONSOLE_METHODS)[number];
11
- export declare enum LogType {
12
- HEADER = "header",
13
- FOOTER = "footer",
14
- LOG = "log"
15
- }
16
- export declare type LogHeader = {
17
- type: LogType.HEADER;
18
- id: string;
19
- appId: string;
20
- environmentId: string;
21
- appVersion: string;
22
- installationContext: string;
23
- functionKey: string;
24
- moduleType: string;
25
- moduleKey: string;
26
- b3: string;
27
- runtime: string;
28
- };
29
- export declare type LogFooter = {
30
- type: LogType.FOOTER;
31
- id: string;
32
- success: boolean;
33
- logMetadata: {
34
- bytes: number;
35
- truncated: boolean;
36
- errorCount: number;
37
- };
38
- outboundCalls: {
39
- count: number;
40
- stargateCount: number;
41
- externalCount: number;
42
- rejectedCount: number;
43
- bytesOut: number;
44
- bytesIn: number;
45
- msWaiting: number;
46
- };
47
- function: {
48
- bytesIn: number;
49
- bytesOut: number;
50
- durationMs: number;
51
- mem: number;
52
- };
53
- };
54
- export declare type LogLine = {
55
- type: LogType.LOG;
56
- id: string;
57
- msg: string | undefined;
58
- P: 3;
59
- ts: number;
60
- lvl: number;
61
- '*': any;
62
- region: string;
63
- };
64
- export declare type HeadedLogLine = Omit<LogHeader, 'type'> & LogLine;
65
- //# sourceMappingURL=logger.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAEA,oBAAY,QAAQ;IAClB,KAAK,KAAK;IACV,IAAI,KAAK;IACT,IAAI,KAAK;IACT,KAAK,KAAK;IACV,KAAK,KAAK;CACX;AAED,eAAO,MAAM,qBAAqB,6CAA8C,CAAC;AACjF,eAAO,MAAM,eAAe,oDAA6C,CAAC;AAE1E,oBAAY,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAE7D,oBAAY,OAAO;IACjB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,GAAG,QAAQ;CACZ;AAED,oBAAY,SAAS,GAAG;IACtB,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,oBAAY,SAAS,GAAG;IACtB,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE;QACX,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,OAAO,CAAC;QACnB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,aAAa,EAAE;QACb,KAAK,EAAE,MAAM,CAAC;QACd,aAAa,EAAE,MAAM,CAAC;QACtB,aAAa,EAAE,MAAM,CAAC;QACtB,aAAa,EAAE,MAAM,CAAC;QACtB,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,QAAQ,EAAE;QACR,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,MAAM,CAAC;QACnB,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;CACH,CAAC;AAEF,oBAAY,OAAO,GAAG;IACpB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,CAAC,EAAE,CAAC,CAAC;IACL,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,GAAG,CAAC;IACT,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,oBAAY,aAAa,GAAG,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC"}
package/out/logger.js DELETED
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LogType = exports.CONSOLE_METHODS = exports.CONSOLE_LEVEL_METHODS = exports.LogLevel = void 0;
4
- var LogLevel;
5
- (function (LogLevel) {
6
- LogLevel[LogLevel["DEBUG"] = 20] = "DEBUG";
7
- LogLevel[LogLevel["INFO"] = 30] = "INFO";
8
- LogLevel[LogLevel["WARN"] = 40] = "WARN";
9
- LogLevel[LogLevel["ERROR"] = 50] = "ERROR";
10
- LogLevel[LogLevel["FATAL"] = 60] = "FATAL";
11
- })(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
12
- exports.CONSOLE_LEVEL_METHODS = ['debug', 'info', 'warn', 'error'];
13
- exports.CONSOLE_METHODS = [...exports.CONSOLE_LEVEL_METHODS, 'log'];
14
- var LogType;
15
- (function (LogType) {
16
- LogType["HEADER"] = "header";
17
- LogType["FOOTER"] = "footer";
18
- LogType["LOG"] = "log";
19
- })(LogType = exports.LogType || (exports.LogType = {}));
@@ -1,2 +0,0 @@
1
- export * from './metrics';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/metrics/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./metrics"), exports);
@@ -1,29 +0,0 @@
1
- import { Metrics, Tags } from '@forge/util/packages/metrics-interface';
2
- import { BaseInvocationRequest } from '../sandbox/invocation-request';
3
- export declare enum MetricType {
4
- TimerMetric = "timer",
5
- CounterMetric = "counter",
6
- GaugeMetric = "gauge"
7
- }
8
- export interface Metric {
9
- name: string;
10
- type: MetricType;
11
- value: number | string;
12
- tags: Tags;
13
- }
14
- export declare class MetricsCollector {
15
- private readonly _metrics;
16
- constructor(_metrics: Metrics);
17
- metrics(): Metrics;
18
- collectMetrics(): Metric[];
19
- static collect(metrics: Metrics, prefix?: string | undefined): Metric[];
20
- wrapInMetrics<Ret>(options: {
21
- name: string;
22
- tags?: Tags;
23
- }, callback: () => Promise<Ret>): Promise<Ret>;
24
- }
25
- export declare const createMetricsCollector: (xenInvocationRequest: BaseInvocationRequest) => {
26
- collector: MetricsCollector;
27
- enabled: boolean;
28
- };
29
- //# sourceMappingURL=metrics.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../src/metrics/metrics.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAa,MAAM,wCAAwC,CAAC;AAElF,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAGtE,oBAAY,UAAU;IACpB,WAAW,UAAU;IACrB,aAAa,YAAY;IACzB,WAAW,UAAU;CACtB;AAED,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,IAAI,EAAE,IAAI,CAAC;CACZ;AAYD,qBAAa,gBAAgB;IACf,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,OAAO;IAEvC,OAAO,IAAI,OAAO;IAIlB,cAAc,IAAI,MAAM,EAAE;IAIjC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,GAAE,MAAM,GAAG,SAAqB,GAAG,MAAM,EAAE;IAuCrE,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,IAAI,CAAA;KAAE,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;CASpH;AAED,eAAO,MAAM,sBAAsB,yBACX,qBAAqB,KAC1C;IAAE,SAAS,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CASjD,CAAC"}
@@ -1,78 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createMetricsCollector = exports.MetricsCollector = exports.MetricType = void 0;
4
- const in_memory_metrics_1 = require("@forge/util/packages/in-memory-metrics");
5
- const metrics_interface_1 = require("@forge/util/packages/metrics-interface");
6
- const feature_flag_1 = require("../feature-flag");
7
- var MetricType;
8
- (function (MetricType) {
9
- MetricType["TimerMetric"] = "timer";
10
- MetricType["CounterMetric"] = "counter";
11
- MetricType["GaugeMetric"] = "gauge";
12
- })(MetricType = exports.MetricType || (exports.MetricType = {}));
13
- function isInMemoryMetrics(metrics) {
14
- return metrics.constructor.name === in_memory_metrics_1.InMemoryMetrics.name;
15
- }
16
- class MetricsCollector {
17
- _metrics;
18
- constructor(_metrics) {
19
- this._metrics = _metrics;
20
- }
21
- metrics() {
22
- return this._metrics;
23
- }
24
- collectMetrics() {
25
- return MetricsCollector.collect(this._metrics);
26
- }
27
- static collect(metrics, prefix = undefined) {
28
- if (!isInMemoryMetrics(metrics)) {
29
- return [];
30
- }
31
- const addPrefix = (p, value) => {
32
- return p ? p + '.' + value : value;
33
- };
34
- const allMetrics = Array.from(metrics.getChildren().values())
35
- .map((v) => [...MetricsCollector.collect(v, addPrefix(prefix, v.getName()))])
36
- .reduce((accumulator, value) => accumulator.concat(value), []);
37
- const counters = Array.from(metrics.getCounters().values()).map((v) => ({
38
- name: addPrefix(prefix, v.getName()),
39
- tags: v.getTags(),
40
- type: MetricType.CounterMetric,
41
- value: v.getCount()
42
- }));
43
- const gauges = Array.from(metrics.getGauges().values()).map((v) => ({
44
- name: addPrefix(prefix, v.getName()),
45
- tags: v.getTags(),
46
- type: MetricType.GaugeMetric,
47
- value: v.getValue()
48
- }));
49
- const timers = metrics.getTimers().map((v) => ({
50
- name: addPrefix(prefix, v.getName()),
51
- tags: v.getTags(),
52
- type: MetricType.TimerMetric,
53
- value: v.getTime()
54
- }));
55
- allMetrics.push(...timers, ...counters, ...gauges);
56
- return allMetrics;
57
- }
58
- async wrapInMetrics(options, callback) {
59
- this._metrics.counter(options.name, options.tags).incr();
60
- const timer = this._metrics.timing(options.name, options.tags).measure();
61
- try {
62
- return await callback();
63
- }
64
- finally {
65
- timer.stop();
66
- }
67
- }
68
- }
69
- exports.MetricsCollector = MetricsCollector;
70
- const createMetricsCollector = (xenInvocationRequest) => {
71
- const shouldReportMetrics = xenInvocationRequest.isFeatureFlagEnabled(feature_flag_1.XEN_RUNTIME_SHOULD_REPORT_METRICS);
72
- const metrics = shouldReportMetrics ? new in_memory_metrics_1.InMemoryMetrics() : new metrics_interface_1.NoMetrics();
73
- return {
74
- collector: new MetricsCollector(metrics),
75
- enabled: shouldReportMetrics
76
- };
77
- };
78
- exports.createMetricsCollector = createMetricsCollector;
@@ -1,39 +0,0 @@
1
- import { ConsoleMethod } from '../logger';
2
- export interface InspectorSessionCallbacks {
3
- onMessageFromFrontend: (messge: any) => void;
4
- onSessionStop: () => void;
5
- }
6
- export interface InspectorSessionControls {
7
- sendMessageToFrontend: (messge: any) => void;
8
- stopSession: () => void;
9
- }
10
- export declare type InspectorSessionCallbacksSupplier = (controls: InspectorSessionControls) => InspectorSessionCallbacks;
11
- export interface Inspector {
12
- startServer: (port?: number) => string;
13
- stopServer: () => Promise<void>;
14
- isServerStopped: () => boolean;
15
- startSession: (callbacksSupplier: InspectorSessionCallbacksSupplier) => InspectorSessionControls | undefined;
16
- logConsole: (method: ConsoleMethod, ...args: any[]) => void;
17
- }
18
- export declare const SETUP_METHODS: string[];
19
- export declare class ChromeInspector implements Inspector {
20
- static DENY_CODE: number;
21
- static DENY_REASON: string;
22
- static FORCE_RESET_FRONTEND_STATE_EVENTS: string[];
23
- private wss?;
24
- private callbacks?;
25
- private frontendMsgsForNewSandbox;
26
- startServer(port?: number): string;
27
- stopServer(): Promise<void>;
28
- isServerStopped(): boolean;
29
- startSession(callbacksSupplier: InspectorSessionCallbacksSupplier): InspectorSessionControls | undefined;
30
- logConsole(method: ConsoleMethod, ...args: any[]): void;
31
- getWebsocketPort(): number;
32
- private sendMessageToFrontend;
33
- private stopSession;
34
- private forceResetFrontendState;
35
- private addMessageForNewSandbox;
36
- private deliverMessagesForNewSandbox;
37
- }
38
- export declare const notImplementedInspector: Inspector;
39
- //# sourceMappingURL=inspector.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"inspector.d.ts","sourceRoot":"","sources":["../../src/sandbox/inspector.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,WAAW,yBAAyB;IACxC,qBAAqB,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;IAC7C,aAAa,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED,MAAM,WAAW,wBAAwB;IACvC,qBAAqB,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;IAC7C,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB;AAED,oBAAY,iCAAiC,GAAG,CAAC,QAAQ,EAAE,wBAAwB,KAAK,yBAAyB,CAAC;AAElH,MAAM,WAAW,SAAS;IAKxB,WAAW,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAKvC,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhC,eAAe,EAAE,MAAM,OAAO,CAAC;IAM/B,YAAY,EAAE,CAAC,iBAAiB,EAAE,iCAAiC,KAAK,wBAAwB,GAAG,SAAS,CAAC;IAK7G,UAAU,EAAE,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;CAC7D;AAqBD,eAAO,MAAM,aAAa,UASzB,CAAC;AAsFF,qBAAa,eAAgB,YAAW,SAAS;IAC/C,OAAc,SAAS,SAAQ;IAC/B,OAAc,WAAW,SAAkC;IAK3D,OAAc,iCAAiC,WAK7C;IAGF,OAAO,CAAC,GAAG,CAAC,CAAmB;IAC/B,OAAO,CAAC,SAAS,CAAC,CAA4B;IAY9C,OAAO,CAAC,yBAAyB,CAAa;IAEvC,WAAW,CAAC,IAAI,SAAI,GAAG,MAAM;IA0C7B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAoB3B,eAAe,IAAI,OAAO;IAI1B,YAAY,CAAC,iBAAiB,EAAE,iCAAiC,GAAG,wBAAwB,GAAG,SAAS;IAwBxG,UAAU,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IA8BvD,gBAAgB,IAAI,MAAM;IAcjC,OAAO,CAAC,qBAAqB,CAU3B;IAEF,OAAO,CAAC,WAAW,CAiBjB;IAEF,OAAO,CAAC,uBAAuB;IAM/B,OAAO,CAAC,uBAAuB;IAY/B,OAAO,CAAC,4BAA4B;CAarC;AAKD,eAAO,MAAM,uBAAuB,EAAE,SAYrC,CAAC"}
@@ -1,258 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.notImplementedInspector = exports.ChromeInspector = exports.SETUP_METHODS = void 0;
4
- const tslib_1 = require("tslib");
5
- const ws_1 = tslib_1.__importDefault(require("ws"));
6
- const util_1 = require("util");
7
- const CLOSE_CONNECTION_ON_SESSION_STOP = false;
8
- const VERBOSE_LOG = false;
9
- const INSPECTOR_SUBTYPE_DETECTORS = {
10
- null: (a) => a === null,
11
- array: Array.isArray,
12
- date: (a) => a instanceof Date,
13
- error: (a) => a instanceof Error,
14
- regexp: (a) => a instanceof RegExp
15
- };
16
- const inspectorSubtypeEntries = Object.entries(INSPECTOR_SUBTYPE_DETECTORS);
17
- exports.SETUP_METHODS = [
18
- 'Profiler.enable',
19
- 'Runtime.enable',
20
- 'Debugger.enable',
21
- 'Debugger.setPauseOnExceptions',
22
- 'Debugger.setAsyncCallStackDepth',
23
- 'Runtime.getIsolateId',
24
- 'Debugger.setBlackboxPatterns',
25
- 'Runtime.runIfWaitingForDebugger'
26
- ];
27
- const isMessageForNewSandbox = (message) => {
28
- const msg = JSON.parse(message);
29
- const { method } = msg;
30
- if (!method) {
31
- return false;
32
- }
33
- if (exports.SETUP_METHODS.includes(method)) {
34
- return true;
35
- }
36
- return (method.startsWith('Debugger.') &&
37
- method.toLowerCase().includes('breakpoint') &&
38
- method !== 'Debugger.getPossibleBreakpoints');
39
- };
40
- function log(...args) {
41
- console.log('[Inspector]', ...args);
42
- }
43
- function processArgForLogConsole(arg) {
44
- const type = typeof arg;
45
- if (type === 'undefined') {
46
- return { type };
47
- }
48
- if (arg === null) {
49
- return {
50
- type,
51
- subtype: 'null',
52
- value: null
53
- };
54
- }
55
- if (type === 'number' && (isNaN(arg) || !isFinite(arg))) {
56
- const description = arg.toString();
57
- return {
58
- type,
59
- unserializableValue: description,
60
- description
61
- };
62
- }
63
- const className = type === 'object' ? arg.constructor.name : undefined;
64
- const subtype = inspectorSubtypeEntries.find((a) => a[1](arg));
65
- return {
66
- type,
67
- ...(className ? { className } : undefined),
68
- ...(subtype ? { subtype: subtype[0] } : undefined),
69
- value: arg,
70
- description: (0, util_1.inspect)(arg)
71
- };
72
- }
73
- class ChromeInspector {
74
- static DENY_CODE = 1011;
75
- static DENY_REASON = 'Only one frontend is allowed';
76
- static FORCE_RESET_FRONTEND_STATE_EVENTS = [
77
- '{"method":"Runtime.executionContextsCleared"}',
78
- '{"method":"Inspector.targetReloadedAfterCrash"}'
79
- ];
80
- wss;
81
- callbacks;
82
- frontendMsgsForNewSandbox = [];
83
- startServer(port = 0) {
84
- const wss = new ws_1.default.Server({ port });
85
- wss.on('connection', (ws) => {
86
- if (wss.clients.size > 1) {
87
- ws.close(ChromeInspector.DENY_CODE, ChromeInspector.DENY_REASON);
88
- log(ChromeInspector.DENY_REASON);
89
- return;
90
- }
91
- if (VERBOSE_LOG) {
92
- log('Frontend connected');
93
- }
94
- ws.on('error', (err) => {
95
- log('Error', err);
96
- this.stopSession();
97
- });
98
- ws.on('close', () => {
99
- if (VERBOSE_LOG) {
100
- log('Frontend closed');
101
- }
102
- this.frontendMsgsForNewSandbox = [];
103
- this.stopSession();
104
- });
105
- ws.on('message', (message) => {
106
- if (this.callbacks) {
107
- this.addMessageForNewSandbox(message, true);
108
- this.callbacks.onMessageFromFrontend(message);
109
- }
110
- else {
111
- this.addMessageForNewSandbox(message, false);
112
- }
113
- });
114
- });
115
- this.wss = wss;
116
- return `127.0.0.1:${this.getWebsocketPort()}`;
117
- }
118
- stopServer() {
119
- const wss = this.wss;
120
- if (!wss) {
121
- return Promise.resolve();
122
- }
123
- this.stopSession();
124
- return new Promise((resolve, reject) => {
125
- wss.close((error) => {
126
- this.wss = undefined;
127
- if (error) {
128
- reject(error);
129
- }
130
- else {
131
- resolve();
132
- }
133
- });
134
- });
135
- }
136
- isServerStopped() {
137
- return !this.wss;
138
- }
139
- startSession(callbacksSupplier) {
140
- if (!this.wss || this.wss.clients.size === 0) {
141
- return undefined;
142
- }
143
- if (this.callbacks) {
144
- return undefined;
145
- }
146
- const controls = {
147
- sendMessageToFrontend: this.sendMessageToFrontend,
148
- stopSession: this.stopSession
149
- };
150
- this.callbacks = callbacksSupplier(controls);
151
- this.forceResetFrontendState();
152
- this.deliverMessagesForNewSandbox();
153
- return controls;
154
- }
155
- logConsole(method, ...args) {
156
- if (!this.wss || this.wss.clients.size === 0) {
157
- return undefined;
158
- }
159
- let chromeLevel;
160
- switch (method) {
161
- case 'debug':
162
- chromeLevel = 'verbose';
163
- break;
164
- case 'warn':
165
- chromeLevel = 'warning';
166
- break;
167
- default:
168
- chromeLevel = method;
169
- }
170
- const message = {
171
- method: 'Runtime.consoleAPICalled',
172
- params: {
173
- type: chromeLevel,
174
- timestamp: Date.now(),
175
- args: args.map(processArgForLogConsole)
176
- }
177
- };
178
- this.sendMessageToFrontend(JSON.stringify(message));
179
- }
180
- getWebsocketPort() {
181
- const wss = this.wss;
182
- if (!wss) {
183
- throw Error('Inspector server not started');
184
- }
185
- const address = wss.address();
186
- if (address && address.port) {
187
- return address.port;
188
- }
189
- else {
190
- throw Error('Unable to find port for inspector server');
191
- }
192
- }
193
- sendMessageToFrontend = (message) => {
194
- const wss = this.wss;
195
- if (!wss) {
196
- return;
197
- }
198
- if (VERBOSE_LOG) {
199
- log('Message to frontend:\n' + message);
200
- }
201
- wss.clients.forEach((ws) => ws.send(message));
202
- };
203
- stopSession = () => {
204
- const wss = this.wss;
205
- if (!wss) {
206
- return;
207
- }
208
- if (CLOSE_CONNECTION_ON_SESSION_STOP) {
209
- wss.clients.forEach((ws) => ws.close());
210
- }
211
- const callbacks = this.callbacks;
212
- if (!callbacks) {
213
- return;
214
- }
215
- this.callbacks = undefined;
216
- callbacks.onSessionStop();
217
- };
218
- forceResetFrontendState() {
219
- for (const evt of ChromeInspector.FORCE_RESET_FRONTEND_STATE_EVENTS) {
220
- this.sendMessageToFrontend(evt);
221
- }
222
- }
223
- addMessageForNewSandbox(message, inspecting) {
224
- const shouldAdd = isMessageForNewSandbox(message);
225
- if (shouldAdd) {
226
- this.frontendMsgsForNewSandbox.push(message);
227
- }
228
- if (VERBOSE_LOG) {
229
- log(`Message from frontend, inspecting = ${inspecting}, added for new sandbox = ${shouldAdd}:\n${message}`);
230
- }
231
- }
232
- deliverMessagesForNewSandbox() {
233
- const callbacks = this.callbacks;
234
- if (!callbacks) {
235
- return;
236
- }
237
- if (VERBOSE_LOG) {
238
- log('Messages for new sandbox', this.frontendMsgsForNewSandbox);
239
- }
240
- for (const msg of this.frontendMsgsForNewSandbox) {
241
- callbacks.onMessageFromFrontend(msg);
242
- }
243
- }
244
- }
245
- exports.ChromeInspector = ChromeInspector;
246
- exports.notImplementedInspector = {
247
- startServer: () => {
248
- throw new Error('Not implemented');
249
- },
250
- stopServer: async () => void 0,
251
- isServerStopped: () => true,
252
- startSession: () => {
253
- throw new Error('Not implemented');
254
- },
255
- logConsole: () => {
256
- throw new Error('Not implemented');
257
- }
258
- };