Skip to content

Rule.io SDK


Rule.io SDK / client/src / markTagDirection

Function: markTagDirection()

Call Signature

markTagDirection(event, direction): SubscriberAddedToTagEvent

Defined in: client/src/webhooks/mark-tag.ts:51

Commit the direction of a subscriber.tag-changed event.

Rule.io's "added to tag" and "removed from tag" webhook bodies are identical — parseWebhookEvent therefore returns the ambiguous subscriber.tag-changed shape. Once the receiver knows which direction the request represents (typically because the URL was configured for one or the other in Rule.io's account UI), call this helper to narrow the type.

The returned event preserves the original tag and subscriber fields — only the discriminator changes.

Parameters

event

SubscriberTagChangedEvent

direction

"added"

Returns

SubscriberAddedToTagEvent

Throws

If event.type is not 'subscriber.tag-changed'.

Example

typescript
import { parseWebhookEvent, markTagDirection } from '@rule/client';

app.post('/webhooks/rule/tag-added', (req, res) => {
  const parsed = parseWebhookEvent(req.body);

  if (parsed.type !== 'subscriber.tag-changed') {
    // unexpected — only tag webhooks should reach this URL
    return res.status(400).end();
  }

  const event = markTagDirection(parsed, 'added');
  // event.type === 'subscriber.added-to-tag'

  res.status(200).end();
});

Call Signature

markTagDirection(event, direction): SubscriberRemovedFromTagEvent

Defined in: client/src/webhooks/mark-tag.ts:55

Commit the direction of a subscriber.tag-changed event.

Rule.io's "added to tag" and "removed from tag" webhook bodies are identical — parseWebhookEvent therefore returns the ambiguous subscriber.tag-changed shape. Once the receiver knows which direction the request represents (typically because the URL was configured for one or the other in Rule.io's account UI), call this helper to narrow the type.

The returned event preserves the original tag and subscriber fields — only the discriminator changes.

Parameters

event

SubscriberTagChangedEvent

direction

"removed"

Returns

SubscriberRemovedFromTagEvent

Throws

If event.type is not 'subscriber.tag-changed'.

Example

typescript
import { parseWebhookEvent, markTagDirection } from '@rule/client';

app.post('/webhooks/rule/tag-added', (req, res) => {
  const parsed = parseWebhookEvent(req.body);

  if (parsed.type !== 'subscriber.tag-changed') {
    // unexpected — only tag webhooks should reach this URL
    return res.status(400).end();
  }

  const event = markTagDirection(parsed, 'added');
  // event.type === 'subscriber.added-to-tag'

  res.status(200).end();
});

Call Signature

markTagDirection(event, direction): SubscriberAddedToTagEvent | SubscriberRemovedFromTagEvent

Defined in: client/src/webhooks/mark-tag.ts:59

Commit the direction of a subscriber.tag-changed event.

Rule.io's "added to tag" and "removed from tag" webhook bodies are identical — parseWebhookEvent therefore returns the ambiguous subscriber.tag-changed shape. Once the receiver knows which direction the request represents (typically because the URL was configured for one or the other in Rule.io's account UI), call this helper to narrow the type.

The returned event preserves the original tag and subscriber fields — only the discriminator changes.

Parameters

event

SubscriberTagChangedEvent

direction

"added" | "removed"

Returns

SubscriberAddedToTagEvent | SubscriberRemovedFromTagEvent

Throws

If event.type is not 'subscriber.tag-changed'.

Example

typescript
import { parseWebhookEvent, markTagDirection } from '@rule/client';

app.post('/webhooks/rule/tag-added', (req, res) => {
  const parsed = parseWebhookEvent(req.body);

  if (parsed.type !== 'subscriber.tag-changed') {
    // unexpected — only tag webhooks should reach this URL
    return res.status(400).end();
  }

  const event = markTagDirection(parsed, 'added');
  // event.type === 'subscriber.added-to-tag'

  res.status(200).end();
});