@omen.foundation/node-microservice-runtime 0.1.33 → 0.1.35
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/dist/collector-manager.d.ts.map +1 -1
- package/dist/collector-manager.js +60 -5
- package/dist/collector-manager.js.map +1 -1
- package/package.json +1 -1
- package/src/collector-manager.ts +59 -5
- package/dist/auth.cjs +0 -97
- package/dist/collector-manager.cjs +0 -384
- package/dist/decorators.cjs +0 -181
- package/dist/dependency.cjs +0 -165
- package/dist/dev.cjs +0 -34
- package/dist/discovery.cjs +0 -79
- package/dist/docs.cjs +0 -206
- package/dist/env.cjs +0 -125
- package/dist/errors.cjs +0 -58
- package/dist/federation.cjs +0 -356
- package/dist/index.cjs +0 -48
- package/dist/inventory.cjs +0 -361
- package/dist/logger.cjs +0 -482
- package/dist/message.cjs +0 -19
- package/dist/requester.cjs +0 -100
- package/dist/routing.cjs +0 -39
- package/dist/runtime.cjs +0 -759
- package/dist/services.cjs +0 -346
- package/dist/storage.cjs +0 -147
- package/dist/types.cjs +0 -2
- package/dist/utils/urls.cjs +0 -55
- package/dist/websocket.cjs +0 -142
package/dist/dependency.cjs
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BEAMABLE_SERVICES_TOKEN = exports.REQUEST_CONTEXT_TOKEN = exports.ENVIRONMENT_CONFIG_TOKEN = exports.LOGGER_TOKEN = exports.ServiceProvider = exports.DependencyBuilder = exports.ServiceLifetime = void 0;
|
|
4
|
-
require("reflect-metadata");
|
|
5
|
-
var ServiceLifetime;
|
|
6
|
-
(function (ServiceLifetime) {
|
|
7
|
-
ServiceLifetime["Singleton"] = "singleton";
|
|
8
|
-
ServiceLifetime["Scoped"] = "scoped";
|
|
9
|
-
ServiceLifetime["Transient"] = "transient";
|
|
10
|
-
})(ServiceLifetime || (exports.ServiceLifetime = ServiceLifetime = {}));
|
|
11
|
-
function isConstructor(key) {
|
|
12
|
-
return typeof key === 'function';
|
|
13
|
-
}
|
|
14
|
-
function instantiate(ctor, scope) {
|
|
15
|
-
var _a;
|
|
16
|
-
const paramTypes = (_a = Reflect.getMetadata('design:paramtypes', ctor)) !== null && _a !== void 0 ? _a : [];
|
|
17
|
-
if (paramTypes.length === 0) {
|
|
18
|
-
return new ctor();
|
|
19
|
-
}
|
|
20
|
-
const dependencies = paramTypes.map((param) => {
|
|
21
|
-
if (param === Object || param === Array || param === Promise) {
|
|
22
|
-
throw new Error(`Cannot resolve dependency '${param && param.name ? param.name : String(param)}' for ${ctor.name}. ` +
|
|
23
|
-
'Use ConfigureServices to register a factory explicitly.');
|
|
24
|
-
}
|
|
25
|
-
return scope.resolve(param);
|
|
26
|
-
});
|
|
27
|
-
return new ctor(...dependencies);
|
|
28
|
-
}
|
|
29
|
-
class DependencyBuilder {
|
|
30
|
-
constructor() {
|
|
31
|
-
this.descriptors = new Map();
|
|
32
|
-
}
|
|
33
|
-
addSingleton(key, factory) {
|
|
34
|
-
return this.addDescriptor(key, ServiceLifetime.Singleton, factory);
|
|
35
|
-
}
|
|
36
|
-
addSingletonClass(ctor) {
|
|
37
|
-
return this.addSingleton(ctor, (scope) => instantiate(ctor, scope));
|
|
38
|
-
}
|
|
39
|
-
addSingletonInstance(key, instance) {
|
|
40
|
-
return this.addSingleton(key, () => instance);
|
|
41
|
-
}
|
|
42
|
-
addScoped(key, factory) {
|
|
43
|
-
return this.addDescriptor(key, ServiceLifetime.Scoped, factory);
|
|
44
|
-
}
|
|
45
|
-
addScopedClass(ctor) {
|
|
46
|
-
return this.addScoped(ctor, (scope) => instantiate(ctor, scope));
|
|
47
|
-
}
|
|
48
|
-
addTransient(key, factory) {
|
|
49
|
-
return this.addDescriptor(key, ServiceLifetime.Transient, factory);
|
|
50
|
-
}
|
|
51
|
-
addTransientClass(ctor) {
|
|
52
|
-
return this.addTransient(ctor, (scope) => instantiate(ctor, scope));
|
|
53
|
-
}
|
|
54
|
-
tryAddSingleton(key, factory) {
|
|
55
|
-
if (!this.descriptors.has(key)) {
|
|
56
|
-
this.addSingleton(key, factory);
|
|
57
|
-
}
|
|
58
|
-
return this;
|
|
59
|
-
}
|
|
60
|
-
tryAddSingletonInstance(key, instance) {
|
|
61
|
-
if (!this.descriptors.has(key)) {
|
|
62
|
-
this.addSingletonInstance(key, instance);
|
|
63
|
-
}
|
|
64
|
-
return this;
|
|
65
|
-
}
|
|
66
|
-
build() {
|
|
67
|
-
return new ServiceProvider(this.descriptors);
|
|
68
|
-
}
|
|
69
|
-
addDescriptor(key, lifetime, factory) {
|
|
70
|
-
if (!key) {
|
|
71
|
-
throw new Error('Dependency registration requires a non-empty key.');
|
|
72
|
-
}
|
|
73
|
-
this.descriptors.set(key, { key, lifetime, factory });
|
|
74
|
-
return this;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
exports.DependencyBuilder = DependencyBuilder;
|
|
78
|
-
class ServiceProvider {
|
|
79
|
-
constructor(descriptors) {
|
|
80
|
-
this.singletons = new Map();
|
|
81
|
-
this.descriptors = new Map(descriptors);
|
|
82
|
-
}
|
|
83
|
-
resolve(key) {
|
|
84
|
-
const descriptor = this.descriptors.get(key);
|
|
85
|
-
if (!descriptor && isConstructor(key)) {
|
|
86
|
-
const implicitDescriptor = {
|
|
87
|
-
key,
|
|
88
|
-
lifetime: ServiceLifetime.Transient,
|
|
89
|
-
factory: (scope) => instantiate(key, scope),
|
|
90
|
-
};
|
|
91
|
-
this.descriptors.set(key, implicitDescriptor);
|
|
92
|
-
return this.resolve(key);
|
|
93
|
-
}
|
|
94
|
-
if (!descriptor) {
|
|
95
|
-
throw new Error(`No service registered for key '${typeof key === 'symbol' ? key.toString() : String(key)}'.`);
|
|
96
|
-
}
|
|
97
|
-
switch (descriptor.lifetime) {
|
|
98
|
-
case ServiceLifetime.Singleton: {
|
|
99
|
-
if (!this.singletons.has(descriptor.key)) {
|
|
100
|
-
const value = descriptor.factory(this);
|
|
101
|
-
this.singletons.set(descriptor.key, value);
|
|
102
|
-
}
|
|
103
|
-
return this.singletons.get(descriptor.key);
|
|
104
|
-
}
|
|
105
|
-
case ServiceLifetime.Scoped:
|
|
106
|
-
return descriptor.factory(this);
|
|
107
|
-
case ServiceLifetime.Transient:
|
|
108
|
-
default:
|
|
109
|
-
return descriptor.factory(this);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
createScope() {
|
|
113
|
-
return new ScopedServiceProvider(this.descriptors, this.singletons, this);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
exports.ServiceProvider = ServiceProvider;
|
|
117
|
-
class ScopedServiceProvider {
|
|
118
|
-
constructor(descriptors, rootSingletons, rootProvider) {
|
|
119
|
-
this.scopedInstances = new Map();
|
|
120
|
-
this.descriptors = descriptors;
|
|
121
|
-
this.rootSingletons = rootSingletons;
|
|
122
|
-
this.rootProvider = rootProvider;
|
|
123
|
-
}
|
|
124
|
-
resolve(key) {
|
|
125
|
-
const descriptor = this.descriptors.get(key);
|
|
126
|
-
if (!descriptor && isConstructor(key)) {
|
|
127
|
-
const implicitDescriptor = {
|
|
128
|
-
key,
|
|
129
|
-
lifetime: ServiceLifetime.Transient,
|
|
130
|
-
factory: (scope) => instantiate(key, scope),
|
|
131
|
-
};
|
|
132
|
-
this.descriptors.set(key, implicitDescriptor);
|
|
133
|
-
return this.resolve(key);
|
|
134
|
-
}
|
|
135
|
-
if (!descriptor) {
|
|
136
|
-
throw new Error(`No service registered for key '${typeof key === 'symbol' ? key.toString() : String(key)}'.`);
|
|
137
|
-
}
|
|
138
|
-
switch (descriptor.lifetime) {
|
|
139
|
-
case ServiceLifetime.Singleton: {
|
|
140
|
-
if (!this.rootSingletons.has(descriptor.key)) {
|
|
141
|
-
const value = descriptor.factory(this.rootProvider);
|
|
142
|
-
this.rootSingletons.set(descriptor.key, value);
|
|
143
|
-
}
|
|
144
|
-
return this.rootSingletons.get(descriptor.key);
|
|
145
|
-
}
|
|
146
|
-
case ServiceLifetime.Scoped: {
|
|
147
|
-
if (!this.scopedInstances.has(descriptor.key)) {
|
|
148
|
-
const value = descriptor.factory(this);
|
|
149
|
-
this.scopedInstances.set(descriptor.key, value);
|
|
150
|
-
}
|
|
151
|
-
return this.scopedInstances.get(descriptor.key);
|
|
152
|
-
}
|
|
153
|
-
case ServiceLifetime.Transient:
|
|
154
|
-
default:
|
|
155
|
-
return descriptor.factory(this);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
setInstance(key, value) {
|
|
159
|
-
this.scopedInstances.set(key, value);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
exports.LOGGER_TOKEN = Symbol('beamable:logger');
|
|
163
|
-
exports.ENVIRONMENT_CONFIG_TOKEN = Symbol('beamable:environment');
|
|
164
|
-
exports.REQUEST_CONTEXT_TOKEN = Symbol('beamable:requestContext');
|
|
165
|
-
exports.BEAMABLE_SERVICES_TOKEN = Symbol('beamable:services');
|
package/dist/dev.cjs
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.ExampleService = void 0;
|
|
13
|
-
require("dotenv/config");
|
|
14
|
-
const decorators_js_1 = require("./decorators.js");
|
|
15
|
-
const runtime_js_1 = require("./runtime.js");
|
|
16
|
-
let ExampleService = class ExampleService {
|
|
17
|
-
async echo(ctx, message) {
|
|
18
|
-
return {
|
|
19
|
-
message,
|
|
20
|
-
playerId: ctx.userId,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
exports.ExampleService = ExampleService;
|
|
25
|
-
__decorate([
|
|
26
|
-
(0, decorators_js_1.Callable)(),
|
|
27
|
-
__metadata("design:type", Function),
|
|
28
|
-
__metadata("design:paramtypes", [Object, String]),
|
|
29
|
-
__metadata("design:returntype", Promise)
|
|
30
|
-
], ExampleService.prototype, "echo", null);
|
|
31
|
-
exports.ExampleService = ExampleService = __decorate([
|
|
32
|
-
(0, decorators_js_1.Microservice)('ExampleNodeService')
|
|
33
|
-
], ExampleService);
|
|
34
|
-
void (0, runtime_js_1.runMicroservice)();
|
package/dist/discovery.cjs
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.DiscoveryBroadcaster = void 0;
|
|
7
|
-
const node_dgram_1 = __importDefault(require("node:dgram"));
|
|
8
|
-
const DISCOVERY_PORT = 8624;
|
|
9
|
-
const BROADCAST_PERIOD_MS = 10;
|
|
10
|
-
class DiscoveryBroadcaster {
|
|
11
|
-
constructor(options) {
|
|
12
|
-
var _a;
|
|
13
|
-
this.options = options;
|
|
14
|
-
this.socket = node_dgram_1.default.createSocket('udp4');
|
|
15
|
-
this.disposed = false;
|
|
16
|
-
const message = {
|
|
17
|
-
processId: process.pid,
|
|
18
|
-
cid: options.env.cid,
|
|
19
|
-
pid: options.env.pid,
|
|
20
|
-
prefix: options.routingKey,
|
|
21
|
-
serviceName: options.serviceName,
|
|
22
|
-
healthPort: options.env.healthPort,
|
|
23
|
-
serviceType: 'service',
|
|
24
|
-
startedByAccountId: (_a = options.env.accountId) !== null && _a !== void 0 ? _a : 0,
|
|
25
|
-
isContainer: false,
|
|
26
|
-
dataPort: 0,
|
|
27
|
-
containerId: '',
|
|
28
|
-
};
|
|
29
|
-
this.payload = Buffer.from(JSON.stringify(message), 'utf8');
|
|
30
|
-
this.socket.on('error', (err) => {
|
|
31
|
-
options.logger.warn({ err }, 'Discovery broadcaster socket error.');
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
async start() {
|
|
35
|
-
if (this.disposed) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
await new Promise((resolve, reject) => {
|
|
39
|
-
const onError = (error) => {
|
|
40
|
-
this.socket.off('error', onError);
|
|
41
|
-
reject(error);
|
|
42
|
-
};
|
|
43
|
-
this.socket.once('error', onError);
|
|
44
|
-
this.socket.bind(0, undefined, () => {
|
|
45
|
-
try {
|
|
46
|
-
this.socket.setBroadcast(true);
|
|
47
|
-
this.socket.off('error', onError);
|
|
48
|
-
resolve();
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
this.socket.off('error', onError);
|
|
52
|
-
reject(error);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
this.interval = setInterval(() => {
|
|
57
|
-
this.socket.send(this.payload, DISCOVERY_PORT, '255.255.255.255', (error) => {
|
|
58
|
-
if (error) {
|
|
59
|
-
this.options.logger.debug({ err: error }, 'Discovery broadcast send failed.');
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}, BROADCAST_PERIOD_MS);
|
|
63
|
-
this.interval.unref();
|
|
64
|
-
}
|
|
65
|
-
stop() {
|
|
66
|
-
this.disposed = true;
|
|
67
|
-
if (this.interval) {
|
|
68
|
-
clearInterval(this.interval);
|
|
69
|
-
this.interval = undefined;
|
|
70
|
-
}
|
|
71
|
-
try {
|
|
72
|
-
this.socket.close();
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
this.options.logger.debug({ err: error }, 'Error closing discovery broadcaster socket.');
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
exports.DiscoveryBroadcaster = DiscoveryBroadcaster;
|
package/dist/docs.cjs
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateOpenApiDocument = generateOpenApiDocument;
|
|
4
|
-
const urls_js_1 = require("./utils/urls.js");
|
|
5
|
-
const JSON_CONTENT_TYPE = 'application/json';
|
|
6
|
-
const ADMIN_TAG = 'Administration';
|
|
7
|
-
const SCOPE_SECURITY_SCHEME = {
|
|
8
|
-
type: 'apiKey',
|
|
9
|
-
name: 'X-DE-SCOPE',
|
|
10
|
-
in: 'header',
|
|
11
|
-
description: "Customer and project scope. This should contain the '<customer-id>.<project-id>'. Required for all microservice calls.",
|
|
12
|
-
};
|
|
13
|
-
const BEAM_SCOPE_SECURITY_SCHEME = {
|
|
14
|
-
type: 'apiKey',
|
|
15
|
-
name: 'X-BEAM-SCOPE',
|
|
16
|
-
in: 'header',
|
|
17
|
-
description: "Customer and project scope. This should contain the '<customer-id>.<project-id>'. Required for all microservice calls. Alternative to X-DE-SCOPE.",
|
|
18
|
-
};
|
|
19
|
-
const USER_SECURITY_SCHEME = {
|
|
20
|
-
type: 'http',
|
|
21
|
-
scheme: 'bearer',
|
|
22
|
-
bearerFormat: 'Bearer <Access Token>',
|
|
23
|
-
description: 'Bearer authentication with a player access token in the Authorization header.',
|
|
24
|
-
};
|
|
25
|
-
function generateOpenApiDocument(service, env) {
|
|
26
|
-
const serverBase = buildServiceBaseUrl(env, service);
|
|
27
|
-
const doc = {
|
|
28
|
-
openapi: '3.0.1',
|
|
29
|
-
info: {
|
|
30
|
-
title: service.name,
|
|
31
|
-
version: '0.0.0',
|
|
32
|
-
},
|
|
33
|
-
servers: serverBase ? [{ url: serverBase }] : [],
|
|
34
|
-
paths: {},
|
|
35
|
-
components: {
|
|
36
|
-
securitySchemes: {
|
|
37
|
-
scope: SCOPE_SECURITY_SCHEME,
|
|
38
|
-
beamScope: BEAM_SCOPE_SECURITY_SCHEME,
|
|
39
|
-
user: USER_SECURITY_SCHEME,
|
|
40
|
-
},
|
|
41
|
-
schemas: {},
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
for (const callable of service.callables) {
|
|
45
|
-
const normalizedRoute = normalizeRoute(callable.route);
|
|
46
|
-
const pathKey = `/${normalizedRoute}`;
|
|
47
|
-
const payload = buildRequestSchema(callable.handler);
|
|
48
|
-
const securityEntry = { scope: [], beamScope: [] };
|
|
49
|
-
if (callable.metadata.requireAuth) {
|
|
50
|
-
securityEntry.user = [];
|
|
51
|
-
}
|
|
52
|
-
const operation = {
|
|
53
|
-
operationId: callable.name,
|
|
54
|
-
summary: callable.name,
|
|
55
|
-
tags: callable.metadata.tags.length > 0 ? callable.metadata.tags : ['Callables'],
|
|
56
|
-
responses: {
|
|
57
|
-
'200': {
|
|
58
|
-
description: 'Success',
|
|
59
|
-
content: {
|
|
60
|
-
[JSON_CONTENT_TYPE]: {
|
|
61
|
-
schema: {
|
|
62
|
-
oneOf: [{ type: 'object' }, { type: 'array' }, { type: 'string' }, { type: 'number' }, { type: 'boolean' }, { type: 'null' }],
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
security: [securityEntry],
|
|
69
|
-
'x-beamable-access': callable.metadata.access,
|
|
70
|
-
};
|
|
71
|
-
if (callable.metadata.requiredScopes.length > 0) {
|
|
72
|
-
operation['x-beamable-required-scopes'] = callable.metadata.requiredScopes;
|
|
73
|
-
}
|
|
74
|
-
if (payload) {
|
|
75
|
-
operation.requestBody = {
|
|
76
|
-
required: payload.required,
|
|
77
|
-
content: {
|
|
78
|
-
[JSON_CONTENT_TYPE]: {
|
|
79
|
-
schema: payload.schema,
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
doc.paths[pathKey] = {
|
|
85
|
-
post: operation,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
addAdminOperations(doc);
|
|
89
|
-
return JSON.parse(JSON.stringify(doc));
|
|
90
|
-
}
|
|
91
|
-
function buildRequestSchema(handler) {
|
|
92
|
-
if (typeof handler !== 'function') {
|
|
93
|
-
return {
|
|
94
|
-
required: false,
|
|
95
|
-
schema: {
|
|
96
|
-
type: 'object',
|
|
97
|
-
properties: {
|
|
98
|
-
payload: {
|
|
99
|
-
type: 'array',
|
|
100
|
-
description: 'Callable arguments in invocation order.',
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
additionalProperties: false,
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
const expectedParams = handler.length;
|
|
108
|
-
const payloadCount = Math.max(expectedParams - 1, 0);
|
|
109
|
-
if (payloadCount <= 0) {
|
|
110
|
-
return undefined;
|
|
111
|
-
}
|
|
112
|
-
return {
|
|
113
|
-
required: true,
|
|
114
|
-
schema: {
|
|
115
|
-
type: 'object',
|
|
116
|
-
properties: {
|
|
117
|
-
payload: {
|
|
118
|
-
type: 'array',
|
|
119
|
-
minItems: payloadCount,
|
|
120
|
-
description: 'Callable arguments in invocation order.',
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
required: ['payload'],
|
|
124
|
-
additionalProperties: false,
|
|
125
|
-
},
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
function buildServiceBaseUrl(env, service) {
|
|
129
|
-
const host = (0, urls_js_1.hostToHttpUrl)(env.host).replace(/\/$/, '');
|
|
130
|
-
return `${host}/basic/${env.cid}.${env.pid}.${service.qualifiedName}/`;
|
|
131
|
-
}
|
|
132
|
-
function normalizeRoute(route) {
|
|
133
|
-
if (!route) {
|
|
134
|
-
return '';
|
|
135
|
-
}
|
|
136
|
-
return route.replace(/^\/+/, '');
|
|
137
|
-
}
|
|
138
|
-
function addAdminOperations(doc) {
|
|
139
|
-
const requiredScopeSecurity = { scope: [], beamScope: [] };
|
|
140
|
-
doc.paths['/admin/HealthCheck'] = {
|
|
141
|
-
post: {
|
|
142
|
-
operationId: 'adminHealthCheck',
|
|
143
|
-
summary: 'HealthCheck',
|
|
144
|
-
tags: [ADMIN_TAG],
|
|
145
|
-
responses: {
|
|
146
|
-
'200': {
|
|
147
|
-
description: 'The word "responsive" if all is well.',
|
|
148
|
-
content: {
|
|
149
|
-
[JSON_CONTENT_TYPE]: {
|
|
150
|
-
schema: {
|
|
151
|
-
type: 'string',
|
|
152
|
-
example: 'responsive',
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
security: [requiredScopeSecurity],
|
|
159
|
-
},
|
|
160
|
-
};
|
|
161
|
-
const adminSecurity = { scope: ['admin'], beamScope: ['admin'] };
|
|
162
|
-
doc.paths['/admin/Docs'] = {
|
|
163
|
-
post: {
|
|
164
|
-
operationId: 'adminDocs',
|
|
165
|
-
summary: 'Docs',
|
|
166
|
-
description: 'Generates an OpenAPI/Swagger 3.0 document that describes the available service endpoints.',
|
|
167
|
-
tags: [ADMIN_TAG],
|
|
168
|
-
responses: {
|
|
169
|
-
'200': {
|
|
170
|
-
description: 'Swagger JSON document.',
|
|
171
|
-
content: {
|
|
172
|
-
[JSON_CONTENT_TYPE]: {
|
|
173
|
-
schema: {
|
|
174
|
-
type: 'object',
|
|
175
|
-
},
|
|
176
|
-
},
|
|
177
|
-
},
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
security: [adminSecurity],
|
|
181
|
-
'x-beamable-required-scopes': ['admin'],
|
|
182
|
-
},
|
|
183
|
-
};
|
|
184
|
-
doc.paths['/admin/Metadata'] = {
|
|
185
|
-
post: {
|
|
186
|
-
operationId: 'adminMetadata',
|
|
187
|
-
summary: 'Metadata',
|
|
188
|
-
description: 'Fetch various Beamable SDK metadata for the Microservice.',
|
|
189
|
-
tags: [ADMIN_TAG],
|
|
190
|
-
responses: {
|
|
191
|
-
'200': {
|
|
192
|
-
description: 'Service metadata.',
|
|
193
|
-
content: {
|
|
194
|
-
[JSON_CONTENT_TYPE]: {
|
|
195
|
-
schema: {
|
|
196
|
-
type: 'object',
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
},
|
|
201
|
-
},
|
|
202
|
-
security: [adminSecurity],
|
|
203
|
-
'x-beamable-required-scopes': ['admin'],
|
|
204
|
-
},
|
|
205
|
-
};
|
|
206
|
-
}
|
package/dist/env.cjs
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadEnvironmentConfig = loadEnvironmentConfig;
|
|
4
|
-
exports.ensureWritableTempDirectory = ensureWritableTempDirectory;
|
|
5
|
-
const node_fs_1 = require("node:fs");
|
|
6
|
-
const node_os_1 = require("node:os");
|
|
7
|
-
const node_path_1 = require("node:path");
|
|
8
|
-
const routing_js_1 = require("./routing.js");
|
|
9
|
-
function getBoolean(name, defaultValue = false) {
|
|
10
|
-
const raw = process.env[name];
|
|
11
|
-
if (!raw) {
|
|
12
|
-
return defaultValue;
|
|
13
|
-
}
|
|
14
|
-
return ['1', 'true', 'yes', 'on'].includes(raw.toLowerCase());
|
|
15
|
-
}
|
|
16
|
-
function getNumber(name, defaultValue) {
|
|
17
|
-
const raw = process.env[name];
|
|
18
|
-
if (!raw) {
|
|
19
|
-
return defaultValue;
|
|
20
|
-
}
|
|
21
|
-
const parsed = Number(raw);
|
|
22
|
-
return Number.isFinite(parsed) ? parsed : defaultValue;
|
|
23
|
-
}
|
|
24
|
-
function resolveHealthPort() {
|
|
25
|
-
const preferred = getNumber('HEALTH_PORT', 6565);
|
|
26
|
-
if (preferred > 0) {
|
|
27
|
-
return preferred;
|
|
28
|
-
}
|
|
29
|
-
const base = 45000;
|
|
30
|
-
const span = 2000;
|
|
31
|
-
const candidate = base + (process.pid % span);
|
|
32
|
-
return candidate;
|
|
33
|
-
}
|
|
34
|
-
function isInContainer() {
|
|
35
|
-
try {
|
|
36
|
-
const fs = require('fs');
|
|
37
|
-
if (fs.existsSync('/.dockerenv')) {
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
}
|
|
43
|
-
const hostname = process.env.HOSTNAME || '';
|
|
44
|
-
if (hostname && /^[a-f0-9]{12}$/i.test(hostname)) {
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
if (process.env.DOTNET_RUNNING_IN_CONTAINER === 'true' ||
|
|
48
|
-
process.env.CONTAINER === 'beamable' ||
|
|
49
|
-
!!process.env.ECS_CONTAINER_METADATA_URI ||
|
|
50
|
-
!!process.env.KUBERNETES_SERVICE_HOST) {
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
function resolveRoutingKey() {
|
|
56
|
-
var _a;
|
|
57
|
-
const raw = (_a = process.env.NAME_PREFIX) !== null && _a !== void 0 ? _a : process.env.ROUTING_KEY;
|
|
58
|
-
if (raw && raw.trim().length > 0) {
|
|
59
|
-
return raw.trim();
|
|
60
|
-
}
|
|
61
|
-
if (isInContainer()) {
|
|
62
|
-
return undefined;
|
|
63
|
-
}
|
|
64
|
-
try {
|
|
65
|
-
return (0, routing_js_1.getDefaultRoutingKeyForMachine)();
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
throw new Error(`Unable to determine routing key automatically. Set NAME_PREFIX environment variable. ${error.message}`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
function resolveSdkVersionExecution() {
|
|
72
|
-
var _a;
|
|
73
|
-
return (_a = process.env.BEAMABLE_SDK_VERSION_EXECUTION) !== null && _a !== void 0 ? _a : '';
|
|
74
|
-
}
|
|
75
|
-
function resolveLogLevel() {
|
|
76
|
-
var _a;
|
|
77
|
-
const candidate = (_a = process.env.LOG_LEVEL) !== null && _a !== void 0 ? _a : 'info';
|
|
78
|
-
const allowed = new Set(['fatal', 'error', 'warn', 'info', 'debug', 'trace']);
|
|
79
|
-
return allowed.has(candidate.toLowerCase()) ? candidate.toLowerCase() : 'info';
|
|
80
|
-
}
|
|
81
|
-
function resolveWatchToken() {
|
|
82
|
-
const value = process.env.WATCH_TOKEN;
|
|
83
|
-
if (value === undefined) {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
return getBoolean('WATCH_TOKEN', false);
|
|
87
|
-
}
|
|
88
|
-
function resolveBeamInstanceCount() {
|
|
89
|
-
return getNumber('BEAM_INSTANCE_COUNT', 1);
|
|
90
|
-
}
|
|
91
|
-
function loadEnvironmentConfig() {
|
|
92
|
-
var _a, _b, _c, _d, _e, _f;
|
|
93
|
-
const cid = (_a = process.env.CID) !== null && _a !== void 0 ? _a : '';
|
|
94
|
-
const pid = (_b = process.env.PID) !== null && _b !== void 0 ? _b : '';
|
|
95
|
-
const host = (_c = process.env.HOST) !== null && _c !== void 0 ? _c : '';
|
|
96
|
-
if (!cid || !pid || !host) {
|
|
97
|
-
throw new Error('Missing required Beamable environment variables (CID, PID, HOST).');
|
|
98
|
-
}
|
|
99
|
-
const config = {
|
|
100
|
-
cid,
|
|
101
|
-
pid,
|
|
102
|
-
host,
|
|
103
|
-
secret: (_d = process.env.SECRET) !== null && _d !== void 0 ? _d : undefined,
|
|
104
|
-
refreshToken: (_e = process.env.REFRESH_TOKEN) !== null && _e !== void 0 ? _e : undefined,
|
|
105
|
-
routingKey: resolveRoutingKey(),
|
|
106
|
-
accountId: getNumber('USER_ACCOUNT_ID', 0) || undefined,
|
|
107
|
-
accountEmail: (_f = process.env.USER_EMAIL) !== null && _f !== void 0 ? _f : undefined,
|
|
108
|
-
logLevel: resolveLogLevel(),
|
|
109
|
-
healthPort: resolveHealthPort(),
|
|
110
|
-
disableCustomInitializationHooks: getBoolean('DISABLE_CUSTOM_INITIALIZATION_HOOKS', false),
|
|
111
|
-
watchToken: resolveWatchToken(),
|
|
112
|
-
sdkVersionExecution: resolveSdkVersionExecution(),
|
|
113
|
-
beamInstanceCount: resolveBeamInstanceCount(),
|
|
114
|
-
logTruncateLimit: getNumber('LOG_TRUNCATE_LIMIT', 1000),
|
|
115
|
-
};
|
|
116
|
-
return config;
|
|
117
|
-
}
|
|
118
|
-
function ensureWritableTempDirectory() {
|
|
119
|
-
var _a;
|
|
120
|
-
const candidate = (_a = process.env.LOG_PATH) !== null && _a !== void 0 ? _a : (0, node_path_1.join)((0, node_os_1.tmpdir)(), 'beamable-node-runtime');
|
|
121
|
-
if (!(0, node_fs_1.existsSync)(candidate)) {
|
|
122
|
-
return candidate;
|
|
123
|
-
}
|
|
124
|
-
return candidate;
|
|
125
|
-
}
|
package/dist/errors.cjs
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InvalidConfigurationError = exports.SerializationError = exports.UnknownRouteError = exports.UnauthorizedUserError = exports.MissingScopesError = exports.TimeoutError = exports.AuthenticationError = exports.BeamableRuntimeError = void 0;
|
|
4
|
-
class BeamableRuntimeError extends Error {
|
|
5
|
-
constructor(code, message, cause) {
|
|
6
|
-
var _a;
|
|
7
|
-
super(message);
|
|
8
|
-
this.code = code;
|
|
9
|
-
if (cause !== undefined) {
|
|
10
|
-
this.cause = cause;
|
|
11
|
-
}
|
|
12
|
-
this.name = this.constructor.name;
|
|
13
|
-
(_a = Error.captureStackTrace) === null || _a === void 0 ? void 0 : _a.call(Error, this, this.constructor);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.BeamableRuntimeError = BeamableRuntimeError;
|
|
17
|
-
class AuthenticationError extends BeamableRuntimeError {
|
|
18
|
-
constructor(message, cause) {
|
|
19
|
-
super('AUTHENTICATION_FAILED', message, cause);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.AuthenticationError = AuthenticationError;
|
|
23
|
-
class TimeoutError extends BeamableRuntimeError {
|
|
24
|
-
constructor(message, cause) {
|
|
25
|
-
super('TIMEOUT', message, cause);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.TimeoutError = TimeoutError;
|
|
29
|
-
class MissingScopesError extends BeamableRuntimeError {
|
|
30
|
-
constructor(requiredScopes) {
|
|
31
|
-
super('MISSING_SCOPES', `Missing required scopes: ${Array.from(requiredScopes).join(', ')}`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.MissingScopesError = MissingScopesError;
|
|
35
|
-
class UnauthorizedUserError extends BeamableRuntimeError {
|
|
36
|
-
constructor(route) {
|
|
37
|
-
super('UNAUTHORIZED_USER', `Route "${route}" requires an authenticated user.`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.UnauthorizedUserError = UnauthorizedUserError;
|
|
41
|
-
class UnknownRouteError extends BeamableRuntimeError {
|
|
42
|
-
constructor(route) {
|
|
43
|
-
super('UNKNOWN_ROUTE', `No callable registered for route "${route}".`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
exports.UnknownRouteError = UnknownRouteError;
|
|
47
|
-
class SerializationError extends BeamableRuntimeError {
|
|
48
|
-
constructor(message, cause) {
|
|
49
|
-
super('SERIALIZATION_ERROR', message, cause);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.SerializationError = SerializationError;
|
|
53
|
-
class InvalidConfigurationError extends BeamableRuntimeError {
|
|
54
|
-
constructor(message, cause) {
|
|
55
|
-
super('INVALID_CONFIGURATION', message, cause);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.InvalidConfigurationError = InvalidConfigurationError;
|