openxiangda-nest 2.0.0-alpha.100

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 (106) hide show
  1. package/README.md +158 -0
  2. package/dist/application-credentials.d.ts +19 -0
  3. package/dist/application-credentials.d.ts.map +1 -0
  4. package/dist/application-credentials.js +158 -0
  5. package/dist/application-credentials.js.map +1 -0
  6. package/dist/assignee-provider.d.ts +35 -0
  7. package/dist/assignee-provider.d.ts.map +1 -0
  8. package/dist/assignee-provider.js +223 -0
  9. package/dist/assignee-provider.js.map +1 -0
  10. package/dist/authz.d.ts +28 -0
  11. package/dist/authz.d.ts.map +1 -0
  12. package/dist/authz.js +207 -0
  13. package/dist/authz.js.map +1 -0
  14. package/dist/bootstrap.d.ts +15 -0
  15. package/dist/bootstrap.d.ts.map +1 -0
  16. package/dist/bootstrap.js +40 -0
  17. package/dist/bootstrap.js.map +1 -0
  18. package/dist/business-action-context.d.ts +14 -0
  19. package/dist/business-action-context.d.ts.map +1 -0
  20. package/dist/business-action-context.js +41 -0
  21. package/dist/business-action-context.js.map +1 -0
  22. package/dist/business-directory.d.ts +14 -0
  23. package/dist/business-directory.d.ts.map +1 -0
  24. package/dist/business-directory.js +40 -0
  25. package/dist/business-directory.js.map +1 -0
  26. package/dist/business-notification.d.ts +23 -0
  27. package/dist/business-notification.d.ts.map +1 -0
  28. package/dist/business-notification.js +58 -0
  29. package/dist/business-notification.js.map +1 -0
  30. package/dist/business-process.d.ts +23 -0
  31. package/dist/business-process.d.ts.map +1 -0
  32. package/dist/business-process.js +106 -0
  33. package/dist/business-process.js.map +1 -0
  34. package/dist/data-api.d.ts +116 -0
  35. package/dist/data-api.d.ts.map +1 -0
  36. package/dist/data-api.js +248 -0
  37. package/dist/data-api.js.map +1 -0
  38. package/dist/event-context.d.ts +15 -0
  39. package/dist/event-context.d.ts.map +1 -0
  40. package/dist/event-context.js +33 -0
  41. package/dist/event-context.js.map +1 -0
  42. package/dist/event-handler.d.ts +36 -0
  43. package/dist/event-handler.d.ts.map +1 -0
  44. package/dist/event-handler.js +174 -0
  45. package/dist/event-handler.js.map +1 -0
  46. package/dist/events.d.ts +64 -0
  47. package/dist/events.d.ts.map +1 -0
  48. package/dist/events.js +513 -0
  49. package/dist/events.js.map +1 -0
  50. package/dist/gateway-transport.d.ts +53 -0
  51. package/dist/gateway-transport.d.ts.map +1 -0
  52. package/dist/gateway-transport.js +369 -0
  53. package/dist/gateway-transport.js.map +1 -0
  54. package/dist/health.d.ts +36 -0
  55. package/dist/health.d.ts.map +1 -0
  56. package/dist/health.js +105 -0
  57. package/dist/health.js.map +1 -0
  58. package/dist/index.d.ts +25 -0
  59. package/dist/index.d.ts.map +1 -0
  60. package/dist/index.js +25 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/infrastructure-controller.d.ts +8 -0
  63. package/dist/infrastructure-controller.d.ts.map +1 -0
  64. package/dist/infrastructure-controller.js +15 -0
  65. package/dist/infrastructure-controller.js.map +1 -0
  66. package/dist/logger.d.ts +20 -0
  67. package/dist/logger.d.ts.map +1 -0
  68. package/dist/logger.js +62 -0
  69. package/dist/logger.js.map +1 -0
  70. package/dist/module.d.ts +6 -0
  71. package/dist/module.d.ts.map +1 -0
  72. package/dist/module.js +293 -0
  73. package/dist/module.js.map +1 -0
  74. package/dist/notification.d.ts +18 -0
  75. package/dist/notification.d.ts.map +1 -0
  76. package/dist/notification.js +52 -0
  77. package/dist/notification.js.map +1 -0
  78. package/dist/platform-client.d.ts +115 -0
  79. package/dist/platform-client.d.ts.map +1 -0
  80. package/dist/platform-client.js +506 -0
  81. package/dist/platform-client.js.map +1 -0
  82. package/dist/runtime.d.ts +56 -0
  83. package/dist/runtime.d.ts.map +1 -0
  84. package/dist/runtime.js +253 -0
  85. package/dist/runtime.js.map +1 -0
  86. package/dist/standard-operations.d.ts +62 -0
  87. package/dist/standard-operations.d.ts.map +1 -0
  88. package/dist/standard-operations.js +169 -0
  89. package/dist/standard-operations.js.map +1 -0
  90. package/dist/todo.d.ts +20 -0
  91. package/dist/todo.d.ts.map +1 -0
  92. package/dist/todo.js +48 -0
  93. package/dist/todo.js.map +1 -0
  94. package/dist/tokens.d.ts +5 -0
  95. package/dist/tokens.d.ts.map +1 -0
  96. package/dist/tokens.js +5 -0
  97. package/dist/tokens.js.map +1 -0
  98. package/dist/types.d.ts +178 -0
  99. package/dist/types.d.ts.map +1 -0
  100. package/dist/types.js +2 -0
  101. package/dist/types.js.map +1 -0
  102. package/dist/workflow.d.ts +41 -0
  103. package/dist/workflow.d.ts.map +1 -0
  104. package/dist/workflow.js +97 -0
  105. package/dist/workflow.js.map +1 -0
  106. package/package.json +64 -0
