@domino-sdk/relay 0.2.0 → 0.4.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/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,12 @@ import {
14
13
  createRelayClient,
15
14
  deploymentPreviewSchema,
16
15
  deploymentResultSchema,
17
- exchangeResultSchema,
18
- exchangeSchema,
16
+ identityIntegrationInputSchema,
17
+ identityIntegrationSchema,
18
+ identityIntegrationSecretSchema,
19
19
  interactionSchema,
20
- principalSchema,
20
+ participantExchangeSchema,
21
+ projectCatalogArtifactSchema,
21
22
  projectDeploymentSchema,
22
23
  publishDeploymentSchema,
23
24
  publishQuestDraftSchema,
@@ -35,28 +36,68 @@ import {
35
36
  questViewSchema,
36
37
  reconcileQuestDraft,
37
38
  saveQuestDraftSchema,
38
- sessionSchema,
39
39
  solanaAddressSchema,
40
40
  solanaBalanceSchema,
41
41
  walletChallengeInputSchema,
42
42
  walletChallengeSchema,
43
43
  walletConnectionSchema,
44
44
  walletProofSchema
45
- } from "./chunk-NC3UAP6T.js";
45
+ } from "./chunk-KQVL6MOH.js";
46
+ import {
47
+ defineLeaderboard,
48
+ defineReferral,
49
+ leaderboardArtifactSchema,
50
+ leaderboardDefinitionSchema,
51
+ leaderboardExclusionSchema,
52
+ leaderboardGroupSchema,
53
+ leaderboardPageSchema,
54
+ leaderboardPreviewSchema,
55
+ leaderboardQuerySchema,
56
+ leaderboardRowSchema,
57
+ leaderboardWindowSchema,
58
+ pointsAccountSchema,
59
+ pointsEntrySchema,
60
+ pointsMutationSchema,
61
+ pointsResultSchema,
62
+ publishedLeaderboardSchema,
63
+ publishedReferralSchema,
64
+ referralAcceptSchema,
65
+ referralAccountSchema,
66
+ referralArtifactSchema,
67
+ referralControlSchema,
68
+ referralDefinitionSchema,
69
+ referralHistorySchema,
70
+ referralManagementSchema,
71
+ referralRelationshipSchema,
72
+ referralSummarySchema
73
+ } from "./chunk-TXL43HL3.js";
74
+ import {
75
+ authScopeSchema,
76
+ exchangeResultSchema,
77
+ exchangeSchema,
78
+ principalSchema,
79
+ sessionSchema
80
+ } from "./chunk-QWRSUSNB.js";
46
81
  import {
82
+ accountConnectionSchema,
47
83
  artifactSchema,
48
84
  attemptSchema,
85
+ authProviderSchema,
49
86
  batchReleaseSchema,
50
87
  beginHandoverSchema,
51
88
  completionRecordSchema,
52
89
  configurePickupSchema,
53
90
  confirmHandoverSchema,
54
91
  decisionSchema,
92
+ discordMemberInputSchema,
93
+ discordMemberSchema,
94
+ discordServerSchema,
55
95
  entitlementSchema,
56
96
  errorSchema,
57
97
  eventSchema,
58
98
  evidenceSchema,
59
99
  identifier,
100
+ integrationProviderSchema,
60
101
  mediaUrlSchema,
61
102
  memberListSchema,
62
103
  memberPageSchema,
@@ -70,6 +111,7 @@ import {
70
111
  pickupSelectionSchema,
71
112
  pointsRewardSchema,
72
113
  prerequisiteSchema,
114
+ projectIntegrationSchema,
73
115
  publishedReleaseSchema,
74
116
  questAvailabilitySchema,
75
117
  questDescriptionSchema,
@@ -102,12 +144,14 @@ import {
102
144
  tierRewardSchema,
103
145
  tieredRewardDefinitionSchema,
104
146
  triggerSchema
105
- } from "./chunk-C2KOMNLG.js";
147
+ } from "./chunk-3IQ4KUKF.js";
106
148
  export {
107
149
  QuestUpdatedError,
108
150
  RelayError,
151
+ accountConnectionSchema,
109
152
  artifactSchema,
110
153
  attemptSchema,
154
+ authProviderSchema,
111
155
  authScopeSchema,
112
156
  batchReleaseSchema,
113
157
  beginHandoverSchema,
@@ -125,8 +169,13 @@ export {
125
169
  confirmHandoverSchema,
126
170
  createRelayClient,
127
171
  decisionSchema,
172
+ defineLeaderboard,
173
+ defineReferral,
128
174
  deploymentPreviewSchema,
129
175
  deploymentResultSchema,
176
+ discordMemberInputSchema,
177
+ discordMemberSchema,
178
+ discordServerSchema,
130
179
  entitlementSchema,
131
180
  errorSchema,
132
181
  eventSchema,
@@ -134,24 +183,46 @@ export {
134
183
  exchangeResultSchema,
135
184
  exchangeSchema,
136
185
  identifier,
186
+ identityIntegrationInputSchema,
187
+ identityIntegrationSchema,
188
+ identityIntegrationSecretSchema,
189
+ integrationProviderSchema,
137
190
  interactionSchema,
191
+ leaderboardArtifactSchema,
192
+ leaderboardDefinitionSchema,
193
+ leaderboardExclusionSchema,
194
+ leaderboardGroupSchema,
195
+ leaderboardPageSchema,
196
+ leaderboardPreviewSchema,
197
+ leaderboardQuerySchema,
198
+ leaderboardRowSchema,
199
+ leaderboardWindowSchema,
138
200
  mediaUrlSchema,
139
201
  memberListSchema,
140
202
  memberPageSchema,
141
203
  memberProgressSchema,
142
204
  parseSettings,
205
+ participantExchangeSchema,
143
206
  photoResultSchema,
144
207
  pickupAllocationSchema,
145
208
  pickupAvailabilitySchema,
146
209
  pickupCatalogSchema,
147
210
  pickupPolicySchema,
148
211
  pickupSelectionSchema,
212
+ pointsAccountSchema,
213
+ pointsEntrySchema,
214
+ pointsMutationSchema,
215
+ pointsResultSchema,
149
216
  pointsRewardSchema,
150
217
  prerequisiteSchema,
151
218
  principalSchema,
219
+ projectCatalogArtifactSchema,
152
220
  projectDeploymentSchema,
221
+ projectIntegrationSchema,
153
222
  publishDeploymentSchema,
154
223
  publishQuestDraftSchema,
224
+ publishedLeaderboardSchema,
225
+ publishedReferralSchema,
155
226
  publishedReleaseSchema,
156
227
  questActions,
157
228
  questAvailabilitySchema,
@@ -176,6 +247,15 @@ export {
176
247
  quizQuestionSchema,
177
248
  quizQuestionsSchema,
178
249
  reconcileQuestDraft,
250
+ referralAcceptSchema,
251
+ referralAccountSchema,
252
+ referralArtifactSchema,
253
+ referralControlSchema,
254
+ referralDefinitionSchema,
255
+ referralHistorySchema,
256
+ referralManagementSchema,
257
+ referralRelationshipSchema,
258
+ referralSummarySchema,
179
259
  releaseSchema,
180
260
  reservationSchema,
181
261
  reviewItemSchema,
@@ -1,7 +1,22 @@
1
- /** Server-only proxy: browser cookies stay on the participant origin. */
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 };
@@ -1,12 +1,17 @@
1
+ import {
2
+ exchangeResultSchema
3
+ } from "./chunk-QWRSUSNB.js";
4
+ import "./chunk-3IQ4KUKF.js";
5
+
1
6
  // src/portal-proxy.ts
2
7
  async function proxyParticipant(request, upstream) {
3
8
  const incoming = new URL(request.url);
4
9
  const path = incoming.pathname.slice("/relay".length);
5
- const allowed = incoming.pathname.startsWith("/relay/") && (/^\/v1\/auth\/(providers|connections|start|authorize|complete|session|logout|email\/start|email\/verify|callback\/(google|apple|x|discord))$/.test(
10
+ const allowed = incoming.pathname.startsWith("/relay/") && (/^\/v1\/auth\/(providers|connections|accounts(?:\/disconnect)?|start|authorize|complete|session|logout|email\/start|email\/verify|callback\/[a-z][a-z0-9-]*)$/.test(
6
11
  path
7
12
  ) || /^\/v1\/me\/(progress|experience|attempts|evidence|pass|collection-pass|wallet(?:\/challenge|\/verify)?)$/.test(
8
13
  path
9
- ) || /^\/v1\/attempts\/[\w-]+(?:\/retry)?$/.test(path));
14
+ ) || /^\/v1\/attempts\/[\w-]+(?:\/retry)?$/.test(path) || /^\/v1\/referrals(?:\/(me|history))?$/.test(path) && request.method === "GET" || path === "/v1/referrals/accept" && request.method === "POST" || request.method === "GET" && /^\/v1\/leaderboards(?:\/[\w-]+)?$/.test(path));
10
15
  if (!allowed || !["GET", "POST"].includes(request.method))
11
16
  return Response.json({ error: "Route not found" }, { status: 404 });
12
17
  const target = new URL(upstream.baseUrl);
@@ -43,6 +48,76 @@ 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=Lax; 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: "manual",
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
+ const returnBinding = request.headers.get("Cookie")?.split(";").map((value) => value.trim()).find((value) => value.startsWith("relay_auth_return="));
105
+ if (returnBinding) headers2.set("Cookie", returnBinding);
106
+ headers2.set("Authorization", "Bearer " + token);
107
+ headers2.set("X-Relay-Integration-Key", options.integrationKey);
108
+ headers2.set("Origin", options.origin);
109
+ return send(target, { ...init, headers: headers2, redirect: "manual" });
110
+ }
111
+ });
112
+ const headers = new Headers(response.headers);
113
+ headers.append(
114
+ "Set-Cookie",
115
+ cookie(url.pathname === "/relay/v1/auth/logout" ? "" : token)
116
+ );
117
+ return new Response(response.body, { status: response.status, headers });
118
+ };
119
+ }
46
120
  export {
121
+ createParticipantBackend,
47
122
  proxyParticipant
48
123
  };
