@clikgate/node 2.0.1 → 2.1.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 +25 -0
- package/README.md +116 -7
- package/SECURITY.md +2 -1
- package/dist/cjs/client.d.ts +38 -10
- package/dist/cjs/client.js +50 -16
- package/dist/cjs/currency.d.ts +7 -0
- package/dist/cjs/currency.js +75 -0
- package/dist/cjs/enums.js +1 -1
- package/dist/cjs/event-types.d.ts +108 -0
- package/dist/cjs/event-types.js +109 -0
- package/dist/cjs/express.d.ts +11 -2
- package/dist/cjs/express.js +3 -2
- package/dist/cjs/fastify.d.ts +4 -1
- package/dist/cjs/fastify.js +3 -2
- package/dist/cjs/generated/index.d.ts +1759 -86
- package/dist/cjs/generated/index.js +1 -1
- package/dist/cjs/identity.js +1 -1
- package/dist/cjs/index.d.ts +9 -1
- package/dist/cjs/index.js +15 -1
- package/dist/cjs/installation.d.ts +47 -0
- package/dist/cjs/installation.js +83 -0
- package/dist/cjs/lookups.d.ts +128 -0
- package/dist/cjs/lookups.js +149 -0
- package/dist/cjs/models.d.ts +342 -0
- package/dist/cjs/models.js +2 -0
- package/dist/cjs/next.d.ts +22 -0
- package/dist/cjs/next.js +20 -0
- package/dist/cjs/pager.d.ts +5 -0
- package/dist/cjs/pager.js +40 -0
- package/dist/cjs/referrals.d.ts +169 -0
- package/dist/cjs/referrals.js +208 -0
- package/dist/cjs/resources.d.ts +34 -5
- package/dist/cjs/resources.js +43 -42
- package/dist/cjs/types.d.ts +57 -10
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/webhooks.d.ts +3 -2
- package/dist/cjs/webhooks.js +43 -2
- package/dist/esm/client.d.ts +38 -10
- package/dist/esm/client.js +50 -16
- package/dist/esm/currency.d.ts +7 -0
- package/dist/esm/currency.js +67 -0
- package/dist/esm/enums.js +1 -1
- package/dist/esm/event-types.d.ts +108 -0
- package/dist/esm/event-types.js +106 -0
- package/dist/esm/express.d.ts +11 -2
- package/dist/esm/express.js +3 -2
- package/dist/esm/fastify.d.ts +4 -1
- package/dist/esm/fastify.js +3 -2
- package/dist/esm/generated/index.d.ts +1759 -86
- package/dist/esm/generated/index.js +1 -1
- package/dist/esm/identity.js +1 -1
- package/dist/esm/index.d.ts +9 -1
- package/dist/esm/index.js +4 -0
- package/dist/esm/installation.d.ts +47 -0
- package/dist/esm/installation.js +77 -0
- package/dist/esm/lookups.d.ts +128 -0
- package/dist/esm/lookups.js +142 -0
- package/dist/esm/models.d.ts +342 -0
- package/dist/esm/models.js +1 -0
- package/dist/esm/next.d.ts +22 -0
- package/dist/esm/next.js +19 -0
- package/dist/esm/pager.d.ts +5 -0
- package/dist/esm/pager.js +36 -0
- package/dist/esm/referrals.d.ts +169 -0
- package/dist/esm/referrals.js +204 -0
- package/dist/esm/resources.d.ts +34 -5
- package/dist/esm/resources.js +43 -42
- package/dist/esm/types.d.ts +57 -10
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/webhooks.d.ts +3 -2
- package/dist/esm/webhooks.js +42 -2
- package/package.json +2 -2
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every webhook event type the API sends (SPEC 29.1), as constants holding the wire string.
|
|
3
|
+
* `event.type` stays a plain string, so a type added later is never an error.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* if (event.type === EventType.ReferralQualified) { … }
|
|
7
|
+
*/
|
|
8
|
+
export declare const EventType: {
|
|
9
|
+
readonly AbTestLikelyWinner: "ab_test.likely_winner";
|
|
10
|
+
readonly AlertResolved: "alert.resolved";
|
|
11
|
+
readonly AlertTriggered: "alert.triggered";
|
|
12
|
+
readonly AppPushCredentialsInvalid: "app.push_credentials_invalid";
|
|
13
|
+
readonly AppReengaged: "app.reengaged";
|
|
14
|
+
readonly AppBannerPaused: "app_banner.paused";
|
|
15
|
+
readonly AppBannerPublished: "app_banner.published";
|
|
16
|
+
readonly CampaignPaused: "campaign.paused";
|
|
17
|
+
readonly CampaignResumed: "campaign.resumed";
|
|
18
|
+
readonly ChallengeCancelled: "challenge.cancelled";
|
|
19
|
+
readonly ChallengeEnded: "challenge.ended";
|
|
20
|
+
readonly ChallengeFinalized: "challenge.finalized";
|
|
21
|
+
readonly ChallengeScheduled: "challenge.scheduled";
|
|
22
|
+
readonly ChallengeStarted: "challenge.started";
|
|
23
|
+
readonly ClickCreated: "click.created";
|
|
24
|
+
readonly CodeRedeemed: "code.redeemed";
|
|
25
|
+
readonly ConversionAttributed: "conversion.attributed";
|
|
26
|
+
readonly ConversionReversed: "conversion.reversed";
|
|
27
|
+
readonly ConversionUnattributed: "conversion.unattributed";
|
|
28
|
+
readonly CreditNoteIssued: "credit_note.issued";
|
|
29
|
+
readonly DomainGroupChanged: "domain.group_changed";
|
|
30
|
+
readonly DomainSettingsUpdated: "domain.settings_updated";
|
|
31
|
+
readonly DomainStatusChanged: "domain.status_changed";
|
|
32
|
+
readonly FraudInstallFlagged: "fraud.install_flagged";
|
|
33
|
+
readonly FunnelStuck: "funnel.stuck";
|
|
34
|
+
readonly GoalCompleted: "goal.completed";
|
|
35
|
+
readonly GoalReversed: "goal.reversed";
|
|
36
|
+
readonly IdentityDuplicateDetected: "identity.duplicate_detected";
|
|
37
|
+
readonly InstallAttributed: "install.attributed";
|
|
38
|
+
readonly InstallAttributionUpdated: "install.attribution_updated";
|
|
39
|
+
readonly InstallOrganic: "install.organic";
|
|
40
|
+
readonly InstallUninstallReverted: "install.uninstall_reverted";
|
|
41
|
+
readonly InstallUninstalled: "install.uninstalled";
|
|
42
|
+
readonly InvoiceIssued: "invoice.issued";
|
|
43
|
+
readonly InvoicePaid: "invoice.paid";
|
|
44
|
+
readonly InvoiceVoided: "invoice.voided";
|
|
45
|
+
readonly JobCompleted: "job.completed";
|
|
46
|
+
readonly LeaderboardPeriodClosed: "leaderboard.period_closed";
|
|
47
|
+
readonly LeaderboardPeriodFinalized: "leaderboard.period_finalized";
|
|
48
|
+
readonly LeaderboardRankChanged: "leaderboard.rank_changed";
|
|
49
|
+
readonly LeaderboardTargetReached: "leaderboard.target_reached";
|
|
50
|
+
readonly LeaderboardTargetRevoked: "leaderboard.target_revoked";
|
|
51
|
+
readonly LinkArchived: "link.archived";
|
|
52
|
+
readonly LinkCreated: "link.created";
|
|
53
|
+
readonly LinkDestinationChanged: "link.destination_changed";
|
|
54
|
+
readonly LinkExpired: "link.expired";
|
|
55
|
+
readonly LinkFlagged: "link.flagged";
|
|
56
|
+
readonly LinkPaused: "link.paused";
|
|
57
|
+
readonly LinkResumed: "link.resumed";
|
|
58
|
+
readonly LinkStatsHourly: "link.stats.hourly";
|
|
59
|
+
readonly LinkUpdated: "link.updated";
|
|
60
|
+
readonly OrganizationDeleted: "organization.deleted";
|
|
61
|
+
readonly OrganizationFeatureChanged: "organization.feature_changed";
|
|
62
|
+
readonly OrganizationFeatureDataPurged: "organization.feature_data_purged";
|
|
63
|
+
readonly PartnerApproved: "partner.approved";
|
|
64
|
+
readonly PartnerEarningApproved: "partner_earning.approved";
|
|
65
|
+
readonly PartnerPayoutPaid: "partner_payout.paid";
|
|
66
|
+
readonly PartnerRewardApplied: "partner_reward.applied";
|
|
67
|
+
readonly PartnerRewardApproved: "partner_reward.approved";
|
|
68
|
+
readonly PartnerRewardRemoved: "partner_reward.removed";
|
|
69
|
+
readonly PartnerRewardReversed: "partner_reward.reversed";
|
|
70
|
+
readonly PaymentNotConfirmed: "payment.not_confirmed";
|
|
71
|
+
readonly PaymentRefunded: "payment.refunded";
|
|
72
|
+
readonly PaymentRejected: "payment.rejected";
|
|
73
|
+
readonly PaymentVerified: "payment.verified";
|
|
74
|
+
readonly PersonDeviceChanged: "person.device_changed";
|
|
75
|
+
readonly PrivacyRequestCompleted: "privacy.request_completed";
|
|
76
|
+
readonly ReceiptIssued: "receipt.issued";
|
|
77
|
+
readonly ReferralCreated: "referral.created";
|
|
78
|
+
readonly ReferralDisqualified: "referral.disqualified";
|
|
79
|
+
readonly ReferralHolding: "referral.holding";
|
|
80
|
+
readonly ReferralQualified: "referral.qualified";
|
|
81
|
+
readonly ReferralRefereeUninstalled: "referral.referee_uninstalled";
|
|
82
|
+
readonly ReferralRejected: "referral.rejected";
|
|
83
|
+
readonly ReferralStepCompleted: "referral.step_completed";
|
|
84
|
+
readonly ReferrerBlocked: "referrer.blocked";
|
|
85
|
+
readonly ReferrerCreated: "referrer.created";
|
|
86
|
+
readonly ReferrerQualityChanged: "referrer.quality_changed";
|
|
87
|
+
readonly ReferrerUnblocked: "referrer.unblocked";
|
|
88
|
+
readonly SaleMatched: "sale.matched";
|
|
89
|
+
readonly SaleRefunded: "sale.refunded";
|
|
90
|
+
readonly SkanPostbackReceived: "skan.postback_received";
|
|
91
|
+
readonly SubscriptionActivated: "subscription.activated";
|
|
92
|
+
readonly SubscriptionCancelled: "subscription.cancelled";
|
|
93
|
+
readonly SubscriptionChanged: "subscription.changed";
|
|
94
|
+
readonly SubscriptionExpired: "subscription.expired";
|
|
95
|
+
readonly SubscriptionGraceStarted: "subscription.grace_started";
|
|
96
|
+
readonly SubscriptionRenewed: "subscription.renewed";
|
|
97
|
+
readonly SubscriptionTrialConverted: "subscription.trial_converted";
|
|
98
|
+
readonly SubscriptionTrialEnded: "subscription.trial_ended";
|
|
99
|
+
readonly SubscriptionTrialExtended: "subscription.trial_extended";
|
|
100
|
+
readonly SubscriptionTrialStarted: "subscription.trial_started";
|
|
101
|
+
readonly SubscriptionUpdated: "subscription.updated";
|
|
102
|
+
readonly UsageThresholdReached: "usage.threshold_reached";
|
|
103
|
+
readonly WebhookTest: "webhook.test";
|
|
104
|
+
readonly WebhookEndpointDisabled: "webhook_endpoint.disabled";
|
|
105
|
+
readonly WhatsappConversationAttributed: "whatsapp.conversation_attributed";
|
|
106
|
+
};
|
|
107
|
+
/** A webhook event type this SDK release knows (`event.type` may also be a newer one). */
|
|
108
|
+
export type EventTypeValue = (typeof EventType)[keyof typeof EventType];
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventType = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Every webhook event type the API sends (SPEC 29.1), as constants holding the wire string.
|
|
6
|
+
* `event.type` stays a plain string, so a type added later is never an error.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* if (event.type === EventType.ReferralQualified) { … }
|
|
10
|
+
*/
|
|
11
|
+
exports.EventType = {
|
|
12
|
+
AbTestLikelyWinner: 'ab_test.likely_winner',
|
|
13
|
+
AlertResolved: 'alert.resolved',
|
|
14
|
+
AlertTriggered: 'alert.triggered',
|
|
15
|
+
AppPushCredentialsInvalid: 'app.push_credentials_invalid',
|
|
16
|
+
AppReengaged: 'app.reengaged',
|
|
17
|
+
AppBannerPaused: 'app_banner.paused',
|
|
18
|
+
AppBannerPublished: 'app_banner.published',
|
|
19
|
+
CampaignPaused: 'campaign.paused',
|
|
20
|
+
CampaignResumed: 'campaign.resumed',
|
|
21
|
+
ChallengeCancelled: 'challenge.cancelled',
|
|
22
|
+
ChallengeEnded: 'challenge.ended',
|
|
23
|
+
ChallengeFinalized: 'challenge.finalized',
|
|
24
|
+
ChallengeScheduled: 'challenge.scheduled',
|
|
25
|
+
ChallengeStarted: 'challenge.started',
|
|
26
|
+
ClickCreated: 'click.created',
|
|
27
|
+
CodeRedeemed: 'code.redeemed',
|
|
28
|
+
ConversionAttributed: 'conversion.attributed',
|
|
29
|
+
ConversionReversed: 'conversion.reversed',
|
|
30
|
+
ConversionUnattributed: 'conversion.unattributed',
|
|
31
|
+
CreditNoteIssued: 'credit_note.issued',
|
|
32
|
+
DomainGroupChanged: 'domain.group_changed',
|
|
33
|
+
DomainSettingsUpdated: 'domain.settings_updated',
|
|
34
|
+
DomainStatusChanged: 'domain.status_changed',
|
|
35
|
+
FraudInstallFlagged: 'fraud.install_flagged',
|
|
36
|
+
FunnelStuck: 'funnel.stuck',
|
|
37
|
+
GoalCompleted: 'goal.completed',
|
|
38
|
+
GoalReversed: 'goal.reversed',
|
|
39
|
+
IdentityDuplicateDetected: 'identity.duplicate_detected',
|
|
40
|
+
InstallAttributed: 'install.attributed',
|
|
41
|
+
InstallAttributionUpdated: 'install.attribution_updated',
|
|
42
|
+
InstallOrganic: 'install.organic',
|
|
43
|
+
InstallUninstallReverted: 'install.uninstall_reverted',
|
|
44
|
+
InstallUninstalled: 'install.uninstalled',
|
|
45
|
+
InvoiceIssued: 'invoice.issued',
|
|
46
|
+
InvoicePaid: 'invoice.paid',
|
|
47
|
+
InvoiceVoided: 'invoice.voided',
|
|
48
|
+
JobCompleted: 'job.completed',
|
|
49
|
+
LeaderboardPeriodClosed: 'leaderboard.period_closed',
|
|
50
|
+
LeaderboardPeriodFinalized: 'leaderboard.period_finalized',
|
|
51
|
+
LeaderboardRankChanged: 'leaderboard.rank_changed',
|
|
52
|
+
LeaderboardTargetReached: 'leaderboard.target_reached',
|
|
53
|
+
LeaderboardTargetRevoked: 'leaderboard.target_revoked',
|
|
54
|
+
LinkArchived: 'link.archived',
|
|
55
|
+
LinkCreated: 'link.created',
|
|
56
|
+
LinkDestinationChanged: 'link.destination_changed',
|
|
57
|
+
LinkExpired: 'link.expired',
|
|
58
|
+
LinkFlagged: 'link.flagged',
|
|
59
|
+
LinkPaused: 'link.paused',
|
|
60
|
+
LinkResumed: 'link.resumed',
|
|
61
|
+
LinkStatsHourly: 'link.stats.hourly',
|
|
62
|
+
LinkUpdated: 'link.updated',
|
|
63
|
+
OrganizationDeleted: 'organization.deleted',
|
|
64
|
+
OrganizationFeatureChanged: 'organization.feature_changed',
|
|
65
|
+
OrganizationFeatureDataPurged: 'organization.feature_data_purged',
|
|
66
|
+
PartnerApproved: 'partner.approved',
|
|
67
|
+
PartnerEarningApproved: 'partner_earning.approved',
|
|
68
|
+
PartnerPayoutPaid: 'partner_payout.paid',
|
|
69
|
+
PartnerRewardApplied: 'partner_reward.applied',
|
|
70
|
+
PartnerRewardApproved: 'partner_reward.approved',
|
|
71
|
+
PartnerRewardRemoved: 'partner_reward.removed',
|
|
72
|
+
PartnerRewardReversed: 'partner_reward.reversed',
|
|
73
|
+
PaymentNotConfirmed: 'payment.not_confirmed',
|
|
74
|
+
PaymentRefunded: 'payment.refunded',
|
|
75
|
+
PaymentRejected: 'payment.rejected',
|
|
76
|
+
PaymentVerified: 'payment.verified',
|
|
77
|
+
PersonDeviceChanged: 'person.device_changed',
|
|
78
|
+
PrivacyRequestCompleted: 'privacy.request_completed',
|
|
79
|
+
ReceiptIssued: 'receipt.issued',
|
|
80
|
+
ReferralCreated: 'referral.created',
|
|
81
|
+
ReferralDisqualified: 'referral.disqualified',
|
|
82
|
+
ReferralHolding: 'referral.holding',
|
|
83
|
+
ReferralQualified: 'referral.qualified',
|
|
84
|
+
ReferralRefereeUninstalled: 'referral.referee_uninstalled',
|
|
85
|
+
ReferralRejected: 'referral.rejected',
|
|
86
|
+
ReferralStepCompleted: 'referral.step_completed',
|
|
87
|
+
ReferrerBlocked: 'referrer.blocked',
|
|
88
|
+
ReferrerCreated: 'referrer.created',
|
|
89
|
+
ReferrerQualityChanged: 'referrer.quality_changed',
|
|
90
|
+
ReferrerUnblocked: 'referrer.unblocked',
|
|
91
|
+
SaleMatched: 'sale.matched',
|
|
92
|
+
SaleRefunded: 'sale.refunded',
|
|
93
|
+
SkanPostbackReceived: 'skan.postback_received',
|
|
94
|
+
SubscriptionActivated: 'subscription.activated',
|
|
95
|
+
SubscriptionCancelled: 'subscription.cancelled',
|
|
96
|
+
SubscriptionChanged: 'subscription.changed',
|
|
97
|
+
SubscriptionExpired: 'subscription.expired',
|
|
98
|
+
SubscriptionGraceStarted: 'subscription.grace_started',
|
|
99
|
+
SubscriptionRenewed: 'subscription.renewed',
|
|
100
|
+
SubscriptionTrialConverted: 'subscription.trial_converted',
|
|
101
|
+
SubscriptionTrialEnded: 'subscription.trial_ended',
|
|
102
|
+
SubscriptionTrialExtended: 'subscription.trial_extended',
|
|
103
|
+
SubscriptionTrialStarted: 'subscription.trial_started',
|
|
104
|
+
SubscriptionUpdated: 'subscription.updated',
|
|
105
|
+
UsageThresholdReached: 'usage.threshold_reached',
|
|
106
|
+
WebhookTest: 'webhook.test',
|
|
107
|
+
WebhookEndpointDisabled: 'webhook_endpoint.disabled',
|
|
108
|
+
WhatsappConversationAttributed: 'whatsapp.conversation_attributed',
|
|
109
|
+
};
|
package/dist/cjs/express.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Express / Connect middleware: keeps the click ID (SPEC section 17).
|
|
2
|
+
* Express / Connect middleware: keeps the click ID and reads the app's `Clikgate-Installation` header (SPEC section 17).
|
|
3
3
|
*
|
|
4
4
|
* @example
|
|
5
5
|
* import express from 'express';
|
|
@@ -12,16 +12,25 @@
|
|
|
12
12
|
* app.post('/signup', (req, res) => {
|
|
13
13
|
* const clickId = req.clikgate.clickId; // save it with the application
|
|
14
14
|
* });
|
|
15
|
+
* app.post('/login', async (req, res) => {
|
|
16
|
+
* const user = await signIn(req.body); // your own sign-in check first
|
|
17
|
+
* if (req.clikgate.installation) {
|
|
18
|
+
* await clikgate.identifyUser({ installation: req.clikgate.installation, customerId: user.id });
|
|
19
|
+
* }
|
|
20
|
+
* });
|
|
15
21
|
*
|
|
16
22
|
* @packageDocumentation
|
|
17
23
|
*/
|
|
18
24
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
19
25
|
import { type PersistOptions } from './click-ids.js';
|
|
20
26
|
import type { Clikgate } from './client.js';
|
|
27
|
+
import { type Installation } from './installation.js';
|
|
21
28
|
/** What the middleware puts on the request. */
|
|
22
29
|
export interface ClikgateRequestContext {
|
|
23
30
|
/** The click ID from the query, the `_cg_<param>` cookie or the `Clikgate-Click-Id` header; `null` when there is none. */
|
|
24
31
|
clickId: string | null;
|
|
32
|
+
/** The app installation from the `Clikgate-Installation` header; `null` when it is missing or invalid. */
|
|
33
|
+
installation: Installation | null;
|
|
25
34
|
}
|
|
26
35
|
declare global {
|
|
27
36
|
namespace Express {
|
|
@@ -38,7 +47,7 @@ export interface ClikgateMiddlewareOptions extends PersistOptions {
|
|
|
38
47
|
}
|
|
39
48
|
type Next = (err?: unknown) => void;
|
|
40
49
|
/**
|
|
41
|
-
* Express/Connect middleware: sets `req.clikgate.clickId`, and stores a click ID that arrives in
|
|
50
|
+
* Express/Connect middleware: sets `req.clikgate.clickId` and `req.clikgate.installation`, and stores a click ID that arrives in
|
|
42
51
|
* the query string in the first-party `_cg_<param>` cookie. Pass the client so the organisation's
|
|
43
52
|
* click-ID parameter is used; without it, `cgid`.
|
|
44
53
|
*
|
package/dist/cjs/express.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.captureClickId = captureClickId;
|
|
4
4
|
exports.clikgateMiddleware = clikgateMiddleware;
|
|
5
5
|
const click_ids_js_1 = require("./click-ids.js");
|
|
6
|
+
const installation_js_1 = require("./installation.js");
|
|
6
7
|
/** @internal Shared by the add-ons: read, expose and (optionally) persist the click ID. */
|
|
7
8
|
function captureClickId(helpers, req, res, options) {
|
|
8
9
|
const clickId = helpers.fromRequest(req);
|
|
@@ -16,7 +17,7 @@ function captureClickId(helpers, req, res, options) {
|
|
|
16
17
|
return clickId;
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
19
|
-
* Express/Connect middleware: sets `req.clikgate.clickId`, and stores a click ID that arrives in
|
|
20
|
+
* Express/Connect middleware: sets `req.clikgate.clickId` and `req.clikgate.installation`, and stores a click ID that arrives in
|
|
20
21
|
* the query string in the first-party `_cg_<param>` cookie. Pass the client so the organisation's
|
|
21
22
|
* click-ID parameter is used; without it, `cgid`.
|
|
22
23
|
*
|
|
@@ -34,7 +35,7 @@ function clikgateMiddleware(client, options = {}) {
|
|
|
34
35
|
void client.config().catch(() => undefined);
|
|
35
36
|
}
|
|
36
37
|
const clickId = captureClickId(helpers, req, res, options);
|
|
37
|
-
req.clikgate = { clickId };
|
|
38
|
+
req.clikgate = { clickId, installation: (0, installation_js_1.installationFromRequest)(req) };
|
|
38
39
|
next();
|
|
39
40
|
}
|
|
40
41
|
catch (err) {
|
package/dist/cjs/fastify.d.ts
CHANGED
|
@@ -18,10 +18,13 @@
|
|
|
18
18
|
import type { FastifyPluginAsync } from 'fastify';
|
|
19
19
|
import { type PersistOptions } from './click-ids.js';
|
|
20
20
|
import type { Clikgate } from './client.js';
|
|
21
|
+
import { type Installation } from './installation.js';
|
|
21
22
|
/** What the plugin puts on the request. */
|
|
22
23
|
export interface ClikgateRequestContext {
|
|
23
24
|
/** The click ID, or `null`. */
|
|
24
25
|
clickId: string | null;
|
|
26
|
+
/** The app installation from the `Clikgate-Installation` header; `null` when it is missing or invalid. */
|
|
27
|
+
installation: Installation | null;
|
|
25
28
|
}
|
|
26
29
|
declare module 'fastify' {
|
|
27
30
|
interface FastifyRequest {
|
|
@@ -37,7 +40,7 @@ export interface ClikgatePluginOptions extends PersistOptions {
|
|
|
37
40
|
persist?: boolean;
|
|
38
41
|
}
|
|
39
42
|
/**
|
|
40
|
-
* Fastify plugin: sets `request.clikgate.clickId` and keeps a click ID from the query string in the
|
|
43
|
+
* Fastify plugin: sets `request.clikgate.clickId` and `request.clikgate.installation`, and keeps a click ID from the query string in the
|
|
41
44
|
* `_cg_<param>` cookie.
|
|
42
45
|
*
|
|
43
46
|
* @example
|
package/dist/cjs/fastify.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.clikgatePlugin = void 0;
|
|
4
4
|
const click_ids_js_1 = require("./click-ids.js");
|
|
5
|
+
const installation_js_1 = require("./installation.js");
|
|
5
6
|
const plugin = async (fastify, options) => {
|
|
6
7
|
const { client, persist, ...cookie } = options;
|
|
7
8
|
const helpers = client ? client.clickIds : click_ids_js_1.clickIds;
|
|
@@ -11,7 +12,7 @@ const plugin = async (fastify, options) => {
|
|
|
11
12
|
fastify.decorateRequest('clikgate', null);
|
|
12
13
|
fastify.addHook('onRequest', async (request, reply) => {
|
|
13
14
|
const clickId = helpers.fromRequest({ url: request.url, headers: request.headers });
|
|
14
|
-
request.clikgate = { clickId };
|
|
15
|
+
request.clikgate = { clickId, installation: (0, installation_js_1.installationFromRequest)(request) };
|
|
15
16
|
if (clickId && persist !== false) {
|
|
16
17
|
const url = new URL(request.url, 'http://localhost');
|
|
17
18
|
if (url.searchParams.getAll(helpers.paramName).includes(clickId))
|
|
@@ -25,7 +26,7 @@ meta[Symbol.for('skip-override')] = true;
|
|
|
25
26
|
meta[Symbol.for('fastify.display-name')] = '@clikgate/node/fastify';
|
|
26
27
|
meta[Symbol.for('plugin-meta')] = { name: '@clikgate/node/fastify', fastify: '>=5' };
|
|
27
28
|
/**
|
|
28
|
-
* Fastify plugin: sets `request.clikgate.clickId` and keeps a click ID from the query string in the
|
|
29
|
+
* Fastify plugin: sets `request.clikgate.clickId` and `request.clikgate.installation`, and keeps a click ID from the query string in the
|
|
29
30
|
* `_cg_<param>` cookie.
|
|
30
31
|
*
|
|
31
32
|
* @example
|