nestjs-ddd-cli 3.2.2 → 3.3.1
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/README.md +118 -9
- package/ddd.schema.json +11 -1
- package/dist/commands/doctor-enhanced.d.ts +1 -0
- package/dist/commands/doctor-enhanced.js +94 -79
- package/dist/commands/doctor-enhanced.js.map +1 -1
- package/dist/commands/doctor.d.ts +9 -0
- package/dist/commands/doctor.js +68 -21
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/generate-all.js +54 -28
- package/dist/commands/generate-all.js.map +1 -1
- package/dist/commands/generate-controller.d.ts +1 -0
- package/dist/commands/generate-controller.js +71 -0
- package/dist/commands/generate-controller.js.map +1 -0
- package/dist/commands/generate-domain-service.d.ts +1 -1
- package/dist/commands/generate-domain-service.js +6 -4
- package/dist/commands/generate-domain-service.js.map +1 -1
- package/dist/commands/generate-dto.d.ts +4 -0
- package/dist/commands/generate-dto.js +162 -0
- package/dist/commands/generate-dto.js.map +1 -0
- package/dist/commands/generate-entity.js +7 -2
- package/dist/commands/generate-entity.js.map +1 -1
- package/dist/commands/generate-event.js +10 -4
- package/dist/commands/generate-event.js.map +1 -1
- package/dist/commands/generate-migration-deployment.d.ts +15 -0
- package/dist/commands/generate-migration-deployment.js +326 -0
- package/dist/commands/generate-migration-deployment.js.map +1 -0
- package/dist/commands/generate-migration-deployment.spec.d.ts +1 -0
- package/dist/commands/generate-migration-deployment.spec.js +337 -0
- package/dist/commands/generate-migration-deployment.spec.js.map +1 -0
- package/dist/commands/generate-module.js +4 -2
- package/dist/commands/generate-module.js.map +1 -1
- package/dist/commands/generate-query.js +23 -4
- package/dist/commands/generate-query.js.map +1 -1
- package/dist/commands/generate-repository.d.ts +1 -1
- package/dist/commands/generate-repository.js +17 -34
- package/dist/commands/generate-repository.js.map +1 -1
- package/dist/commands/generate-service.js +19 -4
- package/dist/commands/generate-service.js.map +1 -1
- package/dist/commands/generate-usecase.js +12 -31
- package/dist/commands/generate-usecase.js.map +1 -1
- package/dist/commands/generate-value-object.js +3 -14
- package/dist/commands/generate-value-object.js.map +1 -1
- package/dist/commands/init-project.d.ts +3 -0
- package/dist/commands/init-project.js +19 -9
- package/dist/commands/init-project.js.map +1 -1
- package/dist/commands/interactive-scaffold.js +10 -0
- package/dist/commands/interactive-scaffold.js.map +1 -1
- package/dist/commands/migration.d.ts +3 -0
- package/dist/commands/migration.js +83 -48
- package/dist/commands/migration.js.map +1 -1
- package/dist/commands/recipe.d.ts +2 -0
- package/dist/commands/recipe.js +229 -85
- package/dist/commands/recipe.js.map +1 -1
- package/dist/commands/recipes/banklink-connector-contract.recipe.d.ts +1 -0
- package/dist/commands/recipes/banklink-connector-contract.recipe.js +161 -0
- package/dist/commands/recipes/banklink-connector-contract.recipe.js.map +1 -0
- package/dist/commands/recipes/bounded-json-http.recipe.d.ts +2 -0
- package/dist/commands/recipes/bounded-json-http.recipe.js +53 -0
- package/dist/commands/recipes/bounded-json-http.recipe.js.map +1 -0
- package/dist/commands/recipes/business-reference-identifiers.recipe.d.ts +1 -0
- package/dist/commands/recipes/business-reference-identifiers.recipe.js +223 -0
- package/dist/commands/recipes/business-reference-identifiers.recipe.js.map +1 -0
- package/dist/commands/recipes/event-backbone.recipe.d.ts +1 -0
- package/dist/commands/recipes/event-backbone.recipe.js +1118 -0
- package/dist/commands/recipes/event-backbone.recipe.js.map +1 -0
- package/dist/commands/recipes/external-projection-worker.recipe.d.ts +6 -0
- package/dist/commands/recipes/external-projection-worker.recipe.js +211 -0
- package/dist/commands/recipes/external-projection-worker.recipe.js.map +1 -0
- package/dist/commands/recipes/index.d.ts +11 -0
- package/dist/commands/recipes/index.js +11 -0
- package/dist/commands/recipes/index.js.map +1 -1
- package/dist/commands/recipes/jest-cjs-compat.recipe.d.ts +3 -0
- package/dist/commands/recipes/jest-cjs-compat.recipe.js +130 -0
- package/dist/commands/recipes/jest-cjs-compat.recipe.js.map +1 -0
- package/dist/commands/recipes/joi-env.recipe.js +1 -1
- package/dist/commands/recipes/kafka-consumer.recipe.d.ts +1 -0
- package/dist/commands/recipes/kafka-consumer.recipe.js +65 -0
- package/dist/commands/recipes/kafka-consumer.recipe.js.map +1 -0
- package/dist/commands/recipes/oauth2-client-credentials.recipe.d.ts +1 -0
- package/dist/commands/recipes/oauth2-client-credentials.recipe.js +60 -0
- package/dist/commands/recipes/oauth2-client-credentials.recipe.js.map +1 -0
- package/dist/commands/recipes/oauth2-token-introspection.recipe.d.ts +1 -0
- package/dist/commands/recipes/oauth2-token-introspection.recipe.js +67 -0
- package/dist/commands/recipes/oauth2-token-introspection.recipe.js.map +1 -0
- package/dist/commands/recipes/oidc-bff-session.recipe.d.ts +1 -0
- package/dist/commands/recipes/oidc-bff-session.recipe.js +57 -0
- package/dist/commands/recipes/oidc-bff-session.recipe.js.map +1 -0
- package/dist/commands/recipes/oidc-dashboard.recipe.d.ts +1 -0
- package/dist/commands/recipes/oidc-dashboard.recipe.js +463 -0
- package/dist/commands/recipes/oidc-dashboard.recipe.js.map +1 -0
- package/dist/commands/recipes/oidc-resource-server.recipe.d.ts +1 -0
- package/dist/commands/recipes/oidc-resource-server.recipe.js +85 -0
- package/dist/commands/recipes/oidc-resource-server.recipe.js.map +1 -0
- package/dist/commands/recipes/platform-context.recipe.d.ts +1 -0
- package/dist/commands/recipes/platform-context.recipe.js +229 -0
- package/dist/commands/recipes/platform-context.recipe.js.map +1 -0
- package/dist/commands/recipes/platform-parc-authorization.recipe.d.ts +1 -0
- package/dist/commands/recipes/platform-parc-authorization.recipe.js +339 -0
- package/dist/commands/recipes/platform-parc-authorization.recipe.js.map +1 -0
- package/dist/commands/recipes/platform-parc-bound-authorization.recipe.d.ts +1 -0
- package/dist/commands/recipes/platform-parc-bound-authorization.recipe.js +56 -0
- package/dist/commands/recipes/platform-parc-bound-authorization.recipe.js.map +1 -0
- package/dist/commands/recipes/platform-service-access-request-context.recipe.d.ts +1 -0
- package/dist/commands/recipes/platform-service-access-request-context.recipe.js +103 -0
- package/dist/commands/recipes/platform-service-access-request-context.recipe.js.map +1 -0
- package/dist/commands/recipes/platform-service-runtime.recipe.d.ts +1 -0
- package/dist/commands/recipes/platform-service-runtime.recipe.js +415 -0
- package/dist/commands/recipes/platform-service-runtime.recipe.js.map +1 -0
- package/dist/index.js +77 -9
- package/dist/index.js.map +1 -1
- package/dist/templates/ai-context/CLAUDE.md.hbs +39 -3
- package/dist/templates/ai-context/conventions.md.hbs +13 -8
- package/dist/templates/command/create-command.hbs +8 -3
- package/dist/templates/command/delete-command.hbs +1 -1
- package/dist/templates/command/update-command.hbs +1 -1
- package/dist/templates/controller/application-controller.hbs +7 -0
- package/dist/templates/controller/controller.hbs +6 -0
- package/dist/templates/dto/create-dto.hbs +17 -5
- package/dist/templates/dto/filter-dto.hbs +1 -1
- package/dist/templates/dto/response-dto.hbs +1 -1
- package/dist/templates/entity/entity.hbs +4 -0
- package/dist/templates/mapper/mapper.hbs +5 -1
- package/dist/templates/orm-entity/orm-entity.hbs +9 -1
- package/dist/templates/prisma/prisma-mapper.hbs +6 -0
- package/dist/templates/prisma/prisma-repository.hbs +57 -5
- package/dist/templates/prisma/prisma-schema.hbs +2 -0
- package/dist/templates/query/get-all.query.hbs +10 -2
- package/dist/templates/recipes/bounded-json-http/README.md.hbs +36 -0
- package/dist/templates/recipes/external-projection-worker/README.md.hbs +157 -0
- package/dist/templates/recipes/external-projection-worker/canonical-json.ts.hbs +123 -0
- package/dist/templates/recipes/external-projection-worker/enqueuer.ts.hbs +167 -0
- package/dist/templates/recipes/external-projection-worker/index.ts.hbs +6 -0
- package/dist/templates/recipes/external-projection-worker/migration.ts.hbs +88 -0
- package/dist/templates/recipes/external-projection-worker/module.ts.hbs +36 -0
- package/dist/templates/recipes/external-projection-worker/store.ts.hbs +354 -0
- package/dist/templates/recipes/external-projection-worker/types.ts.hbs +134 -0
- package/dist/templates/recipes/external-projection-worker/worker.ts.hbs +296 -0
- package/dist/templates/recipes/kafka-consumer/README.md.hbs +50 -0
- package/dist/templates/recipes/kafka-consumer/kafka-consumer.ts.hbs +135 -0
- package/dist/templates/recipes/kafka-consumer/migration.ts.hbs +17 -0
- package/dist/templates/recipes/oauth2-client-credentials/README.md.hbs +40 -0
- package/dist/templates/recipes/oauth2-client-credentials/client.spec.ts.hbs +234 -0
- package/dist/templates/recipes/oauth2-client-credentials/client.ts.hbs +210 -0
- package/dist/templates/recipes/oauth2-client-credentials/index.ts.hbs +2 -0
- package/dist/templates/recipes/oauth2-client-credentials/module.ts.hbs +58 -0
- package/dist/templates/recipes/oauth2-token-introspection/README.md.hbs +158 -0
- package/dist/templates/recipes/oauth2-token-introspection/client.spec.ts.hbs +350 -0
- package/dist/templates/recipes/oauth2-token-introspection/client.ts.hbs +241 -0
- package/dist/templates/recipes/oauth2-token-introspection/http-client.spec.ts.hbs +411 -0
- package/dist/templates/recipes/oauth2-token-introspection/http-client.ts.hbs +343 -0
- package/dist/templates/recipes/oauth2-token-introspection/index.ts.hbs +3 -0
- package/dist/templates/recipes/oauth2-token-introspection/module.ts.hbs +58 -0
- package/dist/templates/recipes/oidc-bff-session/README.md.hbs +96 -0
- package/dist/templates/recipes/oidc-bff-session/client.test.ts.hbs +663 -0
- package/dist/templates/recipes/oidc-bff-session/client.ts.hbs +635 -0
- package/dist/templates/recipes/oidc-bff-session/index.ts.hbs +3 -0
- package/dist/templates/recipes/oidc-bff-session/store.integration.test.ts.hbs +480 -0
- package/dist/templates/recipes/oidc-bff-session/store.test.ts.hbs +87 -0
- package/dist/templates/recipes/oidc-bff-session/store.ts.hbs +549 -0
- package/dist/templates/recipes/oidc-bff-session/valkey.test.ts.hbs +158 -0
- package/dist/templates/recipes/oidc-bff-session/valkey.ts.hbs +148 -0
- package/dist/templates/recipes/oidc-resource-server/README.md.hbs +74 -0
- package/dist/templates/recipes/oidc-resource-server/index.ts.hbs +2 -0
- package/dist/templates/recipes/oidc-resource-server/module.ts.hbs +51 -0
- package/dist/templates/recipes/oidc-resource-server/verifier.spec.ts.hbs +186 -0
- package/dist/templates/recipes/oidc-resource-server/verifier.ts.hbs +440 -0
- package/dist/templates/recipes/platform-parc-bound-authorization/README.md.hbs +92 -0
- package/dist/templates/recipes/platform-parc-bound-authorization/client.ts.hbs +142 -0
- package/dist/templates/recipes/platform-service-access-request-context/docs.md.hbs +61 -0
- package/dist/templates/recipes/platform-service-access-request-context/env.example.hbs +7 -0
- package/dist/templates/recipes/platform-service-access-request-context/index.ts.hbs +7 -0
- package/dist/templates/recipes/platform-service-access-request-context/request-context-headers.ts.hbs +61 -0
- package/dist/templates/recipes/platform-service-access-request-context/request-context-introspection.parser.ts.hbs +132 -0
- package/dist/templates/recipes/platform-service-access-request-context/request-context-introspection.types.ts.hbs +40 -0
- package/dist/templates/recipes/platform-service-access-request-context/service-access-request-context.client.ts.hbs +45 -0
- package/dist/templates/recipes/platform-service-access-request-context/service-access-request-context.config.ts.hbs +142 -0
- package/dist/templates/recipes/platform-service-access-request-context/service-access-request-context.guard.ts.hbs +77 -0
- package/dist/templates/recipes/platform-service-access-request-context/service-access-request-context.module.ts.hbs +17 -0
- package/dist/templates/repository/repository.hbs +42 -4
- package/dist/templates/resolver/graphql-input.hbs +23 -6
- package/dist/templates/resolver/resolver.hbs +4 -0
- package/dist/templates/service/domain-service.hbs +2 -2
- package/dist/templates/test/controller.spec.hbs +5 -1
- package/dist/templates/test/prisma-repository.spec.hbs +192 -0
- package/dist/templates/test/repository.spec.hbs +40 -1
- package/dist/templates/test/usecase.spec.hbs +23 -4
- package/dist/templates/usecase/application-usecase.hbs +17 -0
- package/dist/templates/usecase/create-usecase.hbs +34 -3
- package/dist/templates/usecase/update-usecase.hbs +15 -1
- package/dist/utils/config.utils.d.ts +2 -0
- package/dist/utils/config.utils.js +14 -2
- package/dist/utils/config.utils.js.map +1 -1
- package/dist/utils/dependency.utils.d.ts +16 -2
- package/dist/utils/dependency.utils.js +100 -12
- package/dist/utils/dependency.utils.js.map +1 -1
- package/dist/utils/field.utils.d.ts +6 -0
- package/dist/utils/field.utils.js +50 -8
- package/dist/utils/field.utils.js.map +1 -1
- package/dist/utils/field.utils.spec.d.ts +1 -0
- package/dist/utils/field.utils.spec.js +38 -0
- package/dist/utils/field.utils.spec.js.map +1 -0
- package/dist/utils/file.utils.d.ts +23 -1
- package/dist/utils/file.utils.js +37 -1
- package/dist/utils/file.utils.js.map +1 -1
- package/dist/utils/naming.utils.js +5 -4
- package/dist/utils/naming.utils.js.map +1 -1
- package/dist/utils/static-recipe.utils.d.ts +4 -0
- package/dist/utils/static-recipe.utils.js +148 -0
- package/dist/utils/static-recipe.utils.js.map +1 -0
- package/package.json +12 -5
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.applyPlatformParcBoundAuthorizationRecipe = applyPlatformParcBoundAuthorizationRecipe;
|
|
37
|
+
const path = __importStar(require("node:path"));
|
|
38
|
+
const static_recipe_utils_1 = require("../../utils/static-recipe.utils");
|
|
39
|
+
async function applyPlatformParcBoundAuthorizationRecipe(basePath, dryRun = false) {
|
|
40
|
+
const root = path.join(__dirname, '../../templates/recipes');
|
|
41
|
+
await (0, static_recipe_utils_1.applyStaticRecipePlan)(basePath, [
|
|
42
|
+
{
|
|
43
|
+
template: path.join(root, 'oauth2-token-introspection/http-client.ts.hbs'),
|
|
44
|
+
destination: 'src/shared/auth/oauth2-token-introspection/bounded-json-http.client.ts',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
template: path.join(root, 'platform-parc-bound-authorization/client.ts.hbs'),
|
|
48
|
+
destination: 'src/shared/authorization/platform-parc-bound-authorization/parc-bound.client.ts',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
template: path.join(root, 'platform-parc-bound-authorization/README.md.hbs'),
|
|
52
|
+
destination: 'docs/platform/parc-bound-authorization.md',
|
|
53
|
+
},
|
|
54
|
+
], dryRun);
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=platform-parc-bound-authorization.recipe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform-parc-bound-authorization.recipe.js","sourceRoot":"","sources":["../../../src/commands/recipes/platform-parc-bound-authorization.recipe.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,8FAwBC;AA3BD,gDAAkC;AAClC,yEAAwE;AAEjE,KAAK,UAAU,yCAAyC,CAC7D,QAAgB,EAChB,MAAM,GAAG,KAAK;IAEd,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,yBAAyB,CAAC,CAAC;IAC7D,MAAM,IAAA,2CAAqB,EACzB,QAAQ,EACR;QACE;YACE,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,+CAA+C,CAAC;YAC1E,WAAW,EAAE,wEAAwE;SACtF;QACD;YACE,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,iDAAiD,CAAC;YAC5E,WAAW,EACT,iFAAiF;SACpF;QACD;YACE,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,iDAAiD,CAAC;YAC5E,WAAW,EAAE,2CAA2C;SACzD;KACF,EACD,MAAM,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function applyPlatformServiceAccessRequestContextRecipe(basePath: string): Promise<void>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.applyPlatformServiceAccessRequestContextRecipe = applyPlatformServiceAccessRequestContextRecipe;
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
42
|
+
const file_utils_1 = require("../../utils/file.utils");
|
|
43
|
+
const platform_context_recipe_1 = require("./platform-context.recipe");
|
|
44
|
+
const recipeTemplates = [
|
|
45
|
+
{
|
|
46
|
+
source: 'service-access-request-context.config.ts.hbs',
|
|
47
|
+
target: 'src/shared/auth/platform-service-access-request-context/service-access-request-context.config.ts',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
source: 'request-context-introspection.types.ts.hbs',
|
|
51
|
+
target: 'src/shared/auth/platform-service-access-request-context/request-context-introspection.types.ts',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
source: 'request-context-introspection.parser.ts.hbs',
|
|
55
|
+
target: 'src/shared/auth/platform-service-access-request-context/request-context-introspection.parser.ts',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
source: 'request-context-headers.ts.hbs',
|
|
59
|
+
target: 'src/shared/auth/platform-service-access-request-context/request-context-headers.ts',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
source: 'service-access-request-context.client.ts.hbs',
|
|
63
|
+
target: 'src/shared/auth/platform-service-access-request-context/service-access-request-context.client.ts',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
source: 'service-access-request-context.guard.ts.hbs',
|
|
67
|
+
target: 'src/shared/auth/platform-service-access-request-context/service-access-request-context.guard.ts',
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
source: 'service-access-request-context.module.ts.hbs',
|
|
71
|
+
target: 'src/shared/auth/platform-service-access-request-context/service-access-request-context.module.ts',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
source: 'index.ts.hbs',
|
|
75
|
+
target: 'src/shared/auth/platform-service-access-request-context/index.ts',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
source: 'docs.md.hbs',
|
|
79
|
+
target: 'docs/platform/platform-service-access-request-context.md',
|
|
80
|
+
},
|
|
81
|
+
];
|
|
82
|
+
async function applyPlatformServiceAccessRequestContextRecipe(basePath) {
|
|
83
|
+
await (0, platform_context_recipe_1.applyPlatformContextRecipe)(basePath);
|
|
84
|
+
const templatePath = path.join(__dirname, '../../templates/recipes/platform-service-access-request-context');
|
|
85
|
+
for (const template of recipeTemplates) {
|
|
86
|
+
const content = await (0, file_utils_1.readTemplate)(path.join(templatePath, template.source));
|
|
87
|
+
await (0, file_utils_1.writeFile)(path.join(basePath, template.target), content);
|
|
88
|
+
}
|
|
89
|
+
const envExamplePath = path.join(basePath, '.env.example');
|
|
90
|
+
const fallbackExamplePath = path.join(basePath, '.env.platform-service-access-request-context.example');
|
|
91
|
+
const targetExamplePath = (await (0, file_utils_1.fileExists)(envExamplePath))
|
|
92
|
+
? fallbackExamplePath
|
|
93
|
+
: envExamplePath;
|
|
94
|
+
const envContent = await (0, file_utils_1.readTemplate)(path.join(templatePath, 'env.example.hbs'));
|
|
95
|
+
await (0, file_utils_1.ensureDir)(path.dirname(targetExamplePath));
|
|
96
|
+
await (0, file_utils_1.writeFile)(targetExamplePath, envContent);
|
|
97
|
+
console.log(chalk_1.default.green(' ✓ Platform request context contract'));
|
|
98
|
+
console.log(chalk_1.default.green(' ✓ Service Access lease introspection client and guard'));
|
|
99
|
+
console.log(chalk_1.default.green(' ✓ Strict active-response, audience, and principal parsing'));
|
|
100
|
+
console.log(chalk_1.default.green(' ✓ Disabled, shadow, and enforce rollout modes'));
|
|
101
|
+
console.log(chalk_1.default.yellow(' Run this guard before route-specific PARC authorization; caller identity headers are never authority.'));
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=platform-service-access-request-context.recipe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform-service-access-request-context.recipe.js","sourceRoot":"","sources":["../../../src/commands/recipes/platform-service-access-request-context.recipe.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,wGAoCC;AA3FD,2CAA6B;AAC7B,kDAA0B;AAC1B,uDAAwF;AACxF,uEAAuE;AAOvE,MAAM,eAAe,GAA8B;IACjD;QACE,MAAM,EAAE,8CAA8C;QACtD,MAAM,EACJ,kGAAkG;KACrG;IACD;QACE,MAAM,EAAE,4CAA4C;QACpD,MAAM,EACJ,gGAAgG;KACnG;IACD;QACE,MAAM,EAAE,6CAA6C;QACrD,MAAM,EACJ,iGAAiG;KACpG;IACD;QACE,MAAM,EAAE,gCAAgC;QACxC,MAAM,EAAE,oFAAoF;KAC7F;IACD;QACE,MAAM,EAAE,8CAA8C;QACtD,MAAM,EACJ,kGAAkG;KACrG;I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M,IAAA,sBAAS,EAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;IAE/C,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAC,CAAC;IAClE,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC,CAAC;IACpF,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,6DAA6D,CAAC,CAAC,CAAC;IACxF,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,iDAAiD,CAAC,CAAC,CAAC;IAC5E,OAAO,CAAC,GAAG,CACT,eAAK,CAAC,MAAM,CACV,yGAAyG,CAC1G,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function applyPlatformServiceRuntimeRecipe(basePath: string): Promise<void>;
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.applyPlatformServiceRuntimeRecipe = applyPlatformServiceRuntimeRecipe;
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
42
|
+
const file_utils_1 = require("../../utils/file.utils");
|
|
43
|
+
const platform_context_recipe_1 = require("./platform-context.recipe");
|
|
44
|
+
async function applyPlatformServiceRuntimeRecipe(basePath) {
|
|
45
|
+
const runtimePath = path.join(basePath, 'src/shared/platform-service-runtime');
|
|
46
|
+
const docsPath = path.join(basePath, 'docs/platform');
|
|
47
|
+
await (0, platform_context_recipe_1.applyPlatformContextRecipe)(basePath);
|
|
48
|
+
await (0, file_utils_1.ensureDir)(runtimePath);
|
|
49
|
+
await (0, file_utils_1.ensureDir)(docsPath);
|
|
50
|
+
await (0, file_utils_1.writeFile)(path.join(runtimePath, 'platform-service.types.ts'), typesContent);
|
|
51
|
+
await (0, file_utils_1.writeFile)(path.join(runtimePath, 'platform-service.manifest.ts'), manifestContent);
|
|
52
|
+
await (0, file_utils_1.writeFile)(path.join(runtimePath, 'platform-manifest.guard.ts'), manifestGuardContent);
|
|
53
|
+
await (0, file_utils_1.writeFile)(path.join(runtimePath, 'platform-service-manifest.controller.ts'), manifestControllerContent);
|
|
54
|
+
await (0, file_utils_1.writeFile)(path.join(runtimePath, 'platform-service-registration.client.ts'), registrationClientContent);
|
|
55
|
+
await (0, file_utils_1.writeFile)(path.join(runtimePath, 'platform-service.module.ts'), moduleContent);
|
|
56
|
+
await (0, file_utils_1.writeFile)(path.join(runtimePath, 'index.ts'), indexContent);
|
|
57
|
+
await (0, file_utils_1.writeFile)(path.join(docsPath, 'platform-service-runtime.md'), docsContent);
|
|
58
|
+
const envExamplePath = path.join(basePath, '.env.example');
|
|
59
|
+
const fallbackExamplePath = path.join(basePath, '.env.platform-service-runtime.example');
|
|
60
|
+
const targetExamplePath = (await (0, file_utils_1.fileExists)(envExamplePath))
|
|
61
|
+
? fallbackExamplePath
|
|
62
|
+
: envExamplePath;
|
|
63
|
+
await (0, file_utils_1.writeFile)(targetExamplePath, envExampleContent);
|
|
64
|
+
console.log(chalk_1.default.green(' ✓ Platform service manifest and capability contract'));
|
|
65
|
+
console.log(chalk_1.default.green(' ✓ Authenticated Service Access catalog registration'));
|
|
66
|
+
console.log(chalk_1.default.green(' ✓ Private manifest endpoint and runtime heartbeat metadata'));
|
|
67
|
+
console.log(chalk_1.default.yellow(' Provision a per-service Service Access key and set PLATFORM_REGISTRATION_REQUIRED=true in shared environments.'));
|
|
68
|
+
}
|
|
69
|
+
const typesContent = `export type PlatformRuntimeKind = "nestjs" | "go-sidecar" | "laravel" | "rust" | "external";
|
|
70
|
+
|
|
71
|
+
export const PLATFORM_SERVICE_MANIFEST = Symbol("PLATFORM_SERVICE_MANIFEST");
|
|
72
|
+
|
|
73
|
+
export type PlatformServiceCriticality = "system" | "money" | "identity" | "compliance" | "ops" | "product";
|
|
74
|
+
|
|
75
|
+
export interface PlatformServiceEndpoint {
|
|
76
|
+
name: string;
|
|
77
|
+
urlEnv: string;
|
|
78
|
+
healthPath?: string;
|
|
79
|
+
docsPath?: string;
|
|
80
|
+
internalOnly?: boolean;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface PlatformServiceAction {
|
|
84
|
+
name: string;
|
|
85
|
+
description: string;
|
|
86
|
+
owner: string;
|
|
87
|
+
requestContract?: string;
|
|
88
|
+
responseContract?: string;
|
|
89
|
+
idempotencyRequired?: boolean;
|
|
90
|
+
authRequired?: boolean;
|
|
91
|
+
timeoutMs?: number;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface PlatformServiceEvent {
|
|
95
|
+
name: string;
|
|
96
|
+
description: string;
|
|
97
|
+
schema?: string;
|
|
98
|
+
mandatoryForSubscribers?: boolean;
|
|
99
|
+
durable?: boolean;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface PlatformServiceDependency {
|
|
103
|
+
service: string;
|
|
104
|
+
reason: string;
|
|
105
|
+
required: boolean;
|
|
106
|
+
accessGrant?: string;
|
|
107
|
+
timeoutMs?: number;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface PlatformServiceManifest {
|
|
111
|
+
serviceName: string;
|
|
112
|
+
serviceSlug: string;
|
|
113
|
+
displayName: string;
|
|
114
|
+
description?: string;
|
|
115
|
+
companyName?: string;
|
|
116
|
+
productGroup: string;
|
|
117
|
+
runtime: PlatformRuntimeKind;
|
|
118
|
+
criticality: PlatformServiceCriticality;
|
|
119
|
+
ownerTeam?: string;
|
|
120
|
+
capabilities: string[];
|
|
121
|
+
endpoints: PlatformServiceEndpoint[];
|
|
122
|
+
actions: PlatformServiceAction[];
|
|
123
|
+
eventsProduced: PlatformServiceEvent[];
|
|
124
|
+
eventsConsumed: PlatformServiceEvent[];
|
|
125
|
+
dependencies: PlatformServiceDependency[];
|
|
126
|
+
requiredEnv: string[];
|
|
127
|
+
optionalEnv?: string[];
|
|
128
|
+
health: {
|
|
129
|
+
livePath: string;
|
|
130
|
+
readyPath: string;
|
|
131
|
+
metricsPath?: string;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export type PlatformRegistrationStatus = "registered" | "skipped" | "failed";
|
|
136
|
+
|
|
137
|
+
export interface PlatformRegistrationResult {
|
|
138
|
+
status: PlatformRegistrationStatus;
|
|
139
|
+
serviceId?: string;
|
|
140
|
+
reason?: string;
|
|
141
|
+
correlationId: string;
|
|
142
|
+
}
|
|
143
|
+
`;
|
|
144
|
+
const manifestContent = `import { PlatformServiceManifest } from "./platform-service.types";
|
|
145
|
+
|
|
146
|
+
export const platformServiceManifest: PlatformServiceManifest = {
|
|
147
|
+
serviceName: process.env.APP_NAME ?? "replace-me-service",
|
|
148
|
+
serviceSlug: process.env.APP_SERVICE_SLUG ?? "replace-me-service",
|
|
149
|
+
displayName: process.env.APP_DISPLAY_NAME ?? "Replace Me Service",
|
|
150
|
+
description: process.env.APP_DESCRIPTION,
|
|
151
|
+
productGroup: "platform-core",
|
|
152
|
+
runtime: "nestjs",
|
|
153
|
+
criticality: "product",
|
|
154
|
+
capabilities: [],
|
|
155
|
+
endpoints: [
|
|
156
|
+
{
|
|
157
|
+
name: "api",
|
|
158
|
+
urlEnv: "PUBLIC_API_URL",
|
|
159
|
+
healthPath: "/api/v1/health",
|
|
160
|
+
docsPath: "/api/v1/docs",
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
actions: [],
|
|
164
|
+
eventsProduced: [],
|
|
165
|
+
eventsConsumed: [],
|
|
166
|
+
dependencies: [],
|
|
167
|
+
requiredEnv: ["NODE_ENV", "DATABASE_URL", "INTERNAL_API_KEY"],
|
|
168
|
+
optionalEnv: ["SERVICE_ACCESS_URL", "LOG_LEVEL", "CORS_ORIGINS"],
|
|
169
|
+
health: {
|
|
170
|
+
livePath: "/api/v1/health/live",
|
|
171
|
+
readyPath: "/api/v1/health/ready",
|
|
172
|
+
metricsPath: "/metrics",
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
`;
|
|
176
|
+
const manifestGuardContent = `import {
|
|
177
|
+
CanActivate,
|
|
178
|
+
ExecutionContext,
|
|
179
|
+
Injectable,
|
|
180
|
+
UnauthorizedException,
|
|
181
|
+
} from "@nestjs/common";
|
|
182
|
+
import { timingSafeEqual } from "crypto";
|
|
183
|
+
|
|
184
|
+
@Injectable()
|
|
185
|
+
export class PlatformManifestGuard implements CanActivate {
|
|
186
|
+
canActivate(context: ExecutionContext): boolean {
|
|
187
|
+
const request = context.switchToHttp().getRequest<{
|
|
188
|
+
headers: Record<string, string | string[] | undefined>;
|
|
189
|
+
}>();
|
|
190
|
+
const expected = process.env.PLATFORM_MANIFEST_READ_TOKEN;
|
|
191
|
+
const presented = request.headers.authorization;
|
|
192
|
+
const token = typeof presented === "string" && presented.startsWith("Bearer ")
|
|
193
|
+
? presented.slice(7)
|
|
194
|
+
: undefined;
|
|
195
|
+
|
|
196
|
+
if (!expected || !token || !this.matches(token, expected)) {
|
|
197
|
+
throw new UnauthorizedException("Platform manifest authentication required");
|
|
198
|
+
}
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private matches(presented: string, expected: string): boolean {
|
|
203
|
+
const left = Buffer.from(presented);
|
|
204
|
+
const right = Buffer.from(expected);
|
|
205
|
+
return left.length === right.length && timingSafeEqual(left, right);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
`;
|
|
209
|
+
const manifestControllerContent = `import { Controller, Get, UseGuards } from "@nestjs/common";
|
|
210
|
+
import { platformServiceManifest } from "./platform-service.manifest";
|
|
211
|
+
import { PlatformManifestGuard } from "./platform-manifest.guard";
|
|
212
|
+
|
|
213
|
+
@Controller("internal/platform")
|
|
214
|
+
@UseGuards(PlatformManifestGuard)
|
|
215
|
+
export class PlatformServiceManifestController {
|
|
216
|
+
@Get("manifest")
|
|
217
|
+
manifest() {
|
|
218
|
+
return platformServiceManifest;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
`;
|
|
222
|
+
const registrationClientContent = `import { randomUUID } from "crypto";
|
|
223
|
+
import { Inject, Injectable } from "@nestjs/common";
|
|
224
|
+
import { PlatformContextService } from "../platform-context";
|
|
225
|
+
import {
|
|
226
|
+
PLATFORM_SERVICE_MANIFEST,
|
|
227
|
+
PlatformRegistrationResult,
|
|
228
|
+
PlatformServiceManifest,
|
|
229
|
+
} from "./platform-service.types";
|
|
230
|
+
|
|
231
|
+
type RegistrationPhase = "registration" | "heartbeat";
|
|
232
|
+
|
|
233
|
+
@Injectable()
|
|
234
|
+
export class PlatformServiceRegistrationClient {
|
|
235
|
+
constructor(
|
|
236
|
+
@Inject(PLATFORM_SERVICE_MANIFEST)
|
|
237
|
+
private readonly manifest: PlatformServiceManifest,
|
|
238
|
+
private readonly context: PlatformContextService,
|
|
239
|
+
) {}
|
|
240
|
+
|
|
241
|
+
register(): Promise<PlatformRegistrationResult> {
|
|
242
|
+
return this.sync("registration");
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
heartbeat(): Promise<PlatformRegistrationResult> {
|
|
246
|
+
return this.sync("heartbeat");
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
private async sync(phase: RegistrationPhase): Promise<PlatformRegistrationResult> {
|
|
250
|
+
const correlationId = this.context.current()?.correlationId || randomUUID();
|
|
251
|
+
const required = this.booleanEnv("PLATFORM_REGISTRATION_REQUIRED", false);
|
|
252
|
+
const baseUrl = this.clean(process.env.SERVICE_ACCESS_URL)?.replace(/\\/+$/, "");
|
|
253
|
+
const apiKey = this.clean(process.env.SERVICE_ACCESS_INTERNAL_API_KEY);
|
|
254
|
+
const revision = this.clean(process.env.APP_REVISION || process.env.CI_COMMIT_SHA);
|
|
255
|
+
|
|
256
|
+
if (!baseUrl || !apiKey || !revision) {
|
|
257
|
+
return this.unavailable(
|
|
258
|
+
required,
|
|
259
|
+
correlationId,
|
|
260
|
+
"SERVICE_ACCESS_URL, SERVICE_ACCESS_INTERNAL_API_KEY, and APP_REVISION or CI_COMMIT_SHA are required",
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
this.assertSlug(this.manifest.serviceSlug);
|
|
265
|
+
const now = new Date();
|
|
266
|
+
const idempotencyKey = this.idempotencyKey(phase, revision, now);
|
|
267
|
+
const timeoutMs = this.integerEnv("SERVICE_ACCESS_TIMEOUT_MS", 3000);
|
|
268
|
+
|
|
269
|
+
try {
|
|
270
|
+
const response = await fetch(baseUrl + "/registered-services/upsert", {
|
|
271
|
+
method: "POST",
|
|
272
|
+
headers: {
|
|
273
|
+
"Content-Type": "application/json",
|
|
274
|
+
Accept: "application/json",
|
|
275
|
+
"x-internal-api-key": apiKey,
|
|
276
|
+
"Idempotency-Key": idempotencyKey,
|
|
277
|
+
"X-Correlation-ID": correlationId,
|
|
278
|
+
},
|
|
279
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
280
|
+
body: JSON.stringify({
|
|
281
|
+
slug: this.manifest.serviceSlug,
|
|
282
|
+
display_name: this.manifest.displayName,
|
|
283
|
+
owner_type: "platform",
|
|
284
|
+
status: "active",
|
|
285
|
+
description: this.manifest.description,
|
|
286
|
+
metadata: {
|
|
287
|
+
manifest: this.manifest,
|
|
288
|
+
runtime: {
|
|
289
|
+
phase,
|
|
290
|
+
revision,
|
|
291
|
+
image: this.clean(process.env.APP_IMAGE),
|
|
292
|
+
environment: this.clean(process.env.NODE_ENV),
|
|
293
|
+
health: this.manifest.health,
|
|
294
|
+
heartbeatAt: now.toISOString(),
|
|
295
|
+
},
|
|
296
|
+
correlationId,
|
|
297
|
+
},
|
|
298
|
+
}),
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
if (!response.ok) {
|
|
302
|
+
throw new Error("Service Access registration failed with HTTP " + response.status);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const body = (await response.json()) as { id?: unknown };
|
|
306
|
+
return {
|
|
307
|
+
status: "registered",
|
|
308
|
+
serviceId: typeof body.id === "string" ? body.id : undefined,
|
|
309
|
+
correlationId,
|
|
310
|
+
};
|
|
311
|
+
} catch (error) {
|
|
312
|
+
const reason = error instanceof Error ? error.message : "Service Access registration failed";
|
|
313
|
+
if (required) {
|
|
314
|
+
throw new Error(reason);
|
|
315
|
+
}
|
|
316
|
+
return { status: "failed", reason, correlationId };
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
private unavailable(
|
|
321
|
+
required: boolean,
|
|
322
|
+
correlationId: string,
|
|
323
|
+
reason: string,
|
|
324
|
+
): PlatformRegistrationResult {
|
|
325
|
+
if (required) {
|
|
326
|
+
throw new Error(reason);
|
|
327
|
+
}
|
|
328
|
+
return { status: "skipped", reason, correlationId };
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
private idempotencyKey(phase: RegistrationPhase, revision: string, now: Date): string {
|
|
332
|
+
const suffix = phase === "heartbeat" ? ":" + now.toISOString().slice(0, 16) : "";
|
|
333
|
+
return "platform-runtime:" + this.manifest.serviceSlug + ":" + revision + suffix;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
private assertSlug(value: string): void {
|
|
337
|
+
if (!/^[a-z0-9](?:[a-z0-9-]{0,126}[a-z0-9])?$/.test(value)) {
|
|
338
|
+
throw new Error("Platform service slug must be lowercase kebab-case");
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
private booleanEnv(name: string, fallback: boolean): boolean {
|
|
343
|
+
const value = this.clean(process.env[name]);
|
|
344
|
+
return value ? value.toLowerCase() === "true" : fallback;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
private integerEnv(name: string, fallback: number): number {
|
|
348
|
+
const value = Number(process.env[name]);
|
|
349
|
+
return Number.isInteger(value) && value > 0 ? value : fallback;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
private clean(value: string | undefined): string | undefined {
|
|
353
|
+
const cleaned = value?.trim();
|
|
354
|
+
return cleaned || undefined;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
`;
|
|
358
|
+
const moduleContent = `import { Global, Module } from "@nestjs/common";
|
|
359
|
+
import { PlatformContextModule } from "../platform-context";
|
|
360
|
+
import { platformServiceManifest } from "./platform-service.manifest";
|
|
361
|
+
import { PlatformManifestGuard } from "./platform-manifest.guard";
|
|
362
|
+
import { PlatformServiceManifestController } from "./platform-service-manifest.controller";
|
|
363
|
+
import { PlatformServiceRegistrationClient } from "./platform-service-registration.client";
|
|
364
|
+
import { PLATFORM_SERVICE_MANIFEST } from "./platform-service.types";
|
|
365
|
+
|
|
366
|
+
@Global()
|
|
367
|
+
@Module({
|
|
368
|
+
imports: [PlatformContextModule],
|
|
369
|
+
controllers: [PlatformServiceManifestController],
|
|
370
|
+
providers: [
|
|
371
|
+
PlatformManifestGuard,
|
|
372
|
+
PlatformServiceRegistrationClient,
|
|
373
|
+
{
|
|
374
|
+
provide: PLATFORM_SERVICE_MANIFEST,
|
|
375
|
+
useValue: platformServiceManifest,
|
|
376
|
+
},
|
|
377
|
+
],
|
|
378
|
+
exports: [PLATFORM_SERVICE_MANIFEST, PlatformServiceRegistrationClient],
|
|
379
|
+
})
|
|
380
|
+
export class PlatformServiceRuntimeModule {}
|
|
381
|
+
`;
|
|
382
|
+
const indexContent = `export * from "./platform-service.types";
|
|
383
|
+
export * from "./platform-service.manifest";
|
|
384
|
+
export * from "./platform-manifest.guard";
|
|
385
|
+
export * from "./platform-service-manifest.controller";
|
|
386
|
+
export * from "./platform-service-registration.client";
|
|
387
|
+
export * from "./platform-service.module";
|
|
388
|
+
`;
|
|
389
|
+
const envExampleContent = `APP_SERVICE_SLUG=replace-me-service
|
|
390
|
+
APP_DISPLAY_NAME=Replace Me Service
|
|
391
|
+
APP_REVISION=local
|
|
392
|
+
APP_IMAGE=
|
|
393
|
+
SERVICE_ACCESS_URL=
|
|
394
|
+
SERVICE_ACCESS_INTERNAL_API_KEY=
|
|
395
|
+
SERVICE_ACCESS_TIMEOUT_MS=3000
|
|
396
|
+
PLATFORM_REGISTRATION_REQUIRED=false
|
|
397
|
+
PLATFORM_MANIFEST_READ_TOKEN=
|
|
398
|
+
`;
|
|
399
|
+
const docsContent = `# Platform Service Runtime
|
|
400
|
+
|
|
401
|
+
The service manifest declares metadata and capabilities. Service Access remains
|
|
402
|
+
the catalog and grant authority; this recipe does not create a second registry.
|
|
403
|
+
|
|
404
|
+
Call \`PlatformServiceRegistrationClient.register()\` during application
|
|
405
|
+
bootstrap and \`heartbeat()\` from a bounded scheduled job. Both operations
|
|
406
|
+
upsert the service through Service Access and carry runtime revision, image,
|
|
407
|
+
health, correlation, and idempotency metadata. A skipped or failed result is not
|
|
408
|
+
a successful registration.
|
|
409
|
+
|
|
410
|
+
Set \`PLATFORM_REGISTRATION_REQUIRED=true\` in shared staging and production
|
|
411
|
+
after the per-service key is provisioned. Keep the manifest endpoint private and
|
|
412
|
+
protect it with a dedicated read token. Never expose internal endpoints through
|
|
413
|
+
the public gateway.
|
|
414
|
+
`;
|
|
415
|
+
//# sourceMappingURL=platform-service-runtime.recipe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform-service-runtime.recipe.js","sourceRoot":"","sources":["../../../src/commands/recipes/platform-service-runtime.recipe.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,8EAsCC;AA3CD,2CAA6B;AAC7B,kDAA0B;AAC1B,uDAA0E;AAC1E,uEAAuE;AAEhE,KAAK,UAAU,iCAAiC,CAAC,QAAgB;IACtE,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,qCAAqC,CAAC,CAAC;IAC/E,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;IAEtD,MAAM,IAAA,oDAA0B,EAAC,QAAQ,CAAC,CAAC;IAC3C,MAAM,IAAA,sBAAS,EAAC,WAAW,CAAC,CAAC;IAC7B,MAAM,IAAA,sBAAS,EAAC,QAAQ,CAAC,CAAC;IAE1B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