openxiangda-nest 2.0.0-alpha.12

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 (50) hide show
  1. package/README.md +25 -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 +34 -0
  7. package/dist/assignee-provider.d.ts.map +1 -0
  8. package/dist/assignee-provider.js +216 -0
  9. package/dist/assignee-provider.js.map +1 -0
  10. package/dist/authz.d.ts +17 -0
  11. package/dist/authz.d.ts.map +1 -0
  12. package/dist/authz.js +129 -0
  13. package/dist/authz.js.map +1 -0
  14. package/dist/data-api.d.ts +61 -0
  15. package/dist/data-api.d.ts.map +1 -0
  16. package/dist/data-api.js +122 -0
  17. package/dist/data-api.js.map +1 -0
  18. package/dist/events.d.ts +46 -0
  19. package/dist/events.d.ts.map +1 -0
  20. package/dist/events.js +359 -0
  21. package/dist/events.js.map +1 -0
  22. package/dist/health.d.ts +24 -0
  23. package/dist/health.d.ts.map +1 -0
  24. package/dist/health.js +81 -0
  25. package/dist/health.js.map +1 -0
  26. package/dist/index.d.ts +12 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +12 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/module.d.ts +6 -0
  31. package/dist/module.d.ts.map +1 -0
  32. package/dist/module.js +106 -0
  33. package/dist/module.js.map +1 -0
  34. package/dist/platform-client.d.ts +101 -0
  35. package/dist/platform-client.d.ts.map +1 -0
  36. package/dist/platform-client.js +250 -0
  37. package/dist/platform-client.js.map +1 -0
  38. package/dist/tokens.d.ts +4 -0
  39. package/dist/tokens.d.ts.map +1 -0
  40. package/dist/tokens.js +4 -0
  41. package/dist/tokens.js.map +1 -0
  42. package/dist/types.d.ts +71 -0
  43. package/dist/types.d.ts.map +1 -0
  44. package/dist/types.js +2 -0
  45. package/dist/types.js.map +1 -0
  46. package/dist/workflow.d.ts +59 -0
  47. package/dist/workflow.d.ts.map +1 -0
  48. package/dist/workflow.js +84 -0
  49. package/dist/workflow.js.map +1 -0
  50. package/package.json +43 -0