@@ -0,0 +1,174 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import { BadRequestException, Controller, Headers, Inject, Injectable, NotFoundException, Param, Post, Req, SetMetadata, } from '@nestjs/common';
14
+ import { DiscoveryService, Reflector } from '@nestjs/core';
15
+ import { APPLICATION_EVENT_HANDLER_PATH_PREFIX_V2, SCHEMA_VERSIONS, applicationEventHandlerPathV2, sha256Digest, } from 'openxiangda-contracts';
16
+ import { OpenXiangdaEventReceiver } from './events.js';
17
+ import { OpenXiangdaInfrastructureController } from './infrastructure-controller.js';
18
+ import { OPENXIANGDA_MODULE_OPTIONS } from './tokens.js';
19
+ const OPENXIANGDA_EVENT_HANDLER = Symbol('OPENXIANGDA_EVENT_HANDLER');
20
+ export function OpenXiangdaEventHandler(declaration) {
21
+ const normalized = normalizeHandlerDeclaration(declaration);
22
+ return SetMetadata(OPENXIANGDA_EVENT_HANDLER, normalized);
23
+ }
24
+ let OpenXiangdaEventRegistry = class OpenXiangdaEventRegistry {
25
+ discovery;
26
+ reflector;
27
+ options;
28
+ handlers = new Map();
29
+ constructor(discovery, reflector, options) {
30
+ this.discovery = discovery;
31
+ this.reflector = reflector;
32
+ this.options = options;
33
+ }
34
+ onModuleInit() {
35
+ const declared = this.declaredHandlers();
36
+ for (const wrapper of this.discovery.getProviders()) {
37
+ const contract = wrapper.metatype
38
+ ? this.reflector.get(OPENXIANGDA_EVENT_HANDLER, wrapper.metatype)
39
+ : undefined;
40
+ if (!contract || !wrapper.instance)
41
+ continue;
42
+ const expected = declared.get(contract.code);
43
+ if (!expected || sha256Digest(expected) !== sha256Digest(contract)) {
44
+ throw new Error(`事件 handler 与 generated manifest 不一致: ${contract.code}`);
45
+ }
46
+ if (typeof wrapper.instance.handle !== 'function') {
47
+ throw new Error(`事件 handler ${contract.code} 缺少 handle()`);
48
+ }
49
+ if (this.handlers.has(contract.code)) {
50
+ throw new Error(`事件 handler 重复注册: ${contract.code}`);
51
+ }
52
+ this.handlers.set(contract.code, {
53
+ contract: expected,
54
+ consumer: wrapper.instance,
55
+ });
56
+ }
57
+ for (const code of declared.keys()) {
58
+ if (!this.handlers.has(code)) {
59
+ throw new Error(`generated manifest 的事件 handler 未注册: ${code}`);
60
+ }
61
+ }
62
+ }
63
+ resolve(code) {
64
+ const registered = this.handlers.get(String(code || '').trim());
65
+ if (!registered) {
66
+ throw new NotFoundException({
67
+ code: 'OPENXIANGDA_EVENT_HANDLER_NOT_FOUND',
68
+ });
69
+ }
70
+ return registered;
71
+ }
72
+ declaredHandlers() {
73
+ const manifest = this.options.eventHandlerManifest;
74
+ if (!manifest)
75
+ return new Map();
76
+ if (manifest.schemaVersion !== SCHEMA_VERSIONS.eventHandlerManifest ||
77
+ manifest.appCode !== this.options.appCode ||
78
+ !Array.isArray(manifest.handlers) ||
79
+ manifest.handlers.length > 100) {
80
+ throw new Error('eventHandlerManifest 与当前应用不一致');
81
+ }
82
+ const entries = manifest.handlers.map(handler => {
83
+ const normalized = normalizeHandlerDeclaration(handler);
84
+ return [normalized.code, normalized];
85
+ });
86
+ const result = new Map(entries);
87
+ if (result.size !== entries.length) {
88
+ throw new Error('eventHandlerManifest 包含重复 code');
89
+ }
90
+ return result;
91
+ }
92
+ };
93
+ OpenXiangdaEventRegistry = __decorate([
94
+ Injectable(),
95
+ __param(0, Inject(DiscoveryService)),
96
+ __param(1, Inject(Reflector)),
97
+ __param(2, Inject(OPENXIANGDA_MODULE_OPTIONS)),
98
+ __metadata("design:paramtypes", [DiscoveryService,
99
+ Reflector, Object])
100
+ ], OpenXiangdaEventRegistry);
101
+ export { OpenXiangdaEventRegistry };
102
+ let OpenXiangdaEventController = class OpenXiangdaEventController {
103
+ receiver;
104
+ registry;
105
+ constructor(receiver, registry) {
106
+ this.receiver = receiver;
107
+ this.registry = registry;
108
+ }
109
+ async deliver(subscriptionCode, headers, request) {
110
+ if (!Buffer.isBuffer(request.rawBody)) {
111
+ throw new BadRequestException('事件入口必须保留 raw body');
112
+ }
113
+ const registered = this.registry.resolve(subscriptionCode);
114
+ return await this.receiver.accept(registered.contract, headers, request.rawBody, async (event, context) => await registered.consumer.handle(event, context));
115
+ }
116
+ };
117
+ __decorate([
118
+ Post('/:subscriptionCode'),
119
+ __param(0, Param('subscriptionCode')),
120
+ __param(1, Headers()),
121
+ __param(2, Req()),
122
+ __metadata("design:type", Function),
123
+ __metadata("design:paramtypes", [String, Object, Object]),
124
+ __metadata("design:returntype", Promise)
125
+ ], OpenXiangdaEventController.prototype, "deliver", null);
126
+ OpenXiangdaEventController = __decorate([
127
+ OpenXiangdaInfrastructureController(),
128
+ Controller(APPLICATION_EVENT_HANDLER_PATH_PREFIX_V2),
129
+ __param(0, Inject(OpenXiangdaEventReceiver)),
130
+ __param(1, Inject(OpenXiangdaEventRegistry)),
131
+ __metadata("design:paramtypes", [OpenXiangdaEventReceiver,
132
+ OpenXiangdaEventRegistry])
133
+ ], OpenXiangdaEventController);
134
+ export { OpenXiangdaEventController };
135
+ function normalizeHandlerDeclaration(input) {
136
+ const code = String(input?.code || '').trim();
137
+ if (!/^[a-z][a-z0-9-]*$/.test(code)) {
138
+ throw new Error('事件 handler code 必须是 kebab-case');
139
+ }
140
+ const endpointPath = applicationEventHandlerPathV2(code);
141
+ if (input.endpointPath !== endpointPath) {
142
+ throw new Error(`事件 handler endpoint 必须是 ${endpointPath}`);
143
+ }
144
+ const eventTypes = unique(input.eventTypes);
145
+ const dataSchemaVersions = unique(input.dataSchemaVersions);
146
+ if (eventTypes.length < 1 ||
147
+ eventTypes.length > 20 ||
148
+ dataSchemaVersions.length < 1 ||
149
+ dataSchemaVersions.length > 20 ||
150
+ input.maxBodyBytes !== 65_536 ||
151
+ input.receiptProtocolVersion !== 2) {
152
+ throw new Error(`事件 handler contract 不合法: ${code}`);
153
+ }
154
+ return {
155
+ code,
156
+ endpointPath,
157
+ eventTypes,
158
+ dataSchemaVersions,
159
+ maxBodyBytes: 65_536,
160
+ receiptProtocolVersion: 2,
161
+ };
162
+ }
163
+ function unique(values) {
164
+ const normalized = values.map(value => String(value || '').trim());
165
+ if (normalized.some(value => !value)) {
166
+ throw new Error('事件 handler contract 包含空值');
167
+ }
168
+ const result = [...new Set(normalized)].sort();
169
+ if (result.length !== normalized.length) {
170
+ throw new Error('事件 handler contract 包含重复值');
171
+ }
172
+ return result;
173
+ }
174
+ //# sourceMappingURL=event-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-handler.js","sourceRoot":"","sources":["../src/event-handler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAC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C,KAAK,CAAC,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;IAC9C,CAAC;IACD,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC/C,IAAI,MAAM,CAAC,MAAM,KAAK,UAAU,CAAC,MAAM,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,64 @@
1
+ import { HttpException } from '@nestjs/common';
2
+ import { type AppEventHandlerContract, type CloudEvent, type EventDeliveryAck } from 'openxiangda-contracts';
3
+ import { OpenXiangdaEventContext, type OpenXiangdaEventHandlerContext } from './event-context.js';
4
+ import type { OpenXiangdaEventReceiptContext, OpenXiangdaEventReceiptStore, OpenXiangdaModuleOptions } from './types.js';
5
+ export type OpenXiangdaEventAcceptResult = EventDeliveryAck;
6
+ export declare class OpenXiangdaEventRetryableError extends HttpException {
7
+ constructor(code: string, message?: string, status?: number);
8
+ }
9
+ export declare class OpenXiangdaEventDeterministicError extends HttpException {
10
+ constructor(code: string, message?: string, status?: number);
11
+ }
12
+ /**
13
+ * Resolves only declared event subscription credentials from the standard
14
+ * platform environment contract. A staged next secret is first so a rolling
15
+ * deployment can acknowledge deliveries with the credential being activated.
16
+ */
17
+ export declare function eventSigningSecretsFromEnvironment(subscriptionCodes: readonly string[], environment?: Record<string, string | undefined>): {
18
+ [k: string]: string[];
19
+ };
20
+ export declare class InMemoryOpenXiangdaEventReceiptStore implements OpenXiangdaEventReceiptStore {
21
+ private readonly receipts;
22
+ claim(receipt: OpenXiangdaEventReceiptContext): Promise<'claimed' | 'duplicate' | 'busy'>;
23
+ complete(receipt: OpenXiangdaEventReceiptContext): Promise<void>;
24
+ release(receipt: OpenXiangdaEventReceiptContext): Promise<void>;
25
+ private key;
26
+ }
27
+ /**
28
+ * Production receipt store backed by the OpenXiangda platform database.
29
+ * The event subscription secret authenticates every command; no app OAuth
30
+ * credential or local database is required.
31
+ */
32
+ export declare class PlatformOpenXiangdaEventReceiptStore implements OpenXiangdaEventReceiptStore {
33
+ private readonly options;
34
+ private readonly claimTokens;
35
+ constructor(options: OpenXiangdaModuleOptions);
36
+ claim(receipt: OpenXiangdaEventReceiptContext): Promise<'claimed' | 'duplicate' | 'busy'>;
37
+ complete(receipt: OpenXiangdaEventReceiptContext): Promise<void>;
38
+ release(receipt: OpenXiangdaEventReceiptContext): Promise<void>;
39
+ private finish;
40
+ private delay;
41
+ private execute;
42
+ private signatureContent;
43
+ private receiptUrl;
44
+ private signingSecrets;
45
+ private key;
46
+ }
47
+ export declare class OpenXiangdaEventReceiver {
48
+ private readonly options;
49
+ private readonly receipts;
50
+ private readonly eventContext;
51
+ private readonly validators;
52
+ constructor(options: OpenXiangdaModuleOptions, receipts: OpenXiangdaEventReceiptStore, eventContext: OpenXiangdaEventContext);
53
+ accept(contract: AppEventHandlerContract, headers: Record<string, string | string[] | undefined>, rawBody: Buffer | string, handler: (event: CloudEvent, context: OpenXiangdaEventHandlerContext) => Promise<unknown> | unknown): Promise<OpenXiangdaEventAcceptResult>;
54
+ private parseEvent;
55
+ private assertTimestamp;
56
+ private assertSignature;
57
+ private assertContentType;
58
+ private assertEventSchema;
59
+ private manifestDigest;
60
+ private schemaKey;
61
+ private ack;
62
+ private header;
63
+ }
64
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,aAAa,EAKd,MAAM,gBAAgB,CAAC;AAExB,OAAO,EASL,KAAK,uBAAuB,EAC5B,KAAK,UAAU,EACf,KAAK,gBAAgB,EAItB,MAAM,uBAAuB,CAAC;AAK/B,OAAO,EACL,uBAAuB,EACvB,KAAK,8BAA8B,EACpC,MAAM,oBAAoB,CAAC;AA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