@clikgate/node 2.0.0 → 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.
Files changed (86) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +126 -6
  3. package/SECURITY.md +2 -1
  4. package/dist/cjs/client.d.ts +54 -10
  5. package/dist/cjs/client.js +75 -16
  6. package/dist/cjs/currency.d.ts +7 -0
  7. package/dist/cjs/currency.js +75 -0
  8. package/dist/cjs/customer-id.d.ts +26 -0
  9. package/dist/cjs/customer-id.js +52 -0
  10. package/dist/cjs/enums.js +1 -1
  11. package/dist/cjs/errors.d.ts +1 -1
  12. package/dist/cjs/event-types.d.ts +108 -0
  13. package/dist/cjs/event-types.js +109 -0
  14. package/dist/cjs/express.d.ts +11 -2
  15. package/dist/cjs/express.js +3 -2
  16. package/dist/cjs/fastify.d.ts +4 -1
  17. package/dist/cjs/fastify.js +3 -2
  18. package/dist/cjs/generated/index.d.ts +2015 -83
  19. package/dist/cjs/generated/index.js +83 -3
  20. package/dist/cjs/identity.d.ts +12 -2
  21. package/dist/cjs/identity.js +37 -3
  22. package/dist/cjs/index.d.ts +11 -1
  23. package/dist/cjs/index.js +21 -1
  24. package/dist/cjs/installation.d.ts +47 -0
  25. package/dist/cjs/installation.js +83 -0
  26. package/dist/cjs/known-customers.d.ts +45 -0
  27. package/dist/cjs/known-customers.js +95 -0
  28. package/dist/cjs/lookups.d.ts +128 -0
  29. package/dist/cjs/lookups.js +149 -0
  30. package/dist/cjs/models.d.ts +342 -0
  31. package/dist/cjs/models.js +2 -0
  32. package/dist/cjs/next.d.ts +22 -0
  33. package/dist/cjs/next.js +20 -0
  34. package/dist/cjs/pager.d.ts +5 -0
  35. package/dist/cjs/pager.js +40 -0
  36. package/dist/cjs/referrals.d.ts +169 -0
  37. package/dist/cjs/referrals.js +208 -0
  38. package/dist/cjs/resources.d.ts +34 -5
  39. package/dist/cjs/resources.js +43 -42
  40. package/dist/cjs/types.d.ts +57 -10
  41. package/dist/cjs/version.d.ts +1 -1
  42. package/dist/cjs/version.js +1 -1
  43. package/dist/cjs/webhooks.d.ts +3 -2
  44. package/dist/cjs/webhooks.js +43 -2
  45. package/dist/esm/client.d.ts +54 -10
  46. package/dist/esm/client.js +75 -16
  47. package/dist/esm/currency.d.ts +7 -0
  48. package/dist/esm/currency.js +67 -0
  49. package/dist/esm/customer-id.d.ts +26 -0
  50. package/dist/esm/customer-id.js +47 -0
  51. package/dist/esm/enums.js +1 -1
  52. package/dist/esm/errors.d.ts +1 -1
  53. package/dist/esm/event-types.d.ts +108 -0
  54. package/dist/esm/event-types.js +106 -0
  55. package/dist/esm/express.d.ts +11 -2
  56. package/dist/esm/express.js +3 -2
  57. package/dist/esm/fastify.d.ts +4 -1
  58. package/dist/esm/fastify.js +3 -2
  59. package/dist/esm/generated/index.d.ts +2015 -83
  60. package/dist/esm/generated/index.js +80 -1
  61. package/dist/esm/identity.d.ts +12 -2
  62. package/dist/esm/identity.js +36 -3
  63. package/dist/esm/index.d.ts +11 -1
  64. package/dist/esm/index.js +6 -0
  65. package/dist/esm/installation.d.ts +47 -0
  66. package/dist/esm/installation.js +77 -0
  67. package/dist/esm/known-customers.d.ts +45 -0
  68. package/dist/esm/known-customers.js +90 -0
  69. package/dist/esm/lookups.d.ts +128 -0
  70. package/dist/esm/lookups.js +142 -0
  71. package/dist/esm/models.d.ts +342 -0
  72. package/dist/esm/models.js +1 -0
  73. package/dist/esm/next.d.ts +22 -0
  74. package/dist/esm/next.js +19 -0
  75. package/dist/esm/pager.d.ts +5 -0
  76. package/dist/esm/pager.js +36 -0
  77. package/dist/esm/referrals.d.ts +169 -0
  78. package/dist/esm/referrals.js +204 -0
  79. package/dist/esm/resources.d.ts +34 -5
  80. package/dist/esm/resources.js +43 -42
  81. package/dist/esm/types.d.ts +57 -10
  82. package/dist/esm/version.d.ts +1 -1
  83. package/dist/esm/version.js +1 -1
  84. package/dist/esm/webhooks.d.ts +3 -2
  85. package/dist/esm/webhooks.js +42 -2
  86. package/package.json +2 -2
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Your customer IDs, in one canonical form: the same form the API stores and checks, so an ID
3
+ * sent from your server, an import and an identity token always match.
4
+ *
5
+ * - canonical form: Unicode NFC, trimmed of Unicode whitespace (and U+FEFF) at both ends, case kept;
6
+ * - warnings (first match wins): `empty`, `too_long` (more than 128 characters), `looks_like_email`,
7
+ * `looks_like_national_id` (exactly 11 digits, unless `allow11DigitIds`), `looks_like_phone`.
8
+ *
9
+ * Use your own stable user ID (for example `u_10482`), never an email, phone number, BVN or NIN.
10
+ */
11
+ /** The longest customer ID kept as a known customer, in Unicode code points. */
12
+ export declare const CUSTOMER_ID_MAX_LENGTH = 128;
13
+ /** Why a customer ID can't be used as a known customer (the API's refusal reasons for the same checks). */
14
+ export type CustomerIdWarning = 'empty' | 'too_long' | 'looks_like_email' | 'looks_like_national_id' | 'looks_like_phone';
15
+ /** The canonical form of a customer ID: NFC, trimmed, case kept. */
16
+ export declare function canonicalCustomerId(customerId: string): string;
17
+ /**
18
+ * Why Clikgate wouldn't keep this ID as a known customer, or `null` when it's fine.
19
+ *
20
+ * @example
21
+ * customerIdWarning('ada@example.com'); // 'looks_like_email'
22
+ * customerIdWarning('u_10482'); // null
23
+ */
24
+ export declare function customerIdWarning(customerId: string, options?: {
25
+ allow11DigitIds?: boolean;
26
+ }): CustomerIdWarning | null;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ /**
3
+ * Your customer IDs, in one canonical form: the same form the API stores and checks, so an ID
4
+ * sent from your server, an import and an identity token always match.
5
+ *
6
+ * - canonical form: Unicode NFC, trimmed of Unicode whitespace (and U+FEFF) at both ends, case kept;
7
+ * - warnings (first match wins): `empty`, `too_long` (more than 128 characters), `looks_like_email`,
8
+ * `looks_like_national_id` (exactly 11 digits, unless `allow11DigitIds`), `looks_like_phone`.
9
+ *
10
+ * Use your own stable user ID (for example `u_10482`), never an email, phone number, BVN or NIN.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.CUSTOMER_ID_MAX_LENGTH = void 0;
14
+ exports.canonicalCustomerId = canonicalCustomerId;
15
+ exports.customerIdWarning = customerIdWarning;
16
+ /** Unicode White_Space characters plus U+FEFF (the byte-order mark). */
17
+ const TRIM = '\t\n\u000b\u000c\r \u0085\u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\ufeff';
18
+ /** The longest customer ID kept as a known customer, in Unicode code points. */
19
+ exports.CUSTOMER_ID_MAX_LENGTH = 128;
20
+ /** The canonical form of a customer ID: NFC, trimmed, case kept. */
21
+ function canonicalCustomerId(customerId) {
22
+ const s = customerId.normalize('NFC');
23
+ let start = 0;
24
+ let end = s.length;
25
+ while (start < end && TRIM.includes(s[start]))
26
+ start++;
27
+ while (end > start && TRIM.includes(s[end - 1]))
28
+ end--;
29
+ return s.slice(start, end);
30
+ }
31
+ /**
32
+ * Why Clikgate wouldn't keep this ID as a known customer, or `null` when it's fine.
33
+ *
34
+ * @example
35
+ * customerIdWarning('ada@example.com'); // 'looks_like_email'
36
+ * customerIdWarning('u_10482'); // null
37
+ */
38
+ function customerIdWarning(customerId, options = {}) {
39
+ const cid = canonicalCustomerId(customerId);
40
+ if (cid === '')
41
+ return 'empty';
42
+ if ([...cid].length > exports.CUSTOMER_ID_MAX_LENGTH)
43
+ return 'too_long';
44
+ const at = cid.indexOf('@');
45
+ if (at >= 0 && cid.slice(at + 1).includes('.'))
46
+ return 'looks_like_email';
47
+ if (/^[0-9]{11}$/.test(cid))
48
+ return options.allow11DigitIds ? null : 'looks_like_national_id';
49
+ if (/^\+?[0-9]{10,15}$/.test(cid.replace(/[ -]/g, '')))
50
+ return 'looks_like_phone';
51
+ return null;
52
+ }
package/dist/cjs/enums.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  // Generated by server/codegen/generate.mjs from openapi.json (GoalKind, GoalStatus, Provider). Do not edit by hand.
3
- // Source sha256 d39834b71974ddd58b7ba177f00c450738a641f18add17189a2f707bf724c796.
3
+ // Source sha256 3efd1f4fb7547b9b836402740027ff175d44649333c4b3a0003260c6ec5bd358.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.Provider = exports.GoalStatus = exports.GoalKind = void 0;
6
6
  /** A goal's kind, set in the goal's settings (never in a goal call): `standard` or `payment`. */