@@ -0,0 +1,24 @@
1
+ import { OpenXiangdaPlatformClient } from './platform-client.js';
2
+ import type { OpenXiangdaModuleOptions } from './types.js';
3
+ export declare class OpenXiangdaPlatformController {
4
+ private readonly options;
5
+ private readonly platform;
6
+ constructor(options: OpenXiangdaModuleOptions, platform: OpenXiangdaPlatformClient);
7
+ health(): {
8
+ status: "ok";
9
+ };
10
+ ready(): Promise<{
11
+ status: "ready";
12
+ platformVersion: string;
13
+ contractVersion: "2.0.0-alpha.1";
14
+ }>;
15
+ version(): {
16
+ appCode: string;
17
+ environmentId: string;
18
+ version: string;
19
+ gitSha: string | null;
20
+ buildId: string | null;
21
+ contractVersion: "2.0.0-alpha.1";
22
+ };
23
+ }
24
+ //# sourceMappingURL=health.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../src/health.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEjE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAE3D,qBACa,6BAA6B;IAGtC,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBADR,OAAO,EAAE,wBAAwB,EACjC,QAAQ,EAAE,yBAAyB;IAItD,MAAM;;;IAKA,KAAK;;;;;IAsBX,OAAO;;;;;;;;CAUR"}
package/dist/health.js ADDED
@@ -0,0 +1,81 @@
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 { Controller, Get, Inject, ServiceUnavailableException, } from '@nestjs/common';
14
+ import { OPENXIANGDA_CONTRACT_VERSION } from 'openxiangda-contracts';
15
+ import { OpenXiangdaPlatformClient } from './platform-client.js';
16
+ import { OPENXIANGDA_MODULE_OPTIONS } from './tokens.js';
17
+ let OpenXiangdaPlatformController = class OpenXiangdaPlatformController {
18
+ options;
19
+ platform;
20
+ constructor(options, platform) {
21
+ this.options = options;
22
+ this.platform = platform;
23
+ }
24
+ health() {
25
+ return { status: 'ok' };
26
+ }
27
+ async ready() {
28
+ try {
29
+ const capabilities = await this.platform.capabilities();
30
+ if (capabilities.contractVersion !== OPENXIANGDA_CONTRACT_VERSION) {
31
+ throw new Error(`contract mismatch: ${capabilities.contractVersion}`);
32
+ }
33
+ return {
34
+ status: 'ready',
35
+ platformVersion: capabilities.platformVersion,
36
+ contractVersion: capabilities.contractVersion,
37
+ };
38
+ }
39
+ catch (error) {
40
+ throw new ServiceUnavailableException({
41
+ status: 'not_ready',
42
+ reason: error?.message || 'platform unavailable',
43
+ });
44
+ }
45
+ }
46
+ version() {
47
+ return {
48
+ appCode: this.options.appCode,
49
+ environmentId: this.options.environmentId,
50
+ version: this.options.version,
51
+ gitSha: this.options.gitSha || null,
52
+ buildId: this.options.buildId || null,
53
+ contractVersion: OPENXIANGDA_CONTRACT_VERSION,
54
+ };
55
+ }
56
+ };
57
+ __decorate([
58
+ Get('health'),
59
+ __metadata("design:type", Function),
60
+ __metadata("design:paramtypes", []),
61
+ __metadata("design:returntype", void 0)
62
+ ], OpenXiangdaPlatformController.prototype, "health", null);
63
+ __decorate([
64
+ Get('ready'),
65
+ __metadata("design:type", Function),
66
+ __metadata("design:paramtypes", []),
67
+ __metadata("design:returntype", Promise)
68
+ ], OpenXiangdaPlatformController.prototype, "ready", null);
69
+ __decorate([
70
+ Get('version'),
71
+ __metadata("design:type", Function),
72
+ __metadata("design:paramtypes", []),
73
+ __metadata("design:returntype", void 0)
74
+ ], OpenXiangdaPlatformController.prototype, "version", null);
75
+ OpenXiangdaPlatformController = __decorate([
76
+ Controller('__platform'),
77
+ __param(0, Inject(OPENXIANGDA_MODULE_OPTIONS)),
78
+ __metadata("design:paramtypes", [Object, OpenXiangdaPlatformClient])
79
+ ], OpenXiangdaPlatformController);
80
+ export { OpenXiangdaPlatformController };
81
+ //# sourceMappingURL=health.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.js","sourceRoot":"","sources":["../src/health.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,UAAU,EACV,GAAG,EACH,MAAM,EACN,2BAA2B,GAC5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAIlD,IAAM,6BAA6B,GAAnC,MAAM,6BAA6B;IAGrB;IACA;IAHnB,YAEmB,OAAiC,EACjC,QAAmC;QADnC,YAAO,GAAP,OAAO,CAA0B;QACjC,aAAQ,GAAR,QAAQ,CAA2B;IACnD,CAAC;IAGJ,MAAM;QACJ,OAAO,EAAE,MAAM,EAAE,IAAa,EAAE,CAAC;IACnC,CAAC;IAGK,AAAN,KAAK,CAAC,KAAK;QACT,IAAI,CAAC;YACH,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,CAAC;YACxD,IAAI,YAAY,CAAC,eAAe,KAAK,4BAA4B,EAAE,CAAC;gBAClE,MAAM,IAAI,KAAK,CACb,sBAAsB,YAAY,CAAC,eAAe,EAAE,CACrD,CAAC;YACJ,CAAC;YACD,OAAO;gBACL,MAAM,EAAE,OAAgB;gBACxB,eAAe,EAAE,YAAY,CAAC,eAAe;gBAC7C,eAAe,EAAE,YAAY,CAAC,eAAe;aAC9C,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,2BAA2B,CAAC;gBACpC,MAAM,EAAE,WAAW;gBACnB,MAAM,EAAG,KAAe,EAAE,OAAO,IAAI,sBAAsB;aAC5D,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAGD,OAAO;QACL,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO;YAC7B,aAAa,EAAE,IAAI,CAAC,OAAO,CAAC,aAAa;YACzC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO;YAC7B,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,IAAI;YACnC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,IAAI;YACrC,eAAe,EAAE,4BAA4B;SAC9C,CAAC;IACJ,CAAC;CACF,CAAA;AArCC;IADC,GAAG,CAAC,QAAQ,CAAC;;;;2DAGb;AAGK;IADL,GAAG,CAAC,OAAO,CAAC;;;;0DAoBZ;AAGD;IADC,GAAG,CAAC,SAAS,CAAC;;;;4DAUd;AA5CU,6BAA6B;IADzC,UAAU,CAAC,YAAY,CAAC;IAGpB,WAAA,MAAM,CAAC,0BAA0B,CAAC,CAAA;6CAER,yBAAyB;GAJ3C,6BAA6B,CA6CzC"}
@@ -0,0 +1,12 @@
1
+ export * from './authz.js';
2
+ export * from './assignee-provider.js';
3
+ export * from './application-credentials.js';
4
+ export * from './data-api.js';
5
+ export * from './events.js';
6
+ export * from './health.js';
7
+ export * from './module.js';
8
+ export * from './platform-client.js';
9
+ export * from './tokens.js';
10
+ export * from './types.js';
11
+ export * from './workflow.js';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ export * from './authz.js';
2
+ export * from './assignee-provider.js';
3
+ export * from './application-credentials.js';
4
+ export * from './data-api.js';
5
+ export * from './events.js';
6
+ export * from './health.js';
7
+ export * from './module.js';
8
+ export * from './platform-client.js';
9
+ export * from './tokens.js';
10
+ export * from './types.js';
11
+ export * from './workflow.js';
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+ import type { OpenXiangdaModuleOptions } from './types.js';
3
+ export declare class OpenXiangdaModule {
4
+ static forRoot(options: OpenXiangdaModuleOptions): DynamicModule;
5
+ }
6
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAkB,MAAM,gBAAgB,CAAC;AAwB/D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAE3D,qBAEa,iBAAiB;IAC5B,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,wBAAwB,GAAG,aAAa;CA2CjE"}
package/dist/module.js ADDED
@@ -0,0 +1,106 @@
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 OpenXiangdaModule_1;
8
+ import { Global, Module } from '@nestjs/common';
9
+ import { DiscoveryModule } from '@nestjs/core';
10
+ import { OpenXiangdaAssigneeProviderController, OpenXiangdaAssigneeProviderReceiver, OpenXiangdaAssigneeProviderRegistry, } from './assignee-provider.js';
11
+ import { OpenXiangdaApplicationCredentials } from './application-credentials.js';
12
+ import { OpenXiangdaAuthzGuard } from './authz.js';
13
+ import { OpenXiangdaApplicationDataApiService, OpenXiangdaDataApiService, } from './data-api.js';
14
+ import { OpenXiangdaPlatformController } from './health.js';
15
+ import { OpenXiangdaEventReceiver, PlatformOpenXiangdaEventReceiptStore, } from './events.js';
16
+ import { OpenXiangdaPlatformClient } from './platform-client.js';
17
+ import { OpenXiangdaWorkflowService } from './workflow.js';
18
+ import { OPENXIANGDA_EVENT_RECEIPT_STORE, OPENXIANGDA_MODULE_OPTIONS, } from './tokens.js';
19
+ let OpenXiangdaModule = OpenXiangdaModule_1 = class OpenXiangdaModule {
20
+ static forRoot(options) {
21
+ validateOptions(options);
22
+ return {
23
+ module: OpenXiangdaModule_1,
24
+ global: true,
25
+ imports: [DiscoveryModule],
26
+ controllers: [
27
+ OpenXiangdaPlatformController,
28
+ OpenXiangdaAssigneeProviderController,
29
+ ],
30
+ providers: [
31
+ { provide: OPENXIANGDA_MODULE_OPTIONS, useValue: Object.freeze(options) },
32
+ {
33
+ provide: OPENXIANGDA_EVENT_RECEIPT_STORE,
34
+ useValue: options.eventReceiptStore ||
35
+ new PlatformOpenXiangdaEventReceiptStore(options),
36
+ },
37
+ OpenXiangdaPlatformClient,
38
+ OpenXiangdaApplicationCredentials,
39
+ OpenXiangdaAuthzGuard,
40
+ OpenXiangdaDataApiService,
41
+ OpenXiangdaApplicationDataApiService,
42
+ OpenXiangdaEventReceiver,
43
+ OpenXiangdaWorkflowService,
44
+ OpenXiangdaAssigneeProviderReceiver,
45
+ OpenXiangdaAssigneeProviderRegistry,
46
+ ],
47
+ exports: [
48
+ OPENXIANGDA_MODULE_OPTIONS,
49
+ OpenXiangdaPlatformClient,
50
+ OpenXiangdaApplicationCredentials,
51
+ OpenXiangdaAuthzGuard,
52
+ OpenXiangdaDataApiService,
53
+ OpenXiangdaApplicationDataApiService,
54
+ OpenXiangdaEventReceiver,
55
+ OpenXiangdaWorkflowService,
56
+ OpenXiangdaAssigneeProviderReceiver,
57
+ OpenXiangdaAssigneeProviderRegistry,
58
+ OPENXIANGDA_EVENT_RECEIPT_STORE,
59
+ ],
60
+ };
61
+ }
62
+ };
63
+ OpenXiangdaModule = OpenXiangdaModule_1 = __decorate([
64
+ Global(),
65
+ Module({})
66
+ ], OpenXiangdaModule);
67
+ export { OpenXiangdaModule };
68
+ function validateOptions(options) {
69
+ for (const key of [
70
+ 'appCode',
71
+ 'platformBaseUrl',
72
+ 'environmentId',
73
+ 'version',
74
+ ]) {
75
+ if (!String(options?.[key] || '').trim()) {
76
+ throw new Error(`OpenXiangdaModule.${key} 不能为空`);
77
+ }
78
+ }
79
+ let url;
80
+ try {
81
+ url = new URL(options.platformBaseUrl);
82
+ }
83
+ catch {
84
+ throw new Error('OpenXiangdaModule.platformBaseUrl 必须是有效 URL');
85
+ }
86
+ if (!['http:', 'https:'].includes(url.protocol)) {
87
+ throw new Error('OpenXiangdaModule.platformBaseUrl 只允许 HTTP(S)');
88
+ }
89
+ if (options.oauthClient) {
90
+ if (!String(options.oauthClient.clientId || '').trim()) {
91
+ throw new Error('OpenXiangdaModule.oauthClient.clientId 不能为空');
92
+ }
93
+ if (!String(options.oauthClient.clientSecret || '')) {
94
+ throw new Error('OpenXiangdaModule.oauthClient.clientSecret 不能为空');
95
+ }
96
+ if (String(options.oauthClient.clientId).includes(':')) {
97
+ throw new Error('OpenXiangdaModule.oauthClient.clientId 不能包含冒号');
98
+ }
99
+ for (const scope of options.oauthClient.scopes || []) {
100
+ if (!/^[A-Za-z0-9*._:-]+$/.test(String(scope))) {
101
+ throw new Error('OpenXiangdaModule.oauthClient.scopes 包含非法 scope');
102
+ }
103
+ }
104
+ }
105
+ }
106
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.js","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":";;;;;;;AAAA,OAAO,EAAiB,MAAM,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EACL,qCAAqC,EACrC,mCAAmC,EACnC,mCAAmC,GACpC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,iCAAiC,EAAE,MAAM,8BAA8B,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EACL,oCAAoC,EACpC,yBAAyB,GAC1B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,6BAA6B,EAAE,MAAM,aAAa,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AAW,CAAC,MAAM,IAAI,EAAE,EAAE,CAAC;YACrD,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;gBAC/C,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;YACrE,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,101 @@
1
+ import { HttpException } from "@nestjs/common";
2
+ import type { AuthorizationDecision, DataPage, DataAggregatePage, DataAggregateQuery, DataAuditPage, DataFileRef, DataFileUploadPlan, DataQuery, DataRecord, DataTransactionRequest, DataTransactionResult, PlatformCapabilities, WorkflowCommand, WorkflowDelegation, WorkflowInstance, WorkflowKernelDescriptor, WorkflowKernelWorkCenter, WorkflowPreparation, WorkflowSurface, WorkflowTask } from "openxiangda-contracts";
3
+ import type { OpenXiangdaModuleOptions, PlatformApplicationPrincipalResult, PlatformPrincipalResult } from "./types.js";
4
+ export declare class OpenXiangdaPlatformError extends HttpException {
5
+ readonly httpStatus: number;
6
+ readonly code: string;
7
+ readonly data?: unknown | undefined;
8
+ constructor(httpStatus: number, code: string, message: string, data?: unknown | undefined);
9
+ }
10
+ export declare class OpenXiangdaPlatformClient {
11
+ private readonly options;
12
+ private readonly baseUrl;
13
+ private readonly fetch;
14
+ constructor(options: OpenXiangdaModuleOptions);
15
+ capabilities(): Promise<PlatformCapabilities>;
16
+ verifyPrincipal(authorization: string, roleSessionId: string): Promise<PlatformPrincipalResult>;
17
+ verifyApplicationPrincipal(authorization: string): Promise<PlatformApplicationPrincipalResult>;
18
+ authorize(authorization: string, roleSessionId: string, input: {
19
+ capability: string;
20
+ dataPolicyCode?: string;
21
+ operation?: string;
22
+ data?: Record<string, unknown>;
23
+ }): Promise<AuthorizationDecision>;
24
+ queryData<T extends Record<string, unknown>>(authorization: string, roleSessionId: string | null, resourceCode: string, query: DataQuery): Promise<DataPage<T>>;
25
+ getData<T extends Record<string, unknown>>(authorization: string, roleSessionId: string | null, resourceCode: string, id: string): Promise<DataRecord<T>>;
26
+ aggregateData<T extends Record<string, unknown>>(authorization: string, roleSessionId: string | null, resourceCode: string, query: DataAggregateQuery): Promise<DataAggregatePage<T>>;
27
+ dataAudit(authorization: string, roleSessionId: string | null, resourceCode: string, id: string, input?: {
28
+ limit?: number;
29
+ offset?: number;
30
+ }): Promise<DataAuditPage>;
31
+ initiateDataFileUpload(authorization: string, roleSessionId: string | null, resourceCode: string, input: {
32
+ fieldCode: string;
33
+ fileName: string;
34
+ fileSize: number;
35
+ contentType?: string;
36
+ recordId?: string;
37
+ }): Promise<DataFileUploadPlan>;
38
+ completeDataFileUpload(authorization: string, roleSessionId: string | null, resourceCode: string, fileId: string): Promise<DataFileRef>;
39
+ createData<T extends Record<string, unknown>>(authorization: string, roleSessionId: string | null, resourceCode: string, data: Record<string, unknown>): Promise<DataRecord<T>>;
40
+ updateData<T extends Record<string, unknown>>(authorization: string, roleSessionId: string | null, resourceCode: string, id: string, input: {
41
+ expectedRevision: number;
42
+ data: Record<string, unknown>;
43
+ }): Promise<DataRecord<T>>;
44
+ deleteData<T extends Record<string, unknown>>(authorization: string, roleSessionId: string | null, resourceCode: string, id: string, expectedRevision: number): Promise<DataRecord<T>>;
45
+ transactData(authorization: string, roleSessionId: string | null, transaction: DataTransactionRequest): Promise<DataTransactionResult>;
46
+ prepareWorkflowStart(authorization: string, roleSessionId: string, workflowCode: string, input: {
47
+ environmentKey?: string;
48
+ businessKey: string;
49
+ dataRef: Record<string, unknown>;
50
+ facts: Record<string, unknown>;
51
+ answers?: Record<string, unknown>;
52
+ }): Promise<WorkflowPreparation>;
53
+ startWorkflow(authorization: string, roleSessionId: string, input: {
54
+ preparationToken: string;
55
+ idempotencyKey: string;
56
+ }): Promise<WorkflowInstance>;
57
+ createWorkflowDelegation(authorization: string, roleSessionId: string, input: {
58
+ workflowCode?: string;
59
+ delegateUserId: string;
60
+ delegateRoleAssignmentId: string;
61
+ validFrom: string;
62
+ validTo: string;
63
+ reason: string;
64
+ }): Promise<WorkflowDelegation>;
65
+ workflowDelegations(authorization: string, roleSessionId: string, input?: {
66
+ all?: boolean;
67
+ }): Promise<{
68
+ items: WorkflowDelegation[];
69
+ total: number;
70
+ }>;
71
+ revokeWorkflowDelegation(authorization: string, roleSessionId: string, delegationId: string): Promise<WorkflowDelegation>;
72
+ workflowTaskSurface(authorization: string, roleSessionId: string, taskId: string): Promise<WorkflowSurface>;
73
+ executeWorkflowTaskCommand(authorization: string, roleSessionId: string, taskId: string, command: WorkflowCommand, input: {
74
+ expectedTaskVersion: number;
75
+ expectedInstanceVersion: number;
76
+ idempotencyKey: string;
77
+ input?: Record<string, unknown>;
78
+ }): Promise<Record<string, unknown>>;
79
+ executeWorkflowInstanceCommand(authorization: string, roleSessionId: string, instanceId: string, command: "withdraw" | "terminate", input: {
80
+ expectedInstanceVersion: number;
81
+ idempotencyKey: string;
82
+ reason: string;
83
+ }): Promise<Record<string, unknown>>;
84
+ workflowWorkCenter(authorization: string, roleSessionId: string, input?: {
85
+ status?: "pending" | "completed";
86
+ limit?: number;
87
+ }): Promise<{
88
+ items: WorkflowTask[];
89
+ }>;
90
+ workflowKernelInstance(authorization: string, roleSessionId: string, instanceId: string): Promise<WorkflowKernelDescriptor>;
91
+ workflowKernelWorkCenter(authorization: string, roleSessionId: string, input?: {
92
+ category?: "pending" | "completed" | "created";
93
+ limit?: number;
94
+ }): Promise<WorkflowKernelWorkCenter>;
95
+ private authzPath;
96
+ private dataPath;
97
+ private workflowPath;
98
+ private identityHeaders;
99
+ private request;
100
+ }
101
+ //# sourceMappingURL=platform-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform-client.d.ts","sourceRoot":"","sources":["../src/platform-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAsB,MAAM,gBAAgB,CAAC;AACnE,OAAO,KAAK,EACV,qBAAqB,EACrB,QAAQ,EACR,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,WAA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IAMpB,OAAO,CAAC,eAAe;YAYT,OAAO;CAqDtB"}
@@ -0,0 +1,250 @@
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 { HttpException, Inject, Injectable } from "@nestjs/common";
14
+ import { OPENXIANGDA_MODULE_OPTIONS } from "./tokens.js";
15
+ export class OpenXiangdaPlatformError extends HttpException {
16
+ httpStatus;
17
+ code;
18
+ data;
19
+ constructor(httpStatus, code, message, data) {
20
+ super({
21
+ statusCode: httpStatus,
22
+ code,
23
+ message,
24
+ ...(data === undefined ? {} : { data }),
25
+ }, httpStatus);
26
+ this.httpStatus = httpStatus;
27
+ this.code = code;
28
+ this.data = data;
29
+ this.name = "OpenXiangdaPlatformError";
30
+ }
31
+ }
32
+ let OpenXiangdaPlatformClient = class OpenXiangdaPlatformClient {
33
+ options;
34
+ baseUrl;
35
+ fetch;
36
+ constructor(options) {
37
+ this.options = options;
38
+ this.baseUrl = options.platformBaseUrl.replace(/\/+$/, "");
39
+ this.fetch = options.fetch || globalThis.fetch.bind(globalThis);
40
+ }
41
+ async capabilities() {
42
+ return await this.request("/openxiangda-api/v2/capabilities");
43
+ }
44
+ async verifyPrincipal(authorization, roleSessionId) {
45
+ return await this.request(`${this.authzPath()}/principal`, { headers: this.identityHeaders(authorization, roleSessionId) });
46
+ }
47
+ async verifyApplicationPrincipal(authorization) {
48
+ return await this.request(`/openxiangda-api/v2/applications/${encodeURIComponent(this.options.appCode)}/oauth2/principal`, { headers: this.identityHeaders(authorization) });
49
+ }
50
+ async authorize(authorization, roleSessionId, input) {
51
+ return await this.request(`${this.authzPath()}/explain`, {
52
+ method: "POST",
53
+ headers: this.identityHeaders(authorization, roleSessionId),
54
+ body: JSON.stringify({ ...input, roleSessionId }),
55
+ });
56
+ }
57
+ async queryData(authorization, roleSessionId, resourceCode, query) {
58
+ return await this.request(this.dataPath(resourceCode, "query"), {
59
+ method: "POST",
60
+ headers: this.identityHeaders(authorization, roleSessionId),
61
+ body: JSON.stringify(query),
62
+ });
63
+ }
64
+ async getData(authorization, roleSessionId, resourceCode, id) {
65
+ return await this.request(this.dataPath(resourceCode, `records/${encodeURIComponent(id)}`), { headers: this.identityHeaders(authorization, roleSessionId) });
66
+ }
67
+ async aggregateData(authorization, roleSessionId, resourceCode, query) {
68
+ return await this.request(this.dataPath(resourceCode, "aggregate"), {
69
+ method: "POST",
70
+ headers: this.identityHeaders(authorization, roleSessionId),
71
+ body: JSON.stringify(query),
72
+ });
73
+ }
74
+ async dataAudit(authorization, roleSessionId, resourceCode, id, input = {}) {
75
+ const query = new URLSearchParams();
76
+ if (input.limit !== undefined)
77
+ query.set("limit", String(input.limit));
78
+ if (input.offset !== undefined)
79
+ query.set("offset", String(input.offset));
80
+ const suffix = query.size ? `?${query}` : "";
81
+ return await this.request(`${this.dataPath(resourceCode, `records/${encodeURIComponent(id)}/audit`)}${suffix}`, { headers: this.identityHeaders(authorization, roleSessionId) });
82
+ }
83
+ async initiateDataFileUpload(authorization, roleSessionId, resourceCode, input) {
84
+ return await this.request(this.dataPath(resourceCode, "files/uploads/initiate"), {
85
+ method: "POST",
86
+ headers: this.identityHeaders(authorization, roleSessionId),
87
+ body: JSON.stringify(input),
88
+ });
89
+ }
90
+ async completeDataFileUpload(authorization, roleSessionId, resourceCode, fileId) {
91
+ return await this.request(this.dataPath(resourceCode, `files/${encodeURIComponent(fileId)}/complete`), {
92
+ method: "POST",
93
+ headers: this.identityHeaders(authorization, roleSessionId),
94
+ body: "{}",
95
+ });
96
+ }
97
+ async createData(authorization, roleSessionId, resourceCode, data) {
98
+ return await this.request(this.dataPath(resourceCode, "records"), {
99
+ method: "POST",
100
+ headers: this.identityHeaders(authorization, roleSessionId),
101
+ body: JSON.stringify({ data }),
102
+ });
103
+ }
104
+ async updateData(authorization, roleSessionId, resourceCode, id, input) {
105
+ return await this.request(this.dataPath(resourceCode, `records/${encodeURIComponent(id)}/update`), {
106
+ method: "POST",
107
+ headers: this.identityHeaders(authorization, roleSessionId),
108
+ body: JSON.stringify(input),
109
+ });
110
+ }
111
+ async deleteData(authorization, roleSessionId, resourceCode, id, expectedRevision) {
112
+ return await this.request(this.dataPath(resourceCode, `records/${encodeURIComponent(id)}/delete`), {
113
+ method: "POST",
114
+ headers: this.identityHeaders(authorization, roleSessionId),
115
+ body: JSON.stringify({ expectedRevision }),
116
+ });
117
+ }
118
+ async transactData(authorization, roleSessionId, transaction) {
119
+ return await this.request(`/openxiangda-api/v2/applications/${encodeURIComponent(this.options.appCode)}/data/transactions`, {
120
+ method: "POST",
121
+ headers: this.identityHeaders(authorization, roleSessionId),
122
+ body: JSON.stringify(transaction),
123
+ });
124
+ }
125
+ async prepareWorkflowStart(authorization, roleSessionId, workflowCode, input) {
126
+ return await this.request(`${this.workflowPath()}/definitions/${encodeURIComponent(workflowCode)}/prepare-start`, {
127
+ method: "POST",
128
+ headers: this.identityHeaders(authorization, roleSessionId),
129
+ body: JSON.stringify(input),
130
+ });
131
+ }
132
+ async startWorkflow(authorization, roleSessionId, input) {
133
+ return await this.request(`${this.workflowPath()}/instances`, {
134
+ method: "POST",
135
+ headers: this.identityHeaders(authorization, roleSessionId),
136
+ body: JSON.stringify(input),
137
+ });
138
+ }
139
+ async createWorkflowDelegation(authorization, roleSessionId, input) {
140
+ return await this.request(`${this.workflowPath()}/delegations`, {
141
+ method: "POST",
142
+ headers: this.identityHeaders(authorization, roleSessionId),
143
+ body: JSON.stringify(input),
144
+ });
145
+ }
146
+ async workflowDelegations(authorization, roleSessionId, input = {}) {
147
+ return await this.request(`${this.workflowPath()}/delegations?all=${input.all === true}`, { headers: this.identityHeaders(authorization, roleSessionId) });
148
+ }
149
+ async revokeWorkflowDelegation(authorization, roleSessionId, delegationId) {
150
+ return await this.request(`${this.workflowPath()}/delegations/${encodeURIComponent(delegationId)}/revoke`, {
151
+ method: "POST",
152
+ headers: this.identityHeaders(authorization, roleSessionId),
153
+ });
154
+ }
155
+ async workflowTaskSurface(authorization, roleSessionId, taskId) {
156
+ return await this.request(`${this.workflowPath()}/tasks/${encodeURIComponent(taskId)}/surface`, { headers: this.identityHeaders(authorization, roleSessionId) });
157
+ }
158
+ async executeWorkflowTaskCommand(authorization, roleSessionId, taskId, command, input) {
159
+ return await this.request(`${this.workflowPath()}/tasks/${encodeURIComponent(taskId)}/commands/${encodeURIComponent(command)}`, {
160
+ method: "POST",
161
+ headers: this.identityHeaders(authorization, roleSessionId),
162
+ body: JSON.stringify(input),
163
+ });
164
+ }
165
+ async executeWorkflowInstanceCommand(authorization, roleSessionId, instanceId, command, input) {
166
+ return await this.request(`${this.workflowPath()}/instances/${encodeURIComponent(instanceId)}/commands/${command}`, {
167
+ method: "POST",
168
+ headers: this.identityHeaders(authorization, roleSessionId),
169
+ body: JSON.stringify(input),
170
+ });
171
+ }
172
+ async workflowWorkCenter(authorization, roleSessionId, input = {}) {
173
+ const query = new URLSearchParams({
174
+ status: input.status || "pending",
175
+ limit: String(Math.min(Math.max(Number(input.limit) || 50, 1), 200)),
176
+ });
177
+ return await this.request(`${this.workflowPath()}/work-center/items?${query}`, { headers: this.identityHeaders(authorization, roleSessionId) });
178
+ }
179
+ async workflowKernelInstance(authorization, roleSessionId, instanceId) {
180
+ return await this.request(`${this.workflowPath()}/kernel/instances/${encodeURIComponent(instanceId)}`, { headers: this.identityHeaders(authorization, roleSessionId) });
181
+ }
182
+ async workflowKernelWorkCenter(authorization, roleSessionId, input = {}) {
183
+ const query = new URLSearchParams({
184
+ category: input.category || "pending",
185
+ limit: String(Math.min(Math.max(Number(input.limit) || 50, 1), 200)),
186
+ });
187
+ return await this.request(`${this.workflowPath()}/kernel/work-center?${query}`, { headers: this.identityHeaders(authorization, roleSessionId) });
188
+ }
189
+ authzPath() {
190
+ return `/openxiangda-api/v2/applications/${encodeURIComponent(this.options.appCode)}/authz`;
191
+ }
192
+ dataPath(resourceCode, suffix) {
193
+ return `/openxiangda-api/v2/applications/${encodeURIComponent(this.options.appCode)}/data/${encodeURIComponent(resourceCode)}/${suffix}`;
194
+ }
195
+ workflowPath() {
196
+ return `/openxiangda-api/v2/applications/${encodeURIComponent(this.options.appCode)}/workflow`;
197
+ }
198
+ identityHeaders(authorization, roleSessionId) {
199
+ return {
200
+ Authorization: authorization,
201
+ ...(roleSessionId
202
+ ? { "X-OpenXiangda-Role-Session-Id": roleSessionId }
203
+ : {}),
204
+ };
205
+ }
206
+ async request(path, init = {}) {
207
+ const controller = new AbortController();
208
+ const timeout = setTimeout(() => controller.abort(), this.options.requestTimeoutMs || 5000);
209
+ try {
210
+ const response = await this.fetch(`${this.baseUrl}${path}`, {
211
+ ...init,
212
+ signal: controller.signal,
213
+ headers: {
214
+ Accept: "application/json",
215
+ ...(init.body ? { "Content-Type": "application/json" } : {}),
216
+ ...(init.headers || {}),
217
+ },
218
+ });
219
+ let envelope;
220
+ try {
221
+ envelope = (await response.json());
222
+ }
223
+ catch {
224
+ throw new OpenXiangdaPlatformError(response.status, "PLATFORM_RESPONSE_INVALID", "OpenXiangda 平台返回的不是有效 JSON");
225
+ }
226
+ if (!response.ok || Number(envelope.code) >= 400) {
227
+ throw new OpenXiangdaPlatformError(response.status, envelope.errorCode || "PLATFORM_REQUEST_FAILED", envelope.message || `OpenXiangda 平台请求失败: ${response.status}`, envelope.data);
228
+ }
229
+ return envelope.data;
230
+ }
231
+ catch (error) {
232
+ if (error instanceof OpenXiangdaPlatformError)
233
+ throw error;
234
+ if (error?.name === "AbortError") {
235
+ throw new OpenXiangdaPlatformError(504, "PLATFORM_REQUEST_TIMEOUT", "OpenXiangda 平台请求超时");
236
+ }
237
+ throw new OpenXiangdaPlatformError(503, "PLATFORM_UNAVAILABLE", error?.message || "OpenXiangda 平台不可用");
238
+ }
239
+ finally {
240
+ clearTimeout(timeout);
241
+ }
242
+ }
243
+ };
244
+ OpenXiangdaPlatformClient = __decorate([
245
+ Injectable(),
246
+ __param(0, Inject(OPENXIANGDA_MODULE_OPTIONS)),
247
+ __metadata("design:paramtypes", [Object])
248
+ ], OpenXiangdaPlatformClient);
249
+ export { OpenXiangdaPlatformClient };
250
+ //# sourceMappingURL=platform-client.js.map