@domino-sdk/relay 0.2.0 → 0.3.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/dist/browser.js +2 -1
- package/dist/chunk-6IXQRMGW.js +37 -0
- package/dist/{chunk-NC3UAP6T.js → chunk-L757OYXZ.js} +72 -68
- package/dist/index.d.ts +36 -1
- package/dist/index.js +16 -6
- package/dist/portal-proxy.d.ts +17 -2
- package/dist/portal-proxy.js +73 -0
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
identifier
|
|
3
|
+
} from "./chunk-C2KOMNLG.js";
|
|
4
|
+
|
|
5
|
+
// src/auth.ts
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
var authScopeSchema = z.object({
|
|
8
|
+
organization: identifier,
|
|
9
|
+
project: identifier,
|
|
10
|
+
environment: z.enum(["test", "live"])
|
|
11
|
+
}).strict();
|
|
12
|
+
var principalSchema = z.discriminatedUnion("kind", [
|
|
13
|
+
z.object({ kind: z.literal("member"), member: identifier }).strict(),
|
|
14
|
+
z.object({ kind: z.literal("staff"), subject: identifier }).strict(),
|
|
15
|
+
z.object({ kind: z.literal("operator"), subject: identifier }).strict()
|
|
16
|
+
]);
|
|
17
|
+
var sessionSchema = authScopeSchema.extend({
|
|
18
|
+
id: identifier,
|
|
19
|
+
principal: principalSchema,
|
|
20
|
+
expiresAt: z.number()
|
|
21
|
+
});
|
|
22
|
+
var exchangeSchema = authScopeSchema.extend({
|
|
23
|
+
identity: z.object({ issuer: identifier, subject: z.string().min(1).max(200) }).strict(),
|
|
24
|
+
role: z.enum(["member", "staff", "operator"])
|
|
25
|
+
}).strict();
|
|
26
|
+
var exchangeResultSchema = z.object({
|
|
27
|
+
token: z.string(),
|
|
28
|
+
session: sessionSchema
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
authScopeSchema,
|
|
33
|
+
principalSchema,
|
|
34
|
+
sessionSchema,
|
|
35
|
+
exchangeSchema,
|
|
36
|
+
exchangeResultSchema
|
|
37
|
+
};
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
authScopeSchema,
|
|
3
|
+
exchangeResultSchema,
|
|
4
|
+
sessionSchema
|
|
5
|
+
} from "./chunk-6IXQRMGW.js";
|
|
1
6
|
import {
|
|
2
7
|
attemptSchema,
|
|
3
8
|
entitlementSchema,
|
|
@@ -572,80 +577,54 @@ function observeProgress(transport, listener, options = {}, onDispose = () => {
|
|
|
572
577
|
// src/index.ts
|
|
573
578
|
import { z as z7 } from "zod";
|
|
574
579
|
|
|
575
|
-
// src/auth.ts
|
|
576
|
-
import { z as z3 } from "zod";
|
|
577
|
-
var authScopeSchema = z3.object({
|
|
578
|
-
organization: identifier,
|
|
579
|
-
project: identifier,
|
|
580
|
-
environment: z3.enum(["test", "live"])
|
|
581
|
-
}).strict();
|
|
582
|
-
var principalSchema = z3.discriminatedUnion("kind", [
|
|
583
|
-
z3.object({ kind: z3.literal("member"), member: identifier }).strict(),
|
|
584
|
-
z3.object({ kind: z3.literal("staff"), subject: identifier }).strict(),
|
|
585
|
-
z3.object({ kind: z3.literal("operator"), subject: identifier }).strict()
|
|
586
|
-
]);
|
|
587
|
-
var sessionSchema = authScopeSchema.extend({
|
|
588
|
-
id: identifier,
|
|
589
|
-
principal: principalSchema,
|
|
590
|
-
expiresAt: z3.number()
|
|
591
|
-
});
|
|
592
|
-
var exchangeSchema = authScopeSchema.extend({
|
|
593
|
-
identity: z3.object({ issuer: identifier, subject: z3.string().min(1).max(200) }).strict(),
|
|
594
|
-
role: z3.enum(["member", "staff", "operator"])
|
|
595
|
-
}).strict();
|
|
596
|
-
var exchangeResultSchema = z3.object({
|
|
597
|
-
token: z3.string(),
|
|
598
|
-
session: sessionSchema
|
|
599
|
-
});
|
|
600
|
-
|
|
601
580
|
// src/wallet.ts
|
|
602
|
-
import { z as
|
|
603
|
-
var solanaAddressSchema =
|
|
604
|
-
var walletConnectionSchema =
|
|
605
|
-
chain:
|
|
581
|
+
import { z as z3 } from "zod";
|
|
582
|
+
var solanaAddressSchema = z3.string().min(32).max(44).regex(/^[1-9A-HJ-NP-Za-km-z]+$/);
|
|
583
|
+
var walletConnectionSchema = z3.object({
|
|
584
|
+
chain: z3.literal("solana"),
|
|
606
585
|
address: solanaAddressSchema,
|
|
607
|
-
verifiedAt:
|
|
608
|
-
revision:
|
|
586
|
+
verifiedAt: z3.number().int().nonnegative(),
|
|
587
|
+
revision: z3.number().int().positive()
|
|
609
588
|
}).strict();
|
|
610
|
-
var walletChallengeInputSchema =
|
|
611
|
-
chain:
|
|
589
|
+
var walletChallengeInputSchema = z3.object({
|
|
590
|
+
chain: z3.literal("solana"),
|
|
612
591
|
address: solanaAddressSchema
|
|
613
592
|
}).strict();
|
|
614
593
|
var walletChallengeSchema = walletChallengeInputSchema.extend({
|
|
615
|
-
id:
|
|
616
|
-
message:
|
|
617
|
-
expiresAt:
|
|
594
|
+
id: z3.string().uuid(),
|
|
595
|
+
message: z3.string(),
|
|
596
|
+
expiresAt: z3.number()
|
|
618
597
|
});
|
|
619
|
-
var walletProofSchema =
|
|
620
|
-
challenge:
|
|
621
|
-
signature:
|
|
598
|
+
var walletProofSchema = z3.object({
|
|
599
|
+
challenge: z3.string().uuid(),
|
|
600
|
+
signature: z3.string().min(64).max(88).regex(/^[1-9A-HJ-NP-Za-km-z]+$/)
|
|
622
601
|
}).strict();
|
|
623
|
-
var solanaBalanceSchema =
|
|
602
|
+
var solanaBalanceSchema = z3.object({
|
|
624
603
|
address: solanaAddressSchema,
|
|
625
|
-
network:
|
|
626
|
-
lamports:
|
|
627
|
-
slot:
|
|
628
|
-
observedAt:
|
|
604
|
+
network: z3.literal("mainnet-beta"),
|
|
605
|
+
lamports: z3.string().regex(/^(0|[1-9][0-9]*)$/),
|
|
606
|
+
slot: z3.number().int().nonnegative().safe(),
|
|
607
|
+
observedAt: z3.number().int().nonnegative()
|
|
629
608
|
}).strict();
|
|
630
609
|
|
|
631
610
|
// src/collection.ts
|
|
632
|
-
import { z as
|
|
633
|
-
var collectionCodeSchema =
|
|
634
|
-
var collectionPassSchema =
|
|
611
|
+
import { z as z4 } from "zod";
|
|
612
|
+
var collectionCodeSchema = z4.string().regex(/^relay:collect:[a-f0-9]{64}$/);
|
|
613
|
+
var collectionPassSchema = z4.object({
|
|
635
614
|
code: collectionCodeSchema,
|
|
636
|
-
expiresAt:
|
|
615
|
+
expiresAt: z4.number(),
|
|
637
616
|
entitlement: identifier
|
|
638
617
|
});
|
|
639
|
-
var collectionResolveSchema =
|
|
618
|
+
var collectionResolveSchema = z4.object({ code: collectionCodeSchema }).strict();
|
|
640
619
|
var collectionBeginSchema = collectionResolveSchema.extend({
|
|
641
620
|
actionId: identifier,
|
|
642
|
-
revision:
|
|
621
|
+
revision: z4.number().int().positive(),
|
|
643
622
|
selection: pickupSelectionSchema.optional()
|
|
644
623
|
});
|
|
645
|
-
var collectionPreviewSchema =
|
|
624
|
+
var collectionPreviewSchema = z4.object({
|
|
646
625
|
entitlement: entitlementSchema,
|
|
647
626
|
inventory: pickupAvailabilitySchema,
|
|
648
|
-
expiresAt:
|
|
627
|
+
expiresAt: z4.number()
|
|
649
628
|
});
|
|
650
629
|
|
|
651
630
|
// src/configuration.ts
|
|
@@ -663,26 +642,51 @@ function questConfiguration(release) {
|
|
|
663
642
|
}
|
|
664
643
|
|
|
665
644
|
// src/deployments.ts
|
|
666
|
-
import { z as
|
|
645
|
+
import { z as z5 } from "zod";
|
|
667
646
|
var projectDeploymentSchema = catalogDeploymentSchema.omit({ expectedRevision: true }).extend({
|
|
668
|
-
releases:
|
|
647
|
+
releases: z5.array(releaseSchema).max(50).default([])
|
|
669
648
|
}).refine(
|
|
670
649
|
(value) => value.releases.length > 0 || value.types.length > 0 || value.collections.length > 0 || value.supportedInteractions !== void 0,
|
|
671
650
|
"No resources configured. Add quests, questTypes, collections, or supportedInteractions to relay.json."
|
|
672
651
|
);
|
|
673
|
-
var deploymentPreviewSchema =
|
|
652
|
+
var deploymentPreviewSchema = z5.object({
|
|
674
653
|
id: identifier,
|
|
675
|
-
baseRevision:
|
|
676
|
-
releases:
|
|
677
|
-
types:
|
|
678
|
-
collections:
|
|
679
|
-
supportedInteractions:
|
|
654
|
+
baseRevision: z5.number().int().nonnegative(),
|
|
655
|
+
releases: z5.array(publishedReleaseSchema),
|
|
656
|
+
types: z5.array(questTypeVersionSchema),
|
|
657
|
+
collections: z5.array(questCollectionSchema),
|
|
658
|
+
supportedInteractions: z5.array(interactionSchema)
|
|
680
659
|
});
|
|
681
|
-
var publishDeploymentSchema =
|
|
660
|
+
var publishDeploymentSchema = z5.object({ id: identifier }).strict();
|
|
682
661
|
var deploymentResultSchema = deploymentPreviewSchema.extend({
|
|
683
|
-
revision:
|
|
662
|
+
revision: z5.number().int().positive()
|
|
684
663
|
});
|
|
685
664
|
|
|
665
|
+
// src/identity-integration.ts
|
|
666
|
+
import { z as z6 } from "zod";
|
|
667
|
+
var identityIntegrationInputSchema = z6.object({
|
|
668
|
+
name: z6.string().trim().min(1).max(80),
|
|
669
|
+
origin: z6.string().url().refine((value) => {
|
|
670
|
+
const url = new URL(value);
|
|
671
|
+
return url.protocol === "https:" && url.origin === value;
|
|
672
|
+
}, "Use an exact HTTPS application origin")
|
|
673
|
+
}).strict();
|
|
674
|
+
var identityIntegrationSchema = authScopeSchema.extend({
|
|
675
|
+
id: z6.string().uuid(),
|
|
676
|
+
name: z6.string(),
|
|
677
|
+
origin: z6.string(),
|
|
678
|
+
expiresAt: z6.number()
|
|
679
|
+
});
|
|
680
|
+
var identityIntegrationSecretSchema = identityIntegrationSchema.extend(
|
|
681
|
+
{
|
|
682
|
+
token: z6.string()
|
|
683
|
+
}
|
|
684
|
+
);
|
|
685
|
+
var participantExchangeSchema = z6.object({
|
|
686
|
+
subject: z6.string().min(1).max(200),
|
|
687
|
+
previousToken: z6.string().max(200).optional()
|
|
688
|
+
}).strict();
|
|
689
|
+
|
|
686
690
|
// src/index.ts
|
|
687
691
|
function createRelayClient(options) {
|
|
688
692
|
async function send(path, init = {}) {
|
|
@@ -904,6 +908,7 @@ function createRelayClient(options) {
|
|
|
904
908
|
signOut: () => changeSession(
|
|
905
909
|
() => request("/v1/auth/logout", z7.object({ ok: z7.boolean() }), json({}))
|
|
906
910
|
),
|
|
911
|
+
/** Local development only. Existing hosted apps use createParticipantBackend from /portal-proxy. */
|
|
907
912
|
exchange: (input) => request("/v1/auth/exchange", exchangeResultSchema, json(input))
|
|
908
913
|
},
|
|
909
914
|
me: {
|
|
@@ -1031,11 +1036,6 @@ export {
|
|
|
1031
1036
|
QuestUpdatedError,
|
|
1032
1037
|
reconcileQuestDraft,
|
|
1033
1038
|
questActions,
|
|
1034
|
-
authScopeSchema,
|
|
1035
|
-
principalSchema,
|
|
1036
|
-
sessionSchema,
|
|
1037
|
-
exchangeSchema,
|
|
1038
|
-
exchangeResultSchema,
|
|
1039
1039
|
solanaAddressSchema,
|
|
1040
1040
|
walletConnectionSchema,
|
|
1041
1041
|
walletChallengeInputSchema,
|
|
@@ -1052,5 +1052,9 @@ export {
|
|
|
1052
1052
|
deploymentPreviewSchema,
|
|
1053
1053
|
publishDeploymentSchema,
|
|
1054
1054
|
deploymentResultSchema,
|
|
1055
|
+
identityIntegrationInputSchema,
|
|
1056
|
+
identityIntegrationSchema,
|
|
1057
|
+
identityIntegrationSecretSchema,
|
|
1058
|
+
participantExchangeSchema,
|
|
1055
1059
|
createRelayClient
|
|
1056
1060
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -3502,6 +3502,40 @@ declare const deploymentResultSchema: z.ZodObject<{
|
|
|
3502
3502
|
}, z.core.$strip>;
|
|
3503
3503
|
type DeploymentPreview = z.infer<typeof deploymentPreviewSchema>;
|
|
3504
3504
|
|
|
3505
|
+
declare const identityIntegrationInputSchema: z.ZodObject<{
|
|
3506
|
+
name: z.ZodString;
|
|
3507
|
+
origin: z.ZodString;
|
|
3508
|
+
}, z.core.$strict>;
|
|
3509
|
+
declare const identityIntegrationSchema: z.ZodObject<{
|
|
3510
|
+
organization: z.ZodString;
|
|
3511
|
+
project: z.ZodString;
|
|
3512
|
+
environment: z.ZodEnum<{
|
|
3513
|
+
test: "test";
|
|
3514
|
+
live: "live";
|
|
3515
|
+
}>;
|
|
3516
|
+
id: z.ZodString;
|
|
3517
|
+
name: z.ZodString;
|
|
3518
|
+
origin: z.ZodString;
|
|
3519
|
+
expiresAt: z.ZodNumber;
|
|
3520
|
+
}, z.core.$strict>;
|
|
3521
|
+
declare const identityIntegrationSecretSchema: z.ZodObject<{
|
|
3522
|
+
organization: z.ZodString;
|
|
3523
|
+
project: z.ZodString;
|
|
3524
|
+
environment: z.ZodEnum<{
|
|
3525
|
+
test: "test";
|
|
3526
|
+
live: "live";
|
|
3527
|
+
}>;
|
|
3528
|
+
id: z.ZodString;
|
|
3529
|
+
name: z.ZodString;
|
|
3530
|
+
origin: z.ZodString;
|
|
3531
|
+
expiresAt: z.ZodNumber;
|
|
3532
|
+
token: z.ZodString;
|
|
3533
|
+
}, z.core.$strict>;
|
|
3534
|
+
declare const participantExchangeSchema: z.ZodObject<{
|
|
3535
|
+
subject: z.ZodString;
|
|
3536
|
+
previousToken: z.ZodOptional<z.ZodString>;
|
|
3537
|
+
}, z.core.$strict>;
|
|
3538
|
+
|
|
3505
3539
|
declare function createRelayClient(options: {
|
|
3506
3540
|
baseUrl: string;
|
|
3507
3541
|
token?: string;
|
|
@@ -4101,6 +4135,7 @@ declare function createRelayClient(options: {
|
|
|
4101
4135
|
signOut: () => Promise<{
|
|
4102
4136
|
ok: boolean;
|
|
4103
4137
|
}>;
|
|
4138
|
+
/** Local development only. Existing hosted apps use createParticipantBackend from /portal-proxy. */
|
|
4104
4139
|
exchange: (input: ExchangeInput) => Promise<{
|
|
4105
4140
|
token: string;
|
|
4106
4141
|
session: {
|
|
@@ -5775,4 +5810,4 @@ declare function createRelayClient(options: {
|
|
|
5775
5810
|
}>;
|
|
5776
5811
|
};
|
|
5777
5812
|
|
|
5778
|
-
export { Attempt, type ClaimSubmission, type CollectionPass, type DeploymentPreview, type ExchangeInput, MemberListOptions, MemberProgress, type PhotoSubmission, type ProgressObservation, type ProgressObserver, PublishedRelease, type QuestActionResult, type QuestCatalog, type QuestController, type QuestDraft, type QuestInstance, type QuestInteraction, QuestUpdatedError, type QuestView, QuizEvidence, type QuizSubmission, RelayError, ReleaseInput, ReviewListOptions, type Session, type SubmissionDraft, type SubmissionStatus, type SubmissionStore, SubmitInput, authScopeSchema, beginHandoverSchema, catalogDeploymentPreviewSchema, catalogDeploymentSchema, collectionBeginSchema, collectionCodeSchema, collectionPassSchema, collectionPreviewSchema, collectionResolveSchema, collectionSlotSchema, collectionViewSchema, createRelayClient, deploymentPreviewSchema, deploymentResultSchema, errorSchema, exchangeResultSchema, exchangeSchema, interactionSchema, principalSchema, projectDeploymentSchema, publishDeploymentSchema, publishQuestDraftSchema, questActions, questCatalogSchema, questCollectionSchema, questConfiguration, questDescriptionSchema, questDraftChangesSchema, questDraftSchema, questExperienceSchema, questInstanceSchema, questInteraction, questPublicationPreviewSchema, questTypeVersionSchema, questViewSchema, reconcileQuestDraft, saveQuestDraftSchema, sessionSchema, walletChallengeInputSchema, walletProofSchema };
|
|
5813
|
+
export { Attempt, type ClaimSubmission, type CollectionPass, type DeploymentPreview, type ExchangeInput, MemberListOptions, MemberProgress, type PhotoSubmission, type ProgressObservation, type ProgressObserver, PublishedRelease, type QuestActionResult, type QuestCatalog, type QuestController, type QuestDraft, type QuestInstance, type QuestInteraction, QuestUpdatedError, type QuestView, QuizEvidence, type QuizSubmission, RelayError, ReleaseInput, ReviewListOptions, type Session, type SubmissionDraft, type SubmissionStatus, type SubmissionStore, SubmitInput, authScopeSchema, beginHandoverSchema, catalogDeploymentPreviewSchema, catalogDeploymentSchema, collectionBeginSchema, collectionCodeSchema, collectionPassSchema, collectionPreviewSchema, collectionResolveSchema, collectionSlotSchema, collectionViewSchema, createRelayClient, deploymentPreviewSchema, deploymentResultSchema, errorSchema, exchangeResultSchema, exchangeSchema, identityIntegrationInputSchema, identityIntegrationSchema, identityIntegrationSecretSchema, interactionSchema, participantExchangeSchema, principalSchema, projectDeploymentSchema, publishDeploymentSchema, publishQuestDraftSchema, questActions, questCatalogSchema, questCollectionSchema, questConfiguration, questDescriptionSchema, questDraftChangesSchema, questDraftSchema, questExperienceSchema, questInstanceSchema, questInteraction, questPublicationPreviewSchema, questTypeVersionSchema, questViewSchema, reconcileQuestDraft, saveQuestDraftSchema, sessionSchema, walletChallengeInputSchema, walletProofSchema };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
QuestUpdatedError,
|
|
3
3
|
RelayError,
|
|
4
|
-
authScopeSchema,
|
|
5
4
|
catalogDeploymentPreviewSchema,
|
|
6
5
|
catalogDeploymentSchema,
|
|
7
6
|
collectionBeginSchema,
|
|
@@ -14,10 +13,11 @@ import {
|
|
|
14
13
|
createRelayClient,
|
|
15
14
|
deploymentPreviewSchema,
|
|
16
15
|
deploymentResultSchema,
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
identityIntegrationInputSchema,
|
|
17
|
+
identityIntegrationSchema,
|
|
18
|
+
identityIntegrationSecretSchema,
|
|
19
19
|
interactionSchema,
|
|
20
|
-
|
|
20
|
+
participantExchangeSchema,
|
|
21
21
|
projectDeploymentSchema,
|
|
22
22
|
publishDeploymentSchema,
|
|
23
23
|
publishQuestDraftSchema,
|
|
@@ -35,14 +35,20 @@ import {
|
|
|
35
35
|
questViewSchema,
|
|
36
36
|
reconcileQuestDraft,
|
|
37
37
|
saveQuestDraftSchema,
|
|
38
|
-
sessionSchema,
|
|
39
38
|
solanaAddressSchema,
|
|
40
39
|
solanaBalanceSchema,
|
|
41
40
|
walletChallengeInputSchema,
|
|
42
41
|
walletChallengeSchema,
|
|
43
42
|
walletConnectionSchema,
|
|
44
43
|
walletProofSchema
|
|
45
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-L757OYXZ.js";
|
|
45
|
+
import {
|
|
46
|
+
authScopeSchema,
|
|
47
|
+
exchangeResultSchema,
|
|
48
|
+
exchangeSchema,
|
|
49
|
+
principalSchema,
|
|
50
|
+
sessionSchema
|
|
51
|
+
} from "./chunk-6IXQRMGW.js";
|
|
46
52
|
import {
|
|
47
53
|
artifactSchema,
|
|
48
54
|
attemptSchema,
|
|
@@ -134,12 +140,16 @@ export {
|
|
|
134
140
|
exchangeResultSchema,
|
|
135
141
|
exchangeSchema,
|
|
136
142
|
identifier,
|
|
143
|
+
identityIntegrationInputSchema,
|
|
144
|
+
identityIntegrationSchema,
|
|
145
|
+
identityIntegrationSecretSchema,
|
|
137
146
|
interactionSchema,
|
|
138
147
|
mediaUrlSchema,
|
|
139
148
|
memberListSchema,
|
|
140
149
|
memberPageSchema,
|
|
141
150
|
memberProgressSchema,
|
|
142
151
|
parseSettings,
|
|
152
|
+
participantExchangeSchema,
|
|
143
153
|
photoResultSchema,
|
|
144
154
|
pickupAllocationSchema,
|
|
145
155
|
pickupAvailabilitySchema,
|
package/dist/portal-proxy.d.ts
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Server-only proxy: browser cookies stay on the participant origin.
|
|
3
|
+
* Point upstream at a participant deployment with trusted server scope configured.
|
|
4
|
+
* Browser Authorization and organization/project/environment selectors are discarded.
|
|
5
|
+
* This does not provide backend identity exchange or configure upstream scope.
|
|
6
|
+
*/
|
|
2
7
|
declare function proxyParticipant(request: Request, upstream: {
|
|
3
8
|
baseUrl: string;
|
|
4
9
|
fetch: typeof fetch;
|
|
5
10
|
}): Promise<Response>;
|
|
11
|
+
/** Use only in an app server route. authenticate must verify the app's own session. */
|
|
12
|
+
declare function createParticipantBackend(options: {
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
integrationKey: string;
|
|
15
|
+
origin: string;
|
|
16
|
+
authenticate: (request: Request) => Promise<{
|
|
17
|
+
subject: string;
|
|
18
|
+
} | null>;
|
|
19
|
+
fetch?: typeof fetch;
|
|
20
|
+
}): (request: Request) => Promise<Response>;
|
|
6
21
|
|
|
7
|
-
export { proxyParticipant };
|
|
22
|
+
export { createParticipantBackend, proxyParticipant };
|
package/dist/portal-proxy.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
exchangeResultSchema
|
|
3
|
+
} from "./chunk-6IXQRMGW.js";
|
|
4
|
+
import "./chunk-C2KOMNLG.js";
|
|
5
|
+
|
|
1
6
|
// src/portal-proxy.ts
|
|
2
7
|
async function proxyParticipant(request, upstream) {
|
|
3
8
|
const incoming = new URL(request.url);
|
|
@@ -43,6 +48,74 @@ async function proxyParticipant(request, upstream) {
|
|
|
43
48
|
headers: resultHeaders
|
|
44
49
|
});
|
|
45
50
|
}
|
|
51
|
+
function createParticipantBackend(options) {
|
|
52
|
+
const origin = new URL(options.origin);
|
|
53
|
+
const base = new URL(options.baseUrl);
|
|
54
|
+
if (origin.protocol !== "https:" || origin.origin !== options.origin || base.protocol !== "https:" || base.origin !== options.baseUrl)
|
|
55
|
+
throw new Error(
|
|
56
|
+
"Configure exact HTTPS application and participant API origins"
|
|
57
|
+
);
|
|
58
|
+
if (!options.integrationKey.startsWith("di_"))
|
|
59
|
+
throw new Error(
|
|
60
|
+
"Use an identity integration server key from Console Settings"
|
|
61
|
+
);
|
|
62
|
+
const send = options.fetch ?? fetch;
|
|
63
|
+
const cookie = (token) => `domino_app_session=${token}; Path=/relay; HttpOnly; Secure; SameSite=Strict; Max-Age=${token ? 28800 : 0}`;
|
|
64
|
+
return async (request) => {
|
|
65
|
+
const url = new URL(request.url);
|
|
66
|
+
const reject = (error, status) => Response.json(
|
|
67
|
+
{ error },
|
|
68
|
+
{ status, headers: { "Cache-Control": "no-store" } }
|
|
69
|
+
);
|
|
70
|
+
if (url.origin !== options.origin)
|
|
71
|
+
return reject("Unexpected application origin", 403);
|
|
72
|
+
if (request.method !== "GET" && (request.headers.get("Origin") !== options.origin || request.headers.get("X-Relay-CSRF") !== "1"))
|
|
73
|
+
return reject("Untrusted browser request", 403);
|
|
74
|
+
const identity = await options.authenticate(request);
|
|
75
|
+
if (!identity)
|
|
76
|
+
return Response.json(
|
|
77
|
+
url.pathname === "/relay/v1/auth/session" ? null : { error: "Sign in to the application" },
|
|
78
|
+
{
|
|
79
|
+
status: url.pathname === "/relay/v1/auth/session" ? 200 : 401,
|
|
80
|
+
headers: { "Set-Cookie": cookie(""), "Cache-Control": "no-store" }
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
const previousToken = request.headers.get("Cookie")?.split(";").map((value) => value.trim()).find((value) => value.startsWith("domino_app_session="))?.slice("domino_app_session=".length);
|
|
84
|
+
const exchanged = await send(options.baseUrl + "/v1/auth/exchange", {
|
|
85
|
+
method: "POST",
|
|
86
|
+
redirect: "error",
|
|
87
|
+
headers: {
|
|
88
|
+
Authorization: "Bearer " + options.integrationKey,
|
|
89
|
+
"Content-Type": "application/json"
|
|
90
|
+
},
|
|
91
|
+
body: JSON.stringify({ subject: identity.subject, previousToken })
|
|
92
|
+
});
|
|
93
|
+
if (!exchanged.ok)
|
|
94
|
+
return reject(
|
|
95
|
+
"Domino identity exchange failed. Check the server integration key and its expiry in Console Settings.",
|
|
96
|
+
exchanged.status
|
|
97
|
+
);
|
|
98
|
+
const { token } = exchangeResultSchema.parse(await exchanged.json());
|
|
99
|
+
const response = await proxyParticipant(request, {
|
|
100
|
+
baseUrl: options.baseUrl,
|
|
101
|
+
fetch: async (target, init) => {
|
|
102
|
+
const headers2 = new Headers(init?.headers);
|
|
103
|
+
headers2.delete("Cookie");
|
|
104
|
+
headers2.set("Authorization", "Bearer " + token);
|
|
105
|
+
headers2.set("X-Relay-Integration-Key", options.integrationKey);
|
|
106
|
+
headers2.set("Origin", options.origin);
|
|
107
|
+
return send(target, { ...init, headers: headers2, redirect: "error" });
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
const headers = new Headers(response.headers);
|
|
111
|
+
headers.set(
|
|
112
|
+
"Set-Cookie",
|
|
113
|
+
cookie(url.pathname === "/relay/v1/auth/logout" ? "" : token)
|
|
114
|
+
);
|
|
115
|
+
return new Response(response.body, { status: response.status, headers });
|
|
116
|
+
};
|
|
117
|
+
}
|
|
46
118
|
export {
|
|
119
|
+
createParticipantBackend,
|
|
47
120
|
proxyParticipant
|
|
48
121
|
};
|