@@ -12,7 +12,7 @@
12
12
  * }
13
13
  */
14
14
  /** Error codes with documented meaning (SPEC section 5). Other codes can appear; `code` is a plain string. */
15
- export type KnownErrorCode = 'invalid_goal_key' | 'invalid_reference' | 'invalid_value' | 'click_id_and_code' | 'batch_too_large' | 'batch_empty' | 'invalid_argument' | 'invalid_click_id' | 'queue_full' | 'client_closed' | 'missing_api_key' | 'invalid_api_key' | 'invalid_option' | 'network_error' | 'timeout' | 'unexpected_status' | 'rate_limit_exceeded' | 'private_mode_field_rejected' | 'link_locked' | 'idempotency_key_reused' | 'idempotency_request_in_progress' | 'goal_archived' | 'goal_not_found' | 'value_required' | 'value_not_allowed' | 'domain_mode_mismatch' | 'https_required' | 'destination_not_allowlisted' | 'test_destination_not_allowed' | 'test_link_limit_reached' | 'plan_limit_reached' | 'plan_upgrade_required' | 'plan_feature_unavailable' | 'feature_disabled' | 'invalid_provider' | 'unknown_provider' | 'code_not_supported' | 'payment_goal_needs_confirmation' | 'unknown_goal' | 'cli_scope' | 'missing_signature' | 'malformed_signature' | 'timestamp_outside_tolerance' | 'no_matching_signature' | 'invalid_payload' | 'server_only' | 'invalid_customer_id' | 'missing_identity_secret' | 'invalid_identity_secrets';
15
+ export type KnownErrorCode = 'invalid_goal_key' | 'invalid_reference' | 'invalid_value' | 'click_id_and_code' | 'batch_too_large' | 'batch_empty' | 'invalid_argument' | 'invalid_click_id' | 'queue_full' | 'client_closed' | 'missing_api_key' | 'invalid_api_key' | 'invalid_option' | 'network_error' | 'timeout' | 'unexpected_status' | 'rate_limit_exceeded' | 'private_mode_field_rejected' | 'private_mode_conflict' | 'link_locked' | 'idempotency_key_reused' | 'idempotency_request_in_progress' | 'goal_archived' | 'goal_not_found' | 'value_required' | 'value_not_allowed' | 'domain_mode_mismatch' | 'https_required' | 'destination_not_allowlisted' | 'test_destination_not_allowed' | 'test_link_limit_reached' | 'plan_limit_reached' | 'plan_upgrade_required' | 'plan_feature_unavailable' | 'feature_disabled' | 'invalid_provider' | 'unknown_provider' | 'code_not_supported' | 'payment_goal_needs_confirmation' | 'unknown_goal' | 'cli_scope' | 'missing_signature' | 'malformed_signature' | 'timestamp_outside_tolerance' | 'no_matching_signature' | 'invalid_payload' | 'server_only' | 'invalid_customer_id' | 'missing_identity_secret' | 'invalid_identity_secrets';
16
16
  /** Fields every Clikgate error carries. */
17
17
  export interface ClikgateErrorInit {
18
18
  message: string;
@@ -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
+ };
@@ -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
  *
@@ -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) {
@@ -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
@@ -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