@minesa-org/mini-interaction 0.1.7 → 0.1.9

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.
@@ -239,6 +239,12 @@ export declare class MiniInteraction {
239
239
  * This is primarily used when Discord asks for a verification URL while setting up Linked Roles.
240
240
  * Provide an HTML file that contains the `{{OAUTH_URL}}` placeholder (or a custom placeholder defined in options)
241
241
  * and this helper will replace the token with a freshly generated OAuth link on every request.
242
+ *
243
+ * Available placeholders:
244
+ * - `{{OAUTH_URL}}` - HTML-escaped OAuth URL for links/buttons.
245
+ * - `{{OAUTH_URL_RAW}}` - raw OAuth URL, ideal for `<script>` usage.
246
+ * - `{{OAUTH_STATE}}` - HTML-escaped OAuth state value.
247
+ * - Custom placeholder name (from {@link DiscordOAuthVerificationPageOptions.placeholder}) and its `_RAW` variant.
242
248
  */
243
249
  discordOAuthVerificationPage(options?: DiscordOAuthVerificationPageOptions): MiniInteractionNodeHandler;
244
250
  /**
@@ -264,7 +270,7 @@ export declare class MiniInteraction {
264
270
  private loadHtmlTemplate;
265
271
  /**
266
272
  * Replaces placeholder tokens in a template with escaped HTML values.
267
- */
273
+ */
268
274
  private renderHtmlTemplate;
269
275
  /**
270
276
  * Normalizes placeholder tokens to the bare key the HTML renderer expects.
@@ -430,6 +430,12 @@ export class MiniInteraction {
430
430
  * This is primarily used when Discord asks for a verification URL while setting up Linked Roles.
431
431
  * Provide an HTML file that contains the `{{OAUTH_URL}}` placeholder (or a custom placeholder defined in options)
432
432
  * and this helper will replace the token with a freshly generated OAuth link on every request.
433
+ *
434
+ * Available placeholders:
435
+ * - `{{OAUTH_URL}}` - HTML-escaped OAuth URL for links/buttons.
436
+ * - `{{OAUTH_URL_RAW}}` - raw OAuth URL, ideal for `<script>` usage.
437
+ * - `{{OAUTH_STATE}}` - HTML-escaped OAuth state value.
438
+ * - Custom placeholder name (from {@link DiscordOAuthVerificationPageOptions.placeholder}) and its `_RAW` variant.
433
439
  */
434
440
  discordOAuthVerificationPage(options = {}) {
435
441
  const scopes = options.scopes ?? ["identify", "role_connections.write"];
@@ -440,12 +446,20 @@ export class MiniInteraction {
440
446
  return (_request, response) => {
441
447
  try {
442
448
  const { url, state } = generateOAuthUrl(oauthConfig, scopes);
443
- const html = this.renderHtmlTemplate(template, {
449
+ const values = {
444
450
  OAUTH_URL: url,
451
+ OAUTH_URL_RAW: url,
445
452
  OAUTH_STATE: state,
446
- ...(placeholderKey !== "OAUTH_URL"
447
- ? { [placeholderKey]: url }
448
- : {}),
453
+ };
454
+ const rawKeys = new Set(["OAUTH_URL_RAW"]);
455
+ if (placeholderKey !== "OAUTH_URL") {
456
+ values[placeholderKey] = url;
457
+ const rawVariant = `${placeholderKey}_RAW`;
458
+ values[rawVariant] = url;
459
+ rawKeys.add(rawVariant);
460
+ }
461
+ const html = this.renderHtmlTemplate(template, values, {
462
+ rawKeys,
449
463
  });
450
464
  sendHtml(response, html);
451
465
  }
@@ -519,14 +533,18 @@ export class MiniInteraction {
519
533
  }
520
534
  /**
521
535
  * Replaces placeholder tokens in a template with escaped HTML values.
522
- */
523
- renderHtmlTemplate(template, values) {
536
+ */
537
+ renderHtmlTemplate(template, values, options) {
538
+ const rawKeys = options?.rawKeys instanceof Set
539
+ ? options.rawKeys
540
+ : new Set(options?.rawKeys ?? []);
524
541
  return template.replace(/\{\{\s*(\w+)\s*\}\}/g, (match, key) => {
525
542
  const value = values[key];
526
543
  if (value === undefined || value === null) {
527
544
  return "";
528
545
  }
529
- return escapeHtml(String(value));
546
+ const stringValue = String(value);
547
+ return rawKeys.has(key) ? stringValue : escapeHtml(stringValue);
530
548
  });
531
549
  }
532
550
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minesa-org/mini-interaction",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Mini interaction, connecting your app with Discord via HTTP-interaction (Vercel support).",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",