package/dist/schema.d.ts CHANGED
@@ -219,6 +219,9 @@ declare const questDescriptionSchema: z.ZodObject<{
219
219
  }, z.core.$strict>>;
220
220
  }, z.core.$strict>>;
221
221
  }, z.core.$strict>>;
222
+ integrations: z.ZodDefault<z.ZodArray<z.ZodEnum<{
223
+ discord: "discord";
224
+ }>>>;
222
225
  fields: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{
223
226
  kind: z.ZodLiteral<"quiz">;
224
227
  default: z.ZodArray<z.ZodObject<{
@@ -401,6 +404,9 @@ declare const publishedReleaseSchema: z.ZodUnion<readonly [z.ZodObject<{
401
404
  }, z.core.$strict>>;
402
405
  }, z.core.$strict>>;
403
406
  }, z.core.$strict>>;
407
+ integrations: z.ZodDefault<z.ZodArray<z.ZodEnum<{
408
+ discord: "discord";
409
+ }>>>;
404
410
  fields: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{
405
411
  kind: z.ZodLiteral<"quiz">;
406
412
  default: z.ZodArray<z.ZodObject<{
@@ -595,6 +601,7 @@ declare const publishedReleaseSchema: z.ZodUnion<readonly [z.ZodObject<{
595
601
  } | undefined;
596
602
  } | undefined;
597
603
  };
604
+ integrations: "discord"[];
598
605
  fields: Record<string, {
599
606
  kind: "quiz";
600
607
  default: {
@@ -770,6 +777,9 @@ declare const templateSchema: z.ZodObject<{
770
777
  }, z.core.$strict>>;
771
778
  }, z.core.$strict>>;
772
779
  }, z.core.$strict>>;
780
+ integrations: z.ZodDefault<z.ZodArray<z.ZodEnum<{
781
+ discord: "discord";
782
+ }>>>;
773
783
  fields: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{
774
784
  kind: z.ZodLiteral<"quiz">;
775
785
  default: z.ZodArray<z.ZodObject<{
@@ -1179,6 +1189,12 @@ declare const memberProgressSchema: z.ZodObject<{
1179
1189
  }, z.core.$strict>>;
1180
1190
  }, z.core.$strict>>;
1181
1191
  }, z.core.$strict>>;
1192
+ connections: z.ZodDefault<z.ZodArray<z.ZodEnum<{
1193
+ discord: "discord";
1194
+ google: "google";
1195
+ apple: "apple";
1196
+ x: "x";
1197
+ }>>>;
1182
1198
  trigger: z.ZodUnion<readonly [z.ZodObject<{
1183
1199
  kind: z.ZodLiteral<"manual">;
1184
1200
  input: z.ZodEnum<{
@@ -1380,6 +1396,9 @@ declare const snapshotSchema: z.ZodObject<{
1380
1396
  }, z.core.$strict>>;
1381
1397
  }, z.core.$strict>>;
1382
1398
  }, z.core.$strict>>;
1399
+ integrations: z.ZodDefault<z.ZodArray<z.ZodEnum<{
1400
+ discord: "discord";
1401
+ }>>>;
1383
1402
  fields: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{
1384
1403
  kind: z.ZodLiteral<"quiz">;
1385
1404
  default: z.ZodArray<z.ZodObject<{
@@ -1574,6 +1593,7 @@ declare const snapshotSchema: z.ZodObject<{
1574
1593
  } | undefined;
1575
1594
  } | undefined;
1576
1595
  };
1596
+ integrations: "discord"[];
1577
1597
  fields: Record<string, {
1578
1598
  kind: "quiz";
1579
1599
  default: {
package/dist/schema.js CHANGED
@@ -48,7 +48,7 @@ import {
48
48
  tierRewardSchema,
49
49
  tieredRewardDefinitionSchema,
50
50
  triggerSchema
51
- } from "./chunk-C2KOMNLG.js";
51
+ } from "./chunk-3IQ4KUKF.js";
52
52
  export {
53
53
  artifactSchema,
54
54
  attemptSchema,