@tier0/sdk-v2 0.9.10 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +96 -0
- package/LICENSE +21 -21
- package/README.md +160 -24
- package/dist/cjs/client.d.ts +79 -3
- package/dist/cjs/client.js +4 -6
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/cloud-server.d.ts +33 -26
- package/dist/cjs/cloud-server.js +102 -100
- package/dist/cjs/cloud-server.js.map +1 -1
- package/dist/cjs/cloud-transport.d.ts +15 -20
- package/dist/cjs/cloud-transport.js +87 -68
- package/dist/cjs/cloud-transport.js.map +1 -1
- package/dist/cjs/data/bootstrap.js +3 -4
- package/dist/cjs/data/bootstrap.js.map +1 -1
- package/dist/cjs/data/call.d.ts +1 -3
- package/dist/cjs/data/call.js +8 -12
- package/dist/cjs/data/call.js.map +1 -1
- package/dist/cjs/data/client.d.ts +8 -7
- package/dist/cjs/data/client.js +24 -11
- package/dist/cjs/data/client.js.map +1 -1
- package/dist/cjs/data/collection.d.ts +3 -5
- package/dist/cjs/data/collection.js +3 -4
- package/dist/cjs/data/collection.js.map +1 -1
- package/dist/cjs/data/context.d.ts +5 -11
- package/dist/cjs/data/context.js +21 -36
- package/dist/cjs/data/context.js.map +1 -1
- package/dist/cjs/data/error.js +1 -1
- package/dist/cjs/data/error.js.map +1 -1
- package/dist/cjs/data/index.d.ts +5 -3
- package/dist/cjs/data/index.js +5 -5
- package/dist/cjs/data/index.js.map +1 -1
- package/dist/cjs/data/relay.d.ts +51 -0
- package/dist/cjs/data/relay.js +371 -0
- package/dist/cjs/data/relay.js.map +1 -0
- package/dist/cjs/data/subscribe.d.ts +22 -38
- package/dist/cjs/data/subscribe.js +22 -28
- package/dist/cjs/data/subscribe.js.map +1 -1
- package/dist/cjs/event-stream.d.ts +28 -0
- package/dist/cjs/event-stream.js +222 -0
- package/dist/cjs/event-stream.js.map +1 -0
- package/dist/cjs/mq/client.d.ts +32 -1
- package/dist/cjs/mq/client.js +404 -69
- package/dist/cjs/mq/client.js.map +1 -1
- package/dist/cjs/mq/index.d.ts +1 -0
- package/dist/cjs/mq/index.js +3 -1
- package/dist/cjs/mq/index.js.map +1 -1
- package/dist/cjs/mq/topic.d.ts +29 -0
- package/dist/cjs/mq/topic.js +48 -0
- package/dist/cjs/mq/topic.js.map +1 -0
- package/dist/cjs/mq/types.d.ts +21 -1
- package/dist/cjs/mq/types.js.map +1 -1
- package/dist/cjs/openapi/api.generated.d.ts +20 -0
- package/dist/cjs/openapi/api.generated.js +11 -0
- package/dist/cjs/openapi/api.generated.js.map +1 -1
- package/dist/cjs/openapi/client.d.ts +46 -0
- package/dist/cjs/openapi/client.js +158 -10
- package/dist/cjs/openapi/client.js.map +1 -1
- package/dist/cjs/openapi/codecs.generated.d.ts +74 -0
- package/dist/cjs/openapi/codecs.generated.js +1 -1
- package/dist/cjs/openapi/codecs.generated.js.map +1 -1
- package/dist/cjs/openapi/types.generated.d.ts +205 -1
- package/dist/cjs/openapi/types.generated.js.map +1 -1
- package/dist/cjs/page-runtime.d.ts +48 -0
- package/dist/cjs/page-runtime.js +74 -0
- package/dist/cjs/page-runtime.js.map +1 -0
- package/dist/cjs/platform-proxy.d.ts +17 -0
- package/dist/cjs/platform-proxy.js +52 -0
- package/dist/cjs/platform-proxy.js.map +1 -0
- package/dist/cjs/runtime-context.d.ts +2 -1
- package/dist/cjs/runtime-context.js +6 -2
- package/dist/cjs/runtime-context.js.map +1 -1
- package/dist/cjs/runtime-env.js.map +1 -1
- package/dist/cjs/source.d.ts +19 -1
- package/dist/cjs/source.js +9 -3
- package/dist/cjs/source.js.map +1 -1
- package/dist/cjs/stream.js +3 -2
- package/dist/cjs/stream.js.map +1 -1
- package/dist/cjs/streams/contract.generated.d.ts +7 -1
- package/dist/cjs/streams/contract.generated.js.map +1 -1
- package/dist/cjs/streams/messages.js +1 -10
- package/dist/cjs/streams/messages.js.map +1 -1
- package/dist/cjs/streams/requests.d.ts +3 -0
- package/dist/cjs/streams/requests.js +5 -2
- package/dist/cjs/streams/requests.js.map +1 -1
- package/dist/cjs/streams/transport.d.ts +1 -13
- package/dist/cjs/streams/transport.js +2 -18
- package/dist/cjs/streams/transport.js.map +1 -1
- package/dist/cjs/uns-v2/client.d.ts +1 -6
- package/dist/cjs/uns-v2/client.js +30 -6
- package/dist/cjs/uns-v2/client.js.map +1 -1
- package/dist/cjs/uns-v2/data-client.d.ts +5 -2
- package/dist/cjs/uns-v2/data-client.js +7 -4
- package/dist/cjs/uns-v2/data-client.js.map +1 -1
- package/dist/cjs/uns-v2/generated.d.ts +6783 -4655
- package/dist/cjs/uns-v2/generated.js +221 -65
- package/dist/cjs/uns-v2/generated.js.map +1 -1
- package/dist/cjs/uns-v2/sse.d.ts +7 -1
- package/dist/cjs/uns-v2/sse.js +12 -2
- package/dist/cjs/uns-v2/sse.js.map +1 -1
- package/dist/esm/client.d.ts +79 -3
- package/dist/esm/client.js +5 -7
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/cloud-server.d.ts +33 -26
- package/dist/esm/cloud-server.js +99 -97
- package/dist/esm/cloud-server.js.map +1 -1
- package/dist/esm/cloud-transport.d.ts +15 -20
- package/dist/esm/cloud-transport.js +86 -67
- package/dist/esm/cloud-transport.js.map +1 -1
- package/dist/esm/data/bootstrap.js +3 -4
- package/dist/esm/data/bootstrap.js.map +1 -1
- package/dist/esm/data/call.d.ts +1 -3
- package/dist/esm/data/call.js +9 -13
- package/dist/esm/data/call.js.map +1 -1
- package/dist/esm/data/client.d.ts +8 -7
- package/dist/esm/data/client.js +22 -9
- package/dist/esm/data/client.js.map +1 -1
- package/dist/esm/data/collection.d.ts +3 -5
- package/dist/esm/data/collection.js +3 -4
- package/dist/esm/data/collection.js.map +1 -1
- package/dist/esm/data/context.d.ts +5 -11
- package/dist/esm/data/context.js +19 -33
- package/dist/esm/data/context.js.map +1 -1
- package/dist/esm/data/error.js +1 -1
- package/dist/esm/data/error.js.map +1 -1
- package/dist/esm/data/index.d.ts +5 -3
- package/dist/esm/data/index.js +3 -2
- package/dist/esm/data/index.js.map +1 -1
- package/dist/esm/data/relay.d.ts +51 -0
- package/dist/esm/data/relay.js +368 -0
- package/dist/esm/data/relay.js.map +1 -0
- package/dist/esm/data/subscribe.d.ts +22 -38
- package/dist/esm/data/subscribe.js +22 -27
- package/dist/esm/data/subscribe.js.map +1 -1
- package/dist/esm/event-stream.d.ts +28 -0
- package/dist/esm/event-stream.js +217 -0
- package/dist/esm/event-stream.js.map +1 -0
- package/dist/esm/mq/client.d.ts +32 -1
- package/dist/esm/mq/client.js +404 -69
- package/dist/esm/mq/client.js.map +1 -1
- package/dist/esm/mq/index.d.ts +1 -0
- package/dist/esm/mq/index.js +1 -0
- package/dist/esm/mq/index.js.map +1 -1
- package/dist/esm/mq/topic.d.ts +29 -0
- package/dist/esm/mq/topic.js +44 -0
- package/dist/esm/mq/topic.js.map +1 -0
- package/dist/esm/mq/types.d.ts +21 -1
- package/dist/esm/mq/types.js.map +1 -1
- package/dist/esm/openapi/api.generated.d.ts +20 -0
- package/dist/esm/openapi/api.generated.js +11 -0
- package/dist/esm/openapi/api.generated.js.map +1 -1
- package/dist/esm/openapi/client.d.ts +46 -0
- package/dist/esm/openapi/client.js +157 -10
- package/dist/esm/openapi/client.js.map +1 -1
- package/dist/esm/openapi/codecs.generated.d.ts +74 -0
- package/dist/esm/openapi/codecs.generated.js +1 -1
- package/dist/esm/openapi/codecs.generated.js.map +1 -1
- package/dist/esm/openapi/types.generated.d.ts +205 -1
- package/dist/esm/openapi/types.generated.js.map +1 -1
- package/dist/esm/page-runtime.d.ts +48 -0
- package/dist/esm/page-runtime.js +65 -0
- package/dist/esm/page-runtime.js.map +1 -0
- package/dist/esm/platform-proxy.d.ts +17 -0
- package/dist/esm/platform-proxy.js +47 -0
- package/dist/esm/platform-proxy.js.map +1 -0
- package/dist/esm/runtime-context.d.ts +2 -1
- package/dist/esm/runtime-context.js +6 -2
- package/dist/esm/runtime-context.js.map +1 -1
- package/dist/esm/runtime-env.js.map +1 -1
- package/dist/esm/source.d.ts +19 -1
- package/dist/esm/source.js +10 -4
- package/dist/esm/source.js.map +1 -1
- package/dist/esm/stream.js +4 -3
- package/dist/esm/stream.js.map +1 -1
- package/dist/esm/streams/contract.generated.d.ts +7 -1
- package/dist/esm/streams/contract.generated.js.map +1 -1
- package/dist/esm/streams/messages.js +1 -10
- package/dist/esm/streams/messages.js.map +1 -1
- package/dist/esm/streams/requests.d.ts +3 -0
- package/dist/esm/streams/requests.js +5 -2
- package/dist/esm/streams/requests.js.map +1 -1
- package/dist/esm/streams/transport.d.ts +1 -13
- package/dist/esm/streams/transport.js +1 -17
- package/dist/esm/streams/transport.js.map +1 -1
- package/dist/esm/uns-v2/client.d.ts +1 -6
- package/dist/esm/uns-v2/client.js +30 -6
- package/dist/esm/uns-v2/client.js.map +1 -1
- package/dist/esm/uns-v2/data-client.d.ts +5 -2
- package/dist/esm/uns-v2/data-client.js +8 -5
- package/dist/esm/uns-v2/data-client.js.map +1 -1
- package/dist/esm/uns-v2/generated.d.ts +6783 -4655
- package/dist/esm/uns-v2/generated.js +221 -65
- package/dist/esm/uns-v2/generated.js.map +1 -1
- package/dist/esm/uns-v2/sse.d.ts +7 -1
- package/dist/esm/uns-v2/sse.js +12 -2
- package/dist/esm/uns-v2/sse.js.map +1 -1
- package/package.json +25 -12
- package/skills/tier0-sdk-v2/SKILL.md +11 -5
- package/skills/tier0-sdk-v2/references/integration.md +14 -24
- package/skills/tier0-sdk-v2/tier0-sdk-v2-data/SKILL.md +11 -5
- package/skills/tier0-sdk-v2/tier0-sdk-v2-data/references/consistency.md +6 -10
- package/skills/tier0-sdk-v2/tier0-sdk-v2-data/references/errors.md +20 -3
- package/skills/tier0-sdk-v2/tier0-sdk-v2-data/references/read-write.md +46 -13
- package/skills/tier0-sdk-v2/tier0-sdk-v2-members/SKILL.md +2 -2
- package/skills/tier0-sdk-v2/tier0-sdk-v2-members/references/app-members.md +5 -1
- package/skills/tier0-sdk-v2/tier0-sdk-v2-mq/SKILL.md +25 -0
- package/skills/tier0-sdk-v2/tier0-sdk-v2-mq/references/quickstart.md +1 -1
- package/skills/tier0-sdk-v2/tier0-sdk-v2-notifications/SKILL.md +3 -3
- package/skills/tier0-sdk-v2/tier0-sdk-v2-notifications/references/send.md +6 -6
- package/skills/tier0-sdk-v2/tier0-sdk-v2-source/SKILL.md +4 -4
- package/skills/tier0-sdk-v2/tier0-sdk-v2-source/references/changes.md +2 -2
- package/skills/tier0-sdk-v2/tier0-sdk-v2-source/references/create.md +26 -36
- package/skills/tier0-sdk-v2/tier0-sdk-v2-source/references/delete.md +9 -23
- package/skills/tier0-sdk-v2/tier0-sdk-v2-source/references/protocols.md +12 -29
- package/skills/tier0-sdk-v2/tier0-sdk-v2-source/references/read.md +4 -5
- package/skills/tier0-sdk-v2/tier0-sdk-v2-source/references/update.md +5 -5
- package/skills/tier0-sdk-v2/tier0-sdk-v2-stream/SKILL.md +3 -3
- package/skills/tier0-sdk-v2/tier0-sdk-v2-stream/references/create.md +23 -9
- package/skills/tier0-sdk-v2/tier0-sdk-v2-stream/references/deploy.md +14 -12
- package/skills/tier0-sdk-v2/tier0-sdk-v2-stream/references/http-server.md +4 -4
- package/skills/tier0-sdk-v2/tier0-sdk-v2-stream/references/read.md +4 -3
- package/skills/tier0-sdk-v2/tier0-sdk-v2-streams/SKILL.md +12 -12
- package/skills/tier0-sdk-v2/tier0-sdk-v2-uns/SKILL.md +2 -1
- package/skills/tier0-sdk-v2/tier0-sdk-v2-uns/references/create.md +2 -2
- package/skills/tier0-sdk-v2/tier0-sdk-v2-uns/references/delete.md +22 -1
- package/skills/tier0-sdk-v2/tier0-sdk-v2-uns/references/read.md +5 -6
- package/dist/cjs/app-identity-contract.generated.d.ts +0 -22
- package/dist/cjs/app-identity-contract.generated.js +0 -51
- package/dist/cjs/app-identity-contract.generated.js.map +0 -1
- package/dist/cjs/runtime.d.ts +0 -13
- package/dist/cjs/runtime.js +0 -51
- package/dist/cjs/runtime.js.map +0 -1
- package/dist/esm/app-identity-contract.generated.d.ts +0 -22
- package/dist/esm/app-identity-contract.generated.js +0 -48
- package/dist/esm/app-identity-contract.generated.js.map +0 -1
- package/dist/esm/runtime.d.ts +0 -13
- package/dist/esm/runtime.js +0 -46
- package/dist/esm/runtime.js.map +0 -1
package/dist/cjs/client.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { CloudTransportConfig } from './cloud-transport.js';
|
|
|
8
8
|
export interface Tier0ClientConfig extends ClientConfig, CloudTransportConfig {
|
|
9
9
|
}
|
|
10
10
|
export type Tier0Client = ReturnType<typeof createClient>;
|
|
11
|
-
/**
|
|
11
|
+
/** 每个实例持有独立配置;带 Key 的客户端只在服务端使用。 */
|
|
12
12
|
export declare function createClient(config?: Tier0ClientConfig): Readonly<{
|
|
13
13
|
streams: {
|
|
14
14
|
requests: StreamRequestsClient;
|
|
@@ -59,6 +59,8 @@ export declare function createClient(config?: Tier0ClientConfig): Readonly<{
|
|
|
59
59
|
send: (body: import("./index.js").components["schemas"]["SdknotificationsSendRequest"], options?: import("./openapi/client.js").RequestOptions) => Promise<{
|
|
60
60
|
createdAt: string;
|
|
61
61
|
messageId: string;
|
|
62
|
+
recipientName?: string;
|
|
63
|
+
recipientUserId: string;
|
|
62
64
|
status: string;
|
|
63
65
|
}>;
|
|
64
66
|
get: (body: import("./index.js").components["schemas"]["SdknotificationsGetRequest"], options?: import("./openapi/client.js").RequestOptions) => Promise<{
|
|
@@ -68,9 +70,17 @@ export declare function createClient(config?: Tier0ClientConfig): Readonly<{
|
|
|
68
70
|
errorCode?: string;
|
|
69
71
|
message?: string;
|
|
70
72
|
messageId: string;
|
|
73
|
+
recipientName?: string;
|
|
74
|
+
recipientUserId: string;
|
|
71
75
|
status: string;
|
|
72
76
|
type: string;
|
|
73
77
|
}>;
|
|
78
|
+
list: (body?: import("./index.js").components["schemas"]["SdknotificationsListRequest"], options?: import("./openapi/client.js").RequestOptions) => Promise<{
|
|
79
|
+
list: import("./index.js").components["schemas"]["NotificationListItem"][];
|
|
80
|
+
page: number | bigint;
|
|
81
|
+
size: number | bigint;
|
|
82
|
+
total: number | bigint;
|
|
83
|
+
}>;
|
|
74
84
|
};
|
|
75
85
|
mqttAuth: {
|
|
76
86
|
create: (body: import("./index.js").components["schemas"]["SdkmqttAuthCreateRequest"], options?: import("./openapi/client.js").RequestOptions) => Promise<{
|
|
@@ -210,7 +220,6 @@ export declare function createClient(config?: Tier0ClientConfig): Readonly<{
|
|
|
210
220
|
files: FilesClient;
|
|
211
221
|
capabilities: CapabilitiesClient;
|
|
212
222
|
source: Readonly<{
|
|
213
|
-
delete: (request: import("./index.js").CloudSourceDeleteReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").CloudSourceDeleteResponse>;
|
|
214
223
|
validate: (request: import("./index.js").UnsV2SourceValidateReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").UnsV2SourceValidateResponse>;
|
|
215
224
|
probe: (request: import("./index.js").UnsV2SourceProbeReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").UnsV2SourceProbeResponse>;
|
|
216
225
|
discover: (request: import("./index.js").CloudSourceDiscoverReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").CloudSourceDiscoverResponse>;
|
|
@@ -225,11 +234,30 @@ export declare function createClient(config?: Tier0ClientConfig): Readonly<{
|
|
|
225
234
|
observations: Readonly<{
|
|
226
235
|
get: (request: import("./index.js").CloudSourceObservationsGetReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").CloudSourceObservationsGetResponse>;
|
|
227
236
|
}>;
|
|
237
|
+
resources: Readonly<{
|
|
238
|
+
catalog: (request: import("./index.js").CloudSourceResourceCatalogReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").CloudSourceResourceCatalogResponse>;
|
|
239
|
+
preview: (request: import("./index.js").CloudSourceResourceReadReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").CloudSourceResourceReadResponse>;
|
|
240
|
+
scan: (request: import("./index.js").CloudSourceResourceScanReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").CloudSourceResourceScanResponse>;
|
|
241
|
+
}>;
|
|
242
|
+
devices: Readonly<{
|
|
243
|
+
list: (request: import("./index.js").CloudSourceDevicesListReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").CloudSourceDevicesListResponse>;
|
|
244
|
+
}>;
|
|
228
245
|
documents: Readonly<{
|
|
229
246
|
list: (request: import("./index.js").CloudSourceDocumentListReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").CloudSourceDocumentListResponse>;
|
|
230
247
|
get: (request: import("./index.js").CloudSourceDocumentGetReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").CloudSourceDocumentGetResponse>;
|
|
231
248
|
create: (request: import("./index.js").CloudSourceDocumentCreateReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").CloudSourceDocumentCreateResponse>;
|
|
232
249
|
update: (request: import("./index.js").CloudSourceDocumentUpdateReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").CloudSourceDocumentUpdateResponse>;
|
|
250
|
+
delete: (request: import("./index.js").UnsV2SourceDocumentDeleteReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").UnsV2SourceDocumentDeleteResponse>;
|
|
251
|
+
credentials: Readonly<{
|
|
252
|
+
update: (request: import("./index.js").UnsV2SourceNativeCredentialsUpdateReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").UnsV2SourceNativeCredentialsUpdateResponse>;
|
|
253
|
+
}>;
|
|
254
|
+
state: Readonly<{
|
|
255
|
+
update: (request: import("./index.js").CloudEdgeSourceStateUpdateReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").CloudEdgeSourceStateUpdateResponse>;
|
|
256
|
+
}>;
|
|
257
|
+
oauth: Readonly<{
|
|
258
|
+
start: (request: import("./index.js").UnsV2SourceNativeOAuthStartReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").UnsV2SourceNativeOAuthStartResponse>;
|
|
259
|
+
complete: (request: import("./index.js").UnsV2SourceNativeOAuthCompleteReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").UnsV2SourceNativeOAuthCompleteResponse>;
|
|
260
|
+
}>;
|
|
233
261
|
}>;
|
|
234
262
|
}>;
|
|
235
263
|
stream: Readonly<{
|
|
@@ -335,6 +363,8 @@ export declare function createClient(config?: Tier0ClientConfig): Readonly<{
|
|
|
335
363
|
send: (body: import("./index.js").components["schemas"]["SdknotificationsSendRequest"], options?: import("./openapi/client.js").RequestOptions) => Promise<{
|
|
336
364
|
createdAt: string;
|
|
337
365
|
messageId: string;
|
|
366
|
+
recipientName?: string;
|
|
367
|
+
recipientUserId: string;
|
|
338
368
|
status: string;
|
|
339
369
|
}>;
|
|
340
370
|
get: (body: import("./index.js").components["schemas"]["SdknotificationsGetRequest"], options?: import("./openapi/client.js").RequestOptions) => Promise<{
|
|
@@ -344,9 +374,17 @@ export declare function createClient(config?: Tier0ClientConfig): Readonly<{
|
|
|
344
374
|
errorCode?: string;
|
|
345
375
|
message?: string;
|
|
346
376
|
messageId: string;
|
|
377
|
+
recipientName?: string;
|
|
378
|
+
recipientUserId: string;
|
|
347
379
|
status: string;
|
|
348
380
|
type: string;
|
|
349
381
|
}>;
|
|
382
|
+
list: (body?: import("./index.js").components["schemas"]["SdknotificationsListRequest"], options?: import("./openapi/client.js").RequestOptions) => Promise<{
|
|
383
|
+
list: import("./index.js").components["schemas"]["NotificationListItem"][];
|
|
384
|
+
page: number | bigint;
|
|
385
|
+
size: number | bigint;
|
|
386
|
+
total: number | bigint;
|
|
387
|
+
}>;
|
|
350
388
|
};
|
|
351
389
|
members: {
|
|
352
390
|
listWorkspace: (body?: import("./index.js").components["schemas"]["SdkmembersListWorkspaceRequest"], options?: import("./openapi/client.js").RequestOptions) => Promise<{
|
|
@@ -570,6 +608,8 @@ export declare const client: Readonly<{
|
|
|
570
608
|
send: (body: import("./index.js").components["schemas"]["SdknotificationsSendRequest"], options?: import("./openapi/client.js").RequestOptions) => Promise<{
|
|
571
609
|
createdAt: string;
|
|
572
610
|
messageId: string;
|
|
611
|
+
recipientName?: string;
|
|
612
|
+
recipientUserId: string;
|
|
573
613
|
status: string;
|
|
574
614
|
}>;
|
|
575
615
|
get: (body: import("./index.js").components["schemas"]["SdknotificationsGetRequest"], options?: import("./openapi/client.js").RequestOptions) => Promise<{
|
|
@@ -579,9 +619,17 @@ export declare const client: Readonly<{
|
|
|
579
619
|
errorCode?: string;
|
|
580
620
|
message?: string;
|
|
581
621
|
messageId: string;
|
|
622
|
+
recipientName?: string;
|
|
623
|
+
recipientUserId: string;
|
|
582
624
|
status: string;
|
|
583
625
|
type: string;
|
|
584
626
|
}>;
|
|
627
|
+
list: (body?: import("./index.js").components["schemas"]["SdknotificationsListRequest"], options?: import("./openapi/client.js").RequestOptions) => Promise<{
|
|
628
|
+
list: import("./index.js").components["schemas"]["NotificationListItem"][];
|
|
629
|
+
page: number | bigint;
|
|
630
|
+
size: number | bigint;
|
|
631
|
+
total: number | bigint;
|
|
632
|
+
}>;
|
|
585
633
|
};
|
|
586
634
|
mqttAuth: {
|
|
587
635
|
create: (body: import("./index.js").components["schemas"]["SdkmqttAuthCreateRequest"], options?: import("./openapi/client.js").RequestOptions) => Promise<{
|
|
@@ -721,7 +769,6 @@ export declare const client: Readonly<{
|
|
|
721
769
|
files: FilesClient;
|
|
722
770
|
capabilities: CapabilitiesClient;
|
|
723
771
|
source: Readonly<{
|
|
724
|
-
delete: (request: import("./index.js").CloudSourceDeleteReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").CloudSourceDeleteResponse>;
|
|
725
772
|
validate: (request: import("./index.js").UnsV2SourceValidateReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").UnsV2SourceValidateResponse>;
|
|
726
773
|
probe: (request: import("./index.js").UnsV2SourceProbeReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").UnsV2SourceProbeResponse>;
|
|
727
774
|
discover: (request: import("./index.js").CloudSourceDiscoverReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").CloudSourceDiscoverResponse>;
|
|
@@ -736,11 +783,30 @@ export declare const client: Readonly<{
|
|
|
736
783
|
observations: Readonly<{
|
|
737
784
|
get: (request: import("./index.js").CloudSourceObservationsGetReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").CloudSourceObservationsGetResponse>;
|
|
738
785
|
}>;
|
|
786
|
+
resources: Readonly<{
|
|
787
|
+
catalog: (request: import("./index.js").CloudSourceResourceCatalogReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").CloudSourceResourceCatalogResponse>;
|
|
788
|
+
preview: (request: import("./index.js").CloudSourceResourceReadReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").CloudSourceResourceReadResponse>;
|
|
789
|
+
scan: (request: import("./index.js").CloudSourceResourceScanReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").CloudSourceResourceScanResponse>;
|
|
790
|
+
}>;
|
|
791
|
+
devices: Readonly<{
|
|
792
|
+
list: (request: import("./index.js").CloudSourceDevicesListReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").CloudSourceDevicesListResponse>;
|
|
793
|
+
}>;
|
|
739
794
|
documents: Readonly<{
|
|
740
795
|
list: (request: import("./index.js").CloudSourceDocumentListReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").CloudSourceDocumentListResponse>;
|
|
741
796
|
get: (request: import("./index.js").CloudSourceDocumentGetReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").CloudSourceDocumentGetResponse>;
|
|
742
797
|
create: (request: import("./index.js").CloudSourceDocumentCreateReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").CloudSourceDocumentCreateResponse>;
|
|
743
798
|
update: (request: import("./index.js").CloudSourceDocumentUpdateReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").CloudSourceDocumentUpdateResponse>;
|
|
799
|
+
delete: (request: import("./index.js").UnsV2SourceDocumentDeleteReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").UnsV2SourceDocumentDeleteResponse>;
|
|
800
|
+
credentials: Readonly<{
|
|
801
|
+
update: (request: import("./index.js").UnsV2SourceNativeCredentialsUpdateReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").UnsV2SourceNativeCredentialsUpdateResponse>;
|
|
802
|
+
}>;
|
|
803
|
+
state: Readonly<{
|
|
804
|
+
update: (request: import("./index.js").CloudEdgeSourceStateUpdateReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").CloudEdgeSourceStateUpdateResponse>;
|
|
805
|
+
}>;
|
|
806
|
+
oauth: Readonly<{
|
|
807
|
+
start: (request: import("./index.js").UnsV2SourceNativeOAuthStartReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").UnsV2SourceNativeOAuthStartResponse>;
|
|
808
|
+
complete: (request: import("./index.js").UnsV2SourceNativeOAuthCompleteReq, options?: import("./openapi/client.js").RequestOptions) => Promise<import("./index.js").UnsV2SourceNativeOAuthCompleteResponse>;
|
|
809
|
+
}>;
|
|
744
810
|
}>;
|
|
745
811
|
}>;
|
|
746
812
|
stream: Readonly<{
|
|
@@ -846,6 +912,8 @@ export declare const client: Readonly<{
|
|
|
846
912
|
send: (body: import("./index.js").components["schemas"]["SdknotificationsSendRequest"], options?: import("./openapi/client.js").RequestOptions) => Promise<{
|
|
847
913
|
createdAt: string;
|
|
848
914
|
messageId: string;
|
|
915
|
+
recipientName?: string;
|
|
916
|
+
recipientUserId: string;
|
|
849
917
|
status: string;
|
|
850
918
|
}>;
|
|
851
919
|
get: (body: import("./index.js").components["schemas"]["SdknotificationsGetRequest"], options?: import("./openapi/client.js").RequestOptions) => Promise<{
|
|
@@ -855,9 +923,17 @@ export declare const client: Readonly<{
|
|
|
855
923
|
errorCode?: string;
|
|
856
924
|
message?: string;
|
|
857
925
|
messageId: string;
|
|
926
|
+
recipientName?: string;
|
|
927
|
+
recipientUserId: string;
|
|
858
928
|
status: string;
|
|
859
929
|
type: string;
|
|
860
930
|
}>;
|
|
931
|
+
list: (body?: import("./index.js").components["schemas"]["SdknotificationsListRequest"], options?: import("./openapi/client.js").RequestOptions) => Promise<{
|
|
932
|
+
list: import("./index.js").components["schemas"]["NotificationListItem"][];
|
|
933
|
+
page: number | bigint;
|
|
934
|
+
size: number | bigint;
|
|
935
|
+
total: number | bigint;
|
|
936
|
+
}>;
|
|
861
937
|
};
|
|
862
938
|
members: {
|
|
863
939
|
listWorkspace: (body?: import("./index.js").components["schemas"]["SdkmembersListWorkspaceRequest"], options?: import("./openapi/client.js").RequestOptions) => Promise<{
|
package/dist/cjs/client.js
CHANGED
|
@@ -14,9 +14,7 @@ const source_js_1 = require("./source.js");
|
|
|
14
14
|
const stream_js_1 = require("./stream.js");
|
|
15
15
|
const capabilities_js_2 = require("./capabilities.js");
|
|
16
16
|
const files_js_1 = require("./files.js");
|
|
17
|
-
|
|
18
|
-
function assemble(resolve, snapshot) {
|
|
19
|
-
const http = resolve();
|
|
17
|
+
function assemble(resolve, snapshot, http = resolve()) {
|
|
20
18
|
const api = (0, api_generated_js_1.createOpenAPI)(http);
|
|
21
19
|
const transport = new transport_js_1.StreamTransport(resolve, snapshot);
|
|
22
20
|
const messages = new messages_js_1.StreamMessagesClient(transport);
|
|
@@ -37,9 +35,9 @@ function assemble(resolve, snapshot) {
|
|
|
37
35
|
api,
|
|
38
36
|
});
|
|
39
37
|
}
|
|
40
|
-
/**
|
|
38
|
+
/** 每个实例持有独立配置;带 Key 的客户端只在服务端使用。 */
|
|
41
39
|
function createClient(config = {}) {
|
|
42
|
-
const snapshot = Object.freeze(
|
|
40
|
+
const snapshot = Object.freeze((0, client_js_1.snapshotClientConfig)(config));
|
|
43
41
|
const http = new client_js_1.HttpClient(snapshot);
|
|
44
42
|
return assemble(() => http, snapshot);
|
|
45
43
|
}
|
|
@@ -52,5 +50,5 @@ const defaultHttp = new Proxy(new client_js_1.HttpClient(), {
|
|
|
52
50
|
},
|
|
53
51
|
});
|
|
54
52
|
/** App 默认交互客户端在调用时解析宿主,无需在浏览器配置密钥。 */
|
|
55
|
-
exports.client = assemble(
|
|
53
|
+
exports.client = assemble(client_js_1.getClient, {}, defaultHttp);
|
|
56
54
|
//# sourceMappingURL=client.js.map
|
package/dist/cjs/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;AAuCA,oCAIC;AA3CD,uDAA6D;AAC7D,uDAA6D;AAC7D,yDAAyD;AACzD,+DAAqE;AACrE,mDAAqG;AACrG,iEAA2D;AAC3D,kDAAuD;AACvD,4DAA4D;AAC5D,2CAA+C;AAC/C,2CAA+C;AAC/C,uDAAuD;AACvD,yCAAyC;AAIzC,SAAS,QAAQ,CAAC,OAAyB,EAAE,QAA2B,EAAE,IAAI,GAAG,OAAO,EAAE;IACxF,MAAM,GAAG,GAAG,IAAA,gCAAa,EAAC,IAAI,CAAC,CAAC;IAChC,MAAM,SAAS,GAAG,IAAI,8BAAe,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACzD,MAAM,QAAQ,GAAG,IAAI,kCAAoB,CAAC,SAAS,CAAC,CAAC;IACrD,MAAM,GAAG,GAAG,IAAA,6BAAiB,EAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACjD,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,OAAO,EAAE,EAAE,QAAQ,EAAE,IAAI,kCAAoB,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,0CAAwB,CA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AC,CAAC,KAAK,CAAC;IACnE,CAAC;CACF,CAAC,CAAC;AACH,sCAAsC;AACzB,QAAA,MAAM,GAAG,QAAQ,CAAC,qBAAS,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC","sourcesContent":["import { StreamRequestsClient } from './streams/requests.js';\nimport { StreamMessagesClient } from './streams/messages.js';\nimport { StreamTransport } from './streams/transport.js';\nimport { StreamCapabilitiesClient } from './streams/capabilities.js';\nimport { getClient, HttpClient, snapshotClientConfig, type ClientConfig } from './openapi/client.js';\nimport { createOpenAPI } from './openapi/api.generated.js';\nimport { createUnsV2Client } from './uns-v2/client.js';\nimport { bindUnsDataClient } from './uns-v2/data-client.js';\nimport { bindSourceClient } from './source.js';\nimport { bindStreamClient } from './stream.js';\nimport { CapabilitiesClient } from './capabilities.js';\nimport { FilesClient } from './files.js';\nimport type { CloudTransportConfig } from './cloud-transport.js';\n\nexport interface Tier0ClientConfig extends ClientConfig, CloudTransportConfig {}\nfunction assemble(resolve: () => HttpClient, snapshot: Tier0ClientConfig, http = resolve()) {\n const api = createOpenAPI(http);\n const transport = new StreamTransport(resolve, snapshot);\n const messages = new StreamMessagesClient(transport);\n const raw = createUnsV2Client(resolve, snapshot);\n return Object.freeze({\n streams: { requests: new StreamRequestsClient(transport), messages, capabilities: new StreamCapabilitiesClient(resolve, snapshot) },\n dispose: () => messages.dispose(),\n system: api.system,\n members: api.members,\n notifications: api.notifications,\n mqttAuth: api.mqttAuth,\n agent: api.agent,\n files: new FilesClient(http),\n capabilities: new CapabilitiesClient(resolve, snapshot),\n source: bindSourceClient(raw),\n stream: bindStreamClient(raw),\n uns: bindUnsDataClient(raw),\n api,\n });\n}\nexport type Tier0Client = ReturnType<typeof createClient>;\n\n/** 每个实例持有独立配置;带 Key 的客户端只在服务端使用。 */\nexport function createClient(config: Tier0ClientConfig = {}) {\n const snapshot = Object.freeze(snapshotClientConfig(config));\n const http = new HttpClient(snapshot);\n return assemble(() => http, snapshot);\n}\n\n// 全局兼容入口也在调用时读取 configureClient,不固化模块导入时的配置。\nconst defaultHttp = new Proxy(new HttpClient(), {\n get(_target, key) {\n const current = getClient();\n const value: unknown = Reflect.get(current, key);\n return typeof value === 'function' ? value.bind(current) : value;\n },\n});\n/** App 默认交互客户端在调用时解析宿主,无需在浏览器配置密钥。 */\nexport const client = assemble(getClient, {}, defaultHttp);\n"]}
|
|
@@ -1,31 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
export declare
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/** Set by the front door on every request it forwards to the App, after stripping any `X-Tier0-*` the client sent. */
|
|
2
|
+
export declare const VISITOR_HEADER = "X-Tier0-Visitor";
|
|
3
|
+
export type VisitorErrorCode = 'VISITOR_HEADER_INVALID' | 'VISITOR_CONFIGURATION_INVALID';
|
|
4
|
+
export declare class VisitorError extends Error {
|
|
5
|
+
readonly code: VisitorErrorCode;
|
|
6
|
+
constructor(code: VisitorErrorCode);
|
|
5
7
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
readonly
|
|
8
|
+
/** The visitor of a request, from `X-Tier0-Visitor`. */
|
|
9
|
+
export interface Visitor {
|
|
10
|
+
readonly subType: 'employee' | 'machine';
|
|
11
|
+
/** Employee user ID, or the call token ID of a machine visitor. */
|
|
12
|
+
readonly subject: string;
|
|
13
|
+
/** Grant of an employee's access; empty for a machine visitor. */
|
|
14
|
+
readonly grant: string;
|
|
9
15
|
readonly workspaceID: string;
|
|
10
16
|
readonly appID: string;
|
|
11
|
-
readonly
|
|
12
|
-
|
|
13
|
-
readonly
|
|
14
|
-
|
|
15
|
-
readonly
|
|
17
|
+
readonly runtime: 'deployed' | 'preview';
|
|
18
|
+
/** Roles of this visitor in the App; in Preview, the roles selected in "view as". */
|
|
19
|
+
readonly appRoles: readonly string[];
|
|
20
|
+
/** Only in Preview's "view as". */
|
|
21
|
+
readonly activeRole?: string;
|
|
16
22
|
}
|
|
17
|
-
export interface
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
/** Pinned server configuration, never a key or URL taken from the request. */
|
|
21
|
-
publicKeys: unknown;
|
|
23
|
+
export interface ParseVisitorOptions {
|
|
24
|
+
/** The App the header must name. Defaults to `TIER0_APP_ID`. */
|
|
25
|
+
appID?: string;
|
|
22
26
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Parses `X-Tier0-Visitor`: the unpadded base64url (RFC 4648 §5) of a UTF-8
|
|
29
|
+
* JSON object of at most 8192 bytes. The header is not signed; the front door
|
|
30
|
+
* is the only way into the App and replaces whatever the client sent. Parsing
|
|
31
|
+
* is strict: a byte order mark, a duplicate key, a lone UTF-16 surrogate
|
|
32
|
+
* (e.g. `"\ud800"`), an unknown or missing field, a wrong type or length, a `ws` that
|
|
33
|
+
* is not a positive decimal ID without sign or leading zero, an employee
|
|
34
|
+
* without a grant or a machine visitor with one, or an `app` other than this
|
|
35
|
+
* App's throws `VISITOR_HEADER_INVALID`. Without an App ID
|
|
36
|
+
* (`TIER0_APP_ID` unset) it throws `VISITOR_CONFIGURATION_INVALID`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function parseVisitorHeader(value: string | null | undefined, options?: ParseVisitorOptions): Visitor;
|
package/dist/cjs/cloud-server.js
CHANGED
|
@@ -1,114 +1,116 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
5
|
-
// Server-only entry point
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
exports.VisitorError = exports.VISITOR_HEADER = void 0;
|
|
4
|
+
exports.parseVisitorHeader = parseVisitorHeader;
|
|
5
|
+
// Server-only entry point: the App's view of the request it is serving.
|
|
6
|
+
const runtime_env_js_1 = require("./runtime-env.js");
|
|
7
|
+
const maxID = BigInt('9223372036854775807');
|
|
8
|
+
/** A positive decimal int64 without sign or leading zero. */
|
|
9
|
+
const validID = (value) => typeof value === 'string' && /^[1-9]\d{0,18}$/.test(value) && BigInt(value) <= maxID;
|
|
10
|
+
const isObject = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
11
|
+
/** Set by the front door on every request it forwards to the App, after stripping any `X-Tier0-*` the client sent. */
|
|
12
|
+
exports.VISITOR_HEADER = 'X-Tier0-Visitor';
|
|
13
|
+
/** Limit of the JSON before encoding. */
|
|
14
|
+
const VISITOR_MAX_JSON_BYTES = 8192;
|
|
15
|
+
/** Unpadded base64url of `VISITOR_MAX_JSON_BYTES`. */
|
|
16
|
+
const VISITOR_MAX_HEADER_LENGTH = Math.ceil((VISITOR_MAX_JSON_BYTES * 4) / 3);
|
|
17
|
+
const VISITOR_MAX_STRING_BYTES = 128;
|
|
18
|
+
const VISITOR_FIELDS = new Set(['ws', 'app', 'runtime', 'sub_type', 'sub', 'grant', 'app_roles', 'active_role']);
|
|
19
|
+
class VisitorError extends Error {
|
|
10
20
|
code;
|
|
11
21
|
constructor(code) {
|
|
12
22
|
super(code);
|
|
13
23
|
this.code = code;
|
|
14
|
-
this.name = '
|
|
24
|
+
this.name = 'VisitorError';
|
|
15
25
|
}
|
|
16
26
|
}
|
|
17
|
-
exports.
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
try {
|
|
45
|
-
let raw = authority.publicKeys;
|
|
46
|
-
if (typeof raw === 'string') {
|
|
47
|
-
if (Buffer.byteLength(raw) > app_identity_contract_generated_js_1.APP_REQUEST_IDENTITY_CONTRACT.maxTokenBytes * app_identity_contract_generated_js_1.APP_REQUEST_IDENTITY_CONTRACT.maxKeys)
|
|
48
|
-
throw invalidConfig();
|
|
49
|
-
raw = JSON.parse(raw);
|
|
50
|
-
}
|
|
51
|
-
if (!isObject(raw) || !exactKeys(raw, ['keys']) || !Array.isArray(raw.keys) ||
|
|
52
|
-
raw.keys.length === 0 || raw.keys.length > app_identity_contract_generated_js_1.APP_REQUEST_IDENTITY_CONTRACT.maxKeys)
|
|
53
|
-
throw invalidConfig();
|
|
54
|
-
for (const key of raw.keys) {
|
|
55
|
-
if (!isObject(key) || !exactKeys(key, app_identity_contract_generated_js_1.APP_REQUEST_IDENTITY_CONTRACT.publicKeyFields) || key.kty !== 'OKP' ||
|
|
56
|
-
key.crv !== 'Ed25519' || typeof key.kid !== 'string' || !kidPattern.test(key.kid) ||
|
|
57
|
-
keys.has(key.kid) || typeof key.x !== 'string' || decode(key.x).length !== 32)
|
|
58
|
-
throw invalidConfig();
|
|
59
|
-
keys.set(key.kid, (0, node_crypto_1.createPublicKey)({ key: { kty: 'OKP', crv: 'Ed25519', x: key.x }, format: 'jwk' }));
|
|
27
|
+
exports.VisitorError = VisitorError;
|
|
28
|
+
/** A UTF-16 surrogate without its pair, as JSON escapes like "\ud800" can produce. */
|
|
29
|
+
const LONE_SURROGATE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;
|
|
30
|
+
/**
|
|
31
|
+
* Raw key tokens of the top-level object, for spotting duplicates
|
|
32
|
+
* (`JSON.parse` keeps the last silently). Values of the visitor are strings
|
|
33
|
+
* and arrays of strings, so only depth 1 holds keys.
|
|
34
|
+
*/
|
|
35
|
+
function topLevelKeys(json) {
|
|
36
|
+
const keys = [];
|
|
37
|
+
let depth = 0;
|
|
38
|
+
for (let i = 0; i < json.length; i += 1) {
|
|
39
|
+
const char = json[i];
|
|
40
|
+
if (char === '{' || char === '[')
|
|
41
|
+
depth += 1;
|
|
42
|
+
else if (char === '}' || char === ']')
|
|
43
|
+
depth -= 1;
|
|
44
|
+
else if (char === '"') {
|
|
45
|
+
const start = i;
|
|
46
|
+
for (i += 1; i < json.length && json[i] !== '"'; i += 1)
|
|
47
|
+
if (json[i] === '\\')
|
|
48
|
+
i += 1;
|
|
49
|
+
let next = i + 1;
|
|
50
|
+
while (next < json.length && /\s/.test(json[next]))
|
|
51
|
+
next += 1;
|
|
52
|
+
if (depth === 1 && json[next] === ':')
|
|
53
|
+
keys.push(json.slice(start, i + 1));
|
|
60
54
|
}
|
|
61
55
|
}
|
|
56
|
+
return keys;
|
|
57
|
+
}
|
|
58
|
+
const bytes = (value) => Buffer.byteLength(value, 'utf8');
|
|
59
|
+
const sized = (value, min, max) => typeof value === 'string' && !LONE_SURROGATE.test(value) && bytes(value) >= min && bytes(value) <= max;
|
|
60
|
+
/**
|
|
61
|
+
* Parses `X-Tier0-Visitor`: the unpadded base64url (RFC 4648 §5) of a UTF-8
|
|
62
|
+
* JSON object of at most 8192 bytes. The header is not signed; the front door
|
|
63
|
+
* is the only way into the App and replaces whatever the client sent. Parsing
|
|
64
|
+
* is strict: a byte order mark, a duplicate key, a lone UTF-16 surrogate
|
|
65
|
+
* (e.g. `"\ud800"`), an unknown or missing field, a wrong type or length, a `ws` that
|
|
66
|
+
* is not a positive decimal ID without sign or leading zero, an employee
|
|
67
|
+
* without a grant or a machine visitor with one, or an `app` other than this
|
|
68
|
+
* App's throws `VISITOR_HEADER_INVALID`. Without an App ID
|
|
69
|
+
* (`TIER0_APP_ID` unset) it throws `VISITOR_CONFIGURATION_INVALID`.
|
|
70
|
+
*/
|
|
71
|
+
function parseVisitorHeader(value, options = {}) {
|
|
72
|
+
const appID = options.appID ?? (0, runtime_env_js_1.getEnvVar)('TIER0_APP_ID')?.trim();
|
|
73
|
+
if (!appID)
|
|
74
|
+
throw new VisitorError('VISITOR_CONFIGURATION_INVALID');
|
|
75
|
+
const fail = () => new VisitorError('VISITOR_HEADER_INVALID');
|
|
76
|
+
if (typeof value !== 'string' || value.length === 0 || value.length > VISITOR_MAX_HEADER_LENGTH || !/^[A-Za-z0-9_-]+$/.test(value))
|
|
77
|
+
throw fail();
|
|
78
|
+
const raw = Buffer.from(value, 'base64url');
|
|
79
|
+
// Only the canonical encoding: no padding, no stray trailing bits.
|
|
80
|
+
if (raw.length > VISITOR_MAX_JSON_BYTES || raw.toString('base64url') !== value)
|
|
81
|
+
throw fail();
|
|
82
|
+
// A UTF-8 byte order mark is not part of the contract (TextDecoder would drop it silently).
|
|
83
|
+
if (raw[0] === 0xef && raw[1] === 0xbb && raw[2] === 0xbf)
|
|
84
|
+
throw fail();
|
|
85
|
+
let claims;
|
|
86
|
+
let json;
|
|
87
|
+
try {
|
|
88
|
+
json = new TextDecoder('utf-8', { fatal: true }).decode(raw);
|
|
89
|
+
claims = JSON.parse(json);
|
|
90
|
+
}
|
|
62
91
|
catch {
|
|
63
|
-
throw
|
|
92
|
+
throw fail();
|
|
64
93
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (!isObject(claims) || !exactKeys(claims, app_identity_contract_generated_js_1.APP_REQUEST_IDENTITY_CONTRACT.requiredClaims) ||
|
|
87
|
-
claims.ver !== app_identity_contract_generated_js_1.APP_REQUEST_IDENTITY_CONTRACT.version || claims.iss !== app_identity_contract_generated_js_1.APP_REQUEST_IDENTITY_CONTRACT.issuer || claims.aud !== app_identity_contract_generated_js_1.APP_REQUEST_IDENTITY_CONTRACT.audience ||
|
|
88
|
-
!validID(claims.sub) || claims.workspaceID !== workspaceID || claims.appID !== appID ||
|
|
89
|
-
claims.method !== request.method || claims.requestURI !== request.requestURI ||
|
|
90
|
-
typeof claims.bodySHA256 !== 'string' || !/^[a-f0-9]{64}$/.test(claims.bodySHA256) ||
|
|
91
|
-
claims.bodySHA256 !== (0, node_crypto_1.createHash)('sha256').update(request.body).digest('hex') ||
|
|
92
|
-
typeof claims.iat !== 'number' || !Number.isSafeInteger(claims.iat) || claims.iat <= 0 ||
|
|
93
|
-
typeof claims.exp !== 'number' || !Number.isSafeInteger(claims.exp) || claims.exp <= claims.iat ||
|
|
94
|
-
claims.exp - claims.iat > app_identity_contract_generated_js_1.APP_REQUEST_IDENTITY_CONTRACT.maxTTLSeconds ||
|
|
95
|
-
typeof claims.jti !== 'string' || !/^[a-f0-9]{32}$/.test(claims.jti) ||
|
|
96
|
-
!Array.isArray(claims.roles) || claims.roles.length > app_identity_contract_generated_js_1.APP_REQUEST_IDENTITY_CONTRACT.maxRoles ||
|
|
97
|
-
claims.roles.some((role) => !validString(role, app_identity_contract_generated_js_1.APP_REQUEST_IDENTITY_CONTRACT.maxRoleBytes) || role.trim() !== role) ||
|
|
98
|
-
new Set(claims.roles).size !== claims.roles.length)
|
|
99
|
-
throw invalid();
|
|
100
|
-
const now = Math.floor(Date.now() / 1000);
|
|
101
|
-
if (claims.iat > now + app_identity_contract_generated_js_1.APP_REQUEST_IDENTITY_CONTRACT.clockSkewSeconds || now >= claims.exp + app_identity_contract_generated_js_1.APP_REQUEST_IDENTITY_CONTRACT.clockSkewSeconds)
|
|
102
|
-
throw invalid();
|
|
103
|
-
return Object.freeze({
|
|
104
|
-
kind: 'gateway-user', userID: claims.sub, workspaceID, appID,
|
|
105
|
-
roleKeys: Object.freeze([...claims.roles]), requestID: claims.jti,
|
|
106
|
-
issuedAt: claims.iat, expiresAt: claims.exp, verificationKeyID: header.kid,
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
catch {
|
|
110
|
-
throw invalid();
|
|
111
|
-
}
|
|
112
|
-
};
|
|
94
|
+
if (!isObject(claims) || Object.keys(claims).some((key) => !VISITOR_FIELDS.has(key)))
|
|
95
|
+
throw fail();
|
|
96
|
+
// Every key at most once, each spelling decoded ("\u0077s" is "ws").
|
|
97
|
+
const keys = topLevelKeys(json).map((token) => JSON.parse(token));
|
|
98
|
+
if (new Set(keys).size !== keys.length)
|
|
99
|
+
throw fail();
|
|
100
|
+
const { ws, app, runtime, sub_type: subType, sub, grant, app_roles: appRoles, active_role: activeRole } = claims;
|
|
101
|
+
if (!validID(ws) || app !== appID ||
|
|
102
|
+
(runtime !== 'deployed' && runtime !== 'preview') ||
|
|
103
|
+
(subType !== 'employee' && subType !== 'machine') ||
|
|
104
|
+
!sized(sub, 1, VISITOR_MAX_STRING_BYTES) ||
|
|
105
|
+
// An employee's access always has a grant; a machine visitor has none.
|
|
106
|
+
typeof grant !== 'string' || (subType === 'employee' ? !sized(grant, 1, VISITOR_MAX_STRING_BYTES) : grant !== '') ||
|
|
107
|
+
!Array.isArray(appRoles) || appRoles.some((role) => !sized(role, 1, VISITOR_MAX_STRING_BYTES)) ||
|
|
108
|
+
(activeRole !== undefined && !sized(activeRole, 1, VISITOR_MAX_STRING_BYTES)))
|
|
109
|
+
throw fail();
|
|
110
|
+
return Object.freeze({
|
|
111
|
+
subType, subject: sub, grant, workspaceID: ws, appID, runtime,
|
|
112
|
+
appRoles: Object.freeze([...new Set(appRoles)]),
|
|
113
|
+
...(activeRole === undefined ? {} : { activeRole }),
|
|
114
|
+
});
|
|
113
115
|
}
|
|
114
116
|
//# sourceMappingURL=cloud-server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloud-server.js","sourceRoot":"","sources":["../../src/cloud-server.ts"],"names":[],"mappings":";;;AA+DA,sEA4DC;AA3HD,mFAAmF;AACnF,6CAAkF;AAClF,6FAAiG;AAEpF,QAAA,2BAA2B,GAAG,kEAAQ,CAAC,MAAM,CAAC;AAE3D,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G,GAAG,GAAG,kEAAQ,CAAC,gBAAgB,IAAI,GAAG,IAAI,MAAM,CAAC,GAAG,GAAG,kEAAQ,CAAC,gBAAgB;gBAAE,MAAM,OAAO,EAAE,CAAC;YACnH,OAAO,MAAM,CAAC,MAAM,CAAC;gBACnB,IAAI,EAAE,cAAuB,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK;gBACrE,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,CAAa,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,GAAG;gBAC7E,QAAQ,EAAE,MAAM,CAAC,GAAG,EAAE,SAAS,EAAE,MAAM,CAAC,GAAG,EAAE,iBAAiB,EAAE,MAAM,CAAC,GAAG;aAC3E,CAAC,CAAC;QACL,CAAC;QAAC,MAAM,CAAC;YAAC,MAAM,OAAO,EAAE,CAAC;QAAC,CAAC;IAC9B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Server-only entry point. Browser HTTP clients remain independent of node:crypto.\nimport { createHash, createPublicKey, verify, type KeyObject } from 'node:crypto';\nimport { APP_REQUEST_IDENTITY_CONTRACT as contract } from './app-identity-contract.generated.js';\n\nexport const APP_REQUEST_IDENTITY_HEADER = contract.header;\n\nexport class AppRequestIdentityError extends Error {\n constructor(public readonly code: 'APP_IDENTITY_INVALID' | 'APP_IDENTITY_CONFIGURATION_INVALID') {\n super(code);\n this.name = 'AppRequestIdentityError';\n }\n}\n\nexport interface VerifiedCloudAppUser {\n readonly kind: 'gateway-user';\n readonly userID: string;\n readonly workspaceID: string;\n readonly appID: string;\n readonly roleKeys: readonly string[];\n readonly requestID: string;\n readonly issuedAt: number;\n readonly expiresAt: number;\n readonly verificationKeyID: string;\n}\n\nexport interface CloudAppIdentityAuthority {\n appID: string;\n workspaceID: string;\n /** Pinned server configuration, never a key or URL taken from the request. */\n publicKeys: unknown;\n}\n\nexport interface CloudAppIdentityRequest {\n assertion: string | undefined;\n method: string;\n requestURI: string;\n /** Exact bytes received from the gateway, before JSON parsing or normalization. */\n body: Uint8Array;\n}\n\nconst invalid = () => new AppRequestIdentityError('APP_IDENTITY_INVALID');\nconst invalidConfig = () => new AppRequestIdentityError('APP_IDENTITY_CONFIGURATION_INVALID');\nconst appPattern = new RegExp(contract.appIDPattern);\nconst kidPattern = new RegExp(contract.keyIDPattern);\nconst methodPattern = new RegExp(contract.methodPattern);\nconst maxID = BigInt('9223372036854775807');\nconst validID = (value: unknown): value is string =>\n typeof value === 'string' && /^[1-9]\\d{0,18}$/.test(value) && BigInt(value) <= maxID;\nconst isObject = (value: unknown): value is Record<string, unknown> =>\n !!value && typeof value === 'object' && !Array.isArray(value);\nconst exactKeys = (value: Record<string, unknown>, keys: readonly string[]) =>\n Object.keys(value).length === keys.length && Object.keys(value).every((key) => keys.includes(key));\nconst validString = (value: unknown, maxBytes: number): value is string =>\n typeof value === 'string' && value.length > 0 && Buffer.byteLength(value) <= maxBytes &&\n Buffer.from(value).toString('utf8') === value && !/[\\u0000-\\u001f\\u007f-\\u009f]/.test(value);\nconst decode = (value: string) => {\n if (!/^[A-Za-z0-9_-]+$/.test(value)) throw invalid();\n const bytes = Buffer.from(value, 'base64url');\n if (bytes.toString('base64url') !== value) throw invalid();\n return bytes;\n};\n\n/** Verifies request provenance, not business authorization or delegated UNS permissions. */\nexport function createCloudAppRequestVerifier(authority: CloudAppIdentityAuthority) {\n if (!isObject(authority) || typeof authority.appID !== 'string' || !appPattern.test(authority.appID) || !validID(authority.workspaceID)) throw invalidConfig();\n const appID = authority.appID;\n const workspaceID = authority.workspaceID;\n const keys = new Map<string, KeyObject>();\n try {\n let raw = authority.publicKeys;\n if (typeof raw === 'string') {\n if (Buffer.byteLength(raw) > contract.maxTokenBytes * contract.maxKeys) throw invalidConfig();\n raw = JSON.parse(raw);\n }\n if (!isObject(raw) || !exactKeys(raw, ['keys']) || !Array.isArray(raw.keys) ||\n raw.keys.length === 0 || raw.keys.length > contract.maxKeys) throw invalidConfig();\n for (const key of raw.keys) {\n if (!isObject(key) || !exactKeys(key, contract.publicKeyFields) || key.kty !== 'OKP' ||\n key.crv !== 'Ed25519' || typeof key.kid !== 'string' || !kidPattern.test(key.kid) ||\n keys.has(key.kid) || typeof key.x !== 'string' || decode(key.x).length !== 32) throw invalidConfig();\n keys.set(key.kid, createPublicKey({ key: { kty: 'OKP', crv: 'Ed25519', x: key.x }, format: 'jwk' }));\n }\n } catch { throw invalidConfig(); }\n\n return (request: CloudAppIdentityRequest): VerifiedCloudAppUser => {\n try {\n if (typeof request.assertion !== 'string' || Buffer.byteLength(request.assertion) > contract.maxTokenBytes ||\n !(request.body instanceof Uint8Array) || request.body.byteLength > contract.maxBodyBytes ||\n !methodPattern.test(request.method) || !validString(request.requestURI, contract.maxURIBytes) ||\n !request.requestURI.startsWith('/') || request.requestURI.startsWith('//')) throw invalid();\n const parts = request.assertion.split('.');\n if (parts.length !== 3) throw invalid();\n const header: unknown = JSON.parse(decode(parts[0]).toString('utf8'));\n if (!isObject(header) || !exactKeys(header, contract.requiredHeaderFields) ||\n header.alg !== contract.algorithm || header.typ !== contract.type ||\n typeof header.kid !== 'string' || !kidPattern.test(header.kid)) throw invalid();\n const key = keys.get(header.kid);\n const signature = decode(parts[2]);\n if (!key || signature.length !== 64 ||\n !verify(null, Buffer.from(parts[0] + '.' + parts[1], 'ascii'), key, signature)) throw invalid();\n const claims: unknown = JSON.parse(decode(parts[1]).toString('utf8'));\n if (!isObject(claims) || !exactKeys(claims, contract.requiredClaims) ||\n claims.ver !== contract.version || claims.iss !== contract.issuer || claims.aud !== contract.audience ||\n !validID(claims.sub) || claims.workspaceID !== workspaceID || claims.appID !== appID ||\n claims.method !== request.method || claims.requestURI !== request.requestURI ||\n typeof claims.bodySHA256 !== 'string' || !/^[a-f0-9]{64}$/.test(claims.bodySHA256) ||\n claims.bodySHA256 !== createHash('sha256').update(request.body).digest('hex') ||\n typeof claims.iat !== 'number' || !Number.isSafeInteger(claims.iat) || claims.iat <= 0 ||\n typeof claims.exp !== 'number' || !Number.isSafeInteger(claims.exp) || claims.exp <= claims.iat ||\n claims.exp - claims.iat > contract.maxTTLSeconds ||\n typeof claims.jti !== 'string' || !/^[a-f0-9]{32}$/.test(claims.jti) ||\n !Array.isArray(claims.roles) || claims.roles.length > contract.maxRoles ||\n claims.roles.some((role) => !validString(role, contract.maxRoleBytes) || role.trim() !== role) ||\n new Set(claims.roles).size !== claims.roles.length) throw invalid();\n const now = Math.floor(Date.now() / 1000);\n if (claims.iat > now + contract.clockSkewSeconds || now >= claims.exp + contract.clockSkewSeconds) throw invalid();\n return Object.freeze({\n kind: 'gateway-user' as const, userID: claims.sub, workspaceID, appID,\n roleKeys: Object.freeze([...claims.roles] as string[]), requestID: claims.jti,\n issuedAt: claims.iat, expiresAt: claims.exp, verificationKeyID: header.kid,\n });\n } catch { throw invalid(); }\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"cloud-server.js","sourceRoot":"","sources":["../../src/cloud-server.ts"],"names":[],"mappings":";;;AA2FA,gDAoCC;AA/HD,wEAAwE;AACxE,qDAA6C;AAE7C,MAAM,KAAK,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAC5C,6DAA6D;AAC7D,MAAM,OAAO,GAAG,CAAC,KAAc,EAAmB,EAAE,CAClD,OAAO,KAAK,KAAK,QAAQ,IAAI,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC;AACvF,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CACpE,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAEhE,sHAAsH;AACzG,QAAA,cAAc,GAAG,iBAAiB,CAAC;AAEhD,yCAAyC;AACzC,MAAM,sBAAsB,GAAG,IAAI,CAAC;AACpC,sDAAsD;AACtD,MA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C,CAAC;QAC3D,GAAG,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC;KACpD,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Server-only entry point: the App's view of the request it is serving.\nimport { getEnvVar } from './runtime-env.js';\n\nconst maxID = BigInt('9223372036854775807');\n/** A positive decimal int64 without sign or leading zero. */\nconst validID = (value: unknown): value is string =>\n typeof value === 'string' && /^[1-9]\\d{0,18}$/.test(value) && BigInt(value) <= maxID;\nconst isObject = (value: unknown): value is Record<string, unknown> =>\n !!value && typeof value === 'object' && !Array.isArray(value);\n\n/** Set by the front door on every request it forwards to the App, after stripping any `X-Tier0-*` the client sent. */\nexport const VISITOR_HEADER = 'X-Tier0-Visitor';\n\n/** Limit of the JSON before encoding. */\nconst VISITOR_MAX_JSON_BYTES = 8192;\n/** Unpadded base64url of `VISITOR_MAX_JSON_BYTES`. */\nconst VISITOR_MAX_HEADER_LENGTH = Math.ceil((VISITOR_MAX_JSON_BYTES * 4) / 3);\nconst VISITOR_MAX_STRING_BYTES = 128;\nconst VISITOR_FIELDS: ReadonlySet<string> = new Set(['ws', 'app', 'runtime', 'sub_type', 'sub', 'grant', 'app_roles', 'active_role']);\n\nexport type VisitorErrorCode = 'VISITOR_HEADER_INVALID' | 'VISITOR_CONFIGURATION_INVALID';\n\nexport class VisitorError extends Error {\n constructor(public readonly code: VisitorErrorCode) {\n super(code);\n this.name = 'VisitorError';\n }\n}\n\n/** The visitor of a request, from `X-Tier0-Visitor`. */\nexport interface Visitor {\n readonly subType: 'employee' | 'machine';\n /** Employee user ID, or the call token ID of a machine visitor. */\n readonly subject: string;\n /** Grant of an employee's access; empty for a machine visitor. */\n readonly grant: string;\n readonly workspaceID: string;\n readonly appID: string;\n readonly runtime: 'deployed' | 'preview';\n /** Roles of this visitor in the App; in Preview, the roles selected in \"view as\". */\n readonly appRoles: readonly string[];\n /** Only in Preview's \"view as\". */\n readonly activeRole?: string;\n}\n\nexport interface ParseVisitorOptions {\n /** The App the header must name. Defaults to `TIER0_APP_ID`. */\n appID?: string;\n}\n\n/** A UTF-16 surrogate without its pair, as JSON escapes like \"\\ud800\" can produce. */\nconst LONE_SURROGATE = /[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?<![\\uD800-\\uDBFF])[\\uDC00-\\uDFFF]/;\n\n/**\n * Raw key tokens of the top-level object, for spotting duplicates\n * (`JSON.parse` keeps the last silently). Values of the visitor are strings\n * and arrays of strings, so only depth 1 holds keys.\n */\nfunction topLevelKeys(json: string): string[] {\n const keys: string[] = [];\n let depth = 0;\n for (let i = 0; i < json.length; i += 1) {\n const char = json[i];\n if (char === '{' || char === '[') depth += 1;\n else if (char === '}' || char === ']') depth -= 1;\n else if (char === '\"') {\n const start = i;\n for (i += 1; i < json.length && json[i] !== '\"'; i += 1) if (json[i] === '\\\\') i += 1;\n let next = i + 1;\n while (next < json.length && /\\s/.test(json[next])) next += 1;\n if (depth === 1 && json[next] === ':') keys.push(json.slice(start, i + 1));\n }\n }\n return keys;\n}\n\nconst bytes = (value: string) => Buffer.byteLength(value, 'utf8');\nconst sized = (value: unknown, min: number, max: number): value is string =>\n typeof value === 'string' && !LONE_SURROGATE.test(value) && bytes(value) >= min && bytes(value) <= max;\n\n/**\n * Parses `X-Tier0-Visitor`: the unpadded base64url (RFC 4648 §5) of a UTF-8\n * JSON object of at most 8192 bytes. The header is not signed; the front door\n * is the only way into the App and replaces whatever the client sent. Parsing\n * is strict: a byte order mark, a duplicate key, a lone UTF-16 surrogate\n * (e.g. `\"\\ud800\"`), an unknown or missing field, a wrong type or length, a `ws` that\n * is not a positive decimal ID without sign or leading zero, an employee\n * without a grant or a machine visitor with one, or an `app` other than this\n * App's throws `VISITOR_HEADER_INVALID`. Without an App ID\n * (`TIER0_APP_ID` unset) it throws `VISITOR_CONFIGURATION_INVALID`.\n */\nexport function parseVisitorHeader(value: string | null | undefined, options: ParseVisitorOptions = {}): Visitor {\n const appID = options.appID ?? getEnvVar('TIER0_APP_ID')?.trim();\n if (!appID) throw new VisitorError('VISITOR_CONFIGURATION_INVALID');\n const fail = () => new VisitorError('VISITOR_HEADER_INVALID');\n if (typeof value !== 'string' || value.length === 0 || value.length > VISITOR_MAX_HEADER_LENGTH || !/^[A-Za-z0-9_-]+$/.test(value)) throw fail();\n const raw = Buffer.from(value, 'base64url');\n // Only the canonical encoding: no padding, no stray trailing bits.\n if (raw.length > VISITOR_MAX_JSON_BYTES || raw.toString('base64url') !== value) throw fail();\n // A UTF-8 byte order mark is not part of the contract (TextDecoder would drop it silently).\n if (raw[0] === 0xef && raw[1] === 0xbb && raw[2] === 0xbf) throw fail();\n let claims: unknown;\n let json: string;\n try {\n json = new TextDecoder('utf-8', { fatal: true }).decode(raw);\n claims = JSON.parse(json);\n } catch {\n throw fail();\n }\n if (!isObject(claims) || Object.keys(claims).some((key) => !VISITOR_FIELDS.has(key))) throw fail();\n // Every key at most once, each spelling decoded (\"\\u0077s\" is \"ws\").\n const keys = topLevelKeys(json).map((token) => JSON.parse(token) as string);\n if (new Set(keys).size !== keys.length) throw fail();\n const { ws, app, runtime, sub_type: subType, sub, grant, app_roles: appRoles, active_role: activeRole } = claims;\n if (!validID(ws) || app !== appID ||\n (runtime !== 'deployed' && runtime !== 'preview') ||\n (subType !== 'employee' && subType !== 'machine') ||\n !sized(sub, 1, VISITOR_MAX_STRING_BYTES) ||\n // An employee's access always has a grant; a machine visitor has none.\n typeof grant !== 'string' || (subType === 'employee' ? !sized(grant, 1, VISITOR_MAX_STRING_BYTES) : grant !== '') ||\n !Array.isArray(appRoles) || appRoles.some((role) => !sized(role, 1, VISITOR_MAX_STRING_BYTES)) ||\n (activeRole !== undefined && !sized(activeRole, 1, VISITOR_MAX_STRING_BYTES))) throw fail();\n return Object.freeze({\n subType, subject: sub, grant, workspaceID: ws, appID, runtime,\n appRoles: Object.freeze([...new Set(appRoles as string[])]),\n ...(activeRole === undefined ? {} : { activeRole }),\n });\n}\n"]}
|