@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Generated by server/codegen/generate.mjs from openapi.json. Do not edit by hand.
|
|
2
|
-
// Source sha256
|
|
2
|
+
// Source sha256 3efd1f4fb7547b9b836402740027ff175d44649333c4b3a0003260c6ec5bd358; OpenAPI Generator 7.26.0 (typescript-fetch, custom templates).
|
|
3
3
|
/* eslint-disable */
|
|
4
4
|
import { encodePathSegment } from '../http.js';
|
|
5
5
|
/**
|
package/dist/esm/identity.js
CHANGED
|
@@ -55,7 +55,7 @@ function resolveSecret(options, source) {
|
|
|
55
55
|
}
|
|
56
56
|
throw new ConfigurationError({
|
|
57
57
|
message: appId === null
|
|
58
|
-
? `No identity secret: set ${IDENTITY_SECRET_ENV} on your server (
|
|
58
|
+
? `No identity secret: set ${IDENTITY_SECRET_ENV} on your server (Developers › SDKs › your app › Set up identity › Identity secret).`
|
|
59
59
|
: `No identity secret for this app: add it to ${IDENTITY_SECRETS_ENV} or set ${IDENTITY_SECRET_ENV}.`,
|
|
60
60
|
code: 'missing_identity_secret',
|
|
61
61
|
param: 'secret',
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
export { Clikgate, type ClikgateOptions, type IdentifyUserParams, type PersonIdentified } from './client.js';
|
|
13
13
|
export { ClickIds, clickIds, isValid as isValidClickId, CLICK_ID_PATTERN, CLICK_ID_HEADER, KEPT_COOKIE, KEPT_BY, BROWSER_ENGINES, PLATFORMS, type PersistOptions, type RequestLike, type ResponseLike, type KeptBy, type BrowserEngine, type Platform, type ClickContext, type KeepRoute, type KeepRouteOptions, type KeepInput, type KeepResult, } from './click-ids.js';
|
|
14
14
|
export { webhooks, type VerifyOptions, type RawBody } from './webhooks.js';
|
|
15
|
+
export { parseInstallationHeader, installationFromRequest, INSTALLATION_HEADER, INSTALLATION_HEADER_MAX_LENGTH, INSTALLATION_PATTERN, type Installation, type HeadersLike, } from './installation.js';
|
|
15
16
|
export { canonicalCustomerId, customerIdWarning, CUSTOMER_ID_MAX_LENGTH, type CustomerIdWarning } from './customer-id.js';
|
|
16
17
|
export { KNOWN_CUSTOMERS_BATCH, type KnownCustomers, type KnownCustomer, type KnownCustomerRefusal, type KnownCustomersImportResult } from './known-customers.js';
|
|
17
18
|
export { createIdentityToken, IDENTITY_SECRET_ENV, IDENTITY_SECRETS_ENV, type IdentityTokenOptions } from './identity.js';
|
|
@@ -24,9 +25,16 @@ export type { Logger, WarningCode } from './logger.js';
|
|
|
24
25
|
export type { Clock, RequestOptions } from './http.js';
|
|
25
26
|
export type { FetchLike } from './transport.js';
|
|
26
27
|
export type { QrOptions, LinkIterator, Conversions, Links, Clicks } from './resources.js';
|
|
28
|
+
export { REFERRER_IMPORT_BATCH } from './referrals.js';
|
|
29
|
+
export type { Referrals, ReferrerCreateParams, ReferrerLookup, ReferralListParams, CompleteStepParams, ReferrerImportRow, ReferrerUpdateParams, } from './referrals.js';
|
|
30
|
+
export type { Privacy, PrivacyRequestParams, People, PeopleSearchOptions, Installs, Codes, CodeRedeemParams } from './lookups.js';
|
|
31
|
+
export type { PageIterator } from './pager.js';
|
|
32
|
+
export { EventType, type EventTypeValue } from './event-types.js';
|
|
33
|
+
export { currencyExponent, minorToAmount } from './currency.js';
|
|
34
|
+
export type { Referrer, ReferrerResult, ReferrerStats, Referral, ReferralStep, RewardInfo, RewardSide, Job, JobResult, PrivacyRequest, Person, PersonSummary, PersonSearchPage, Install, PaymentReport, ConversionObject, CodeRedemption, WebhookGoalEvent, DeviceChange, DeviceChangeSide, ReferralStateChange, LinkCreateParams, LinkUpdateParams, } from './models.js';
|
|
27
35
|
export type { Goals } from './goals.js';
|
|
28
36
|
export { buildFromPaystack, buildFromFlutterwave, buildFromMonnify, buildFromStripe, type Payments, type PaymentStatus, type PaymentConfirmParams, type PaymentConfirmation, type PaymentConfirmationBody, type PaymentHelperOptions, } from './payments.js';
|
|
29
|
-
export type { GoalEvent, GoalAttribution, GoalPayment, GoalBatchItem, GoalBatchResult, Link, LinkWarning, LinkChangeRequest, LinkUpdateResult, Click, Conversion, ListPage, ServerSdkConfig, ConfigGoal, WebhookEvent, QrCode, } from './types.js';
|
|
37
|
+
export type { GoalEvent, GoalAttribution, GoalPayment, GoalBatchItem, GoalBatchResult, Link, LinkWarning, LinkChangeRequest, LinkUpdateResult, Click, Conversion, ListPage, ServerSdkConfig, ConfigGoal, WebhookEvent, WebhookEventAccessors, WebhookEventData, WebhookEventOf, TypedWebhookEvent, QrCode, } from './types.js';
|
|
30
38
|
export { ClikgateError, ConfigurationError, AuthenticationError, PermissionError, InvalidRequestError, PrivateModeFieldRejectedError, NotFoundError, ConflictError, LinkLockedError, IdempotencyError, RateLimitError, ServerError, NetworkError, TimeoutError, SignatureVerificationError, ClikgateServerOnlyError, type KnownErrorCode, } from './errors.js';
|
|
31
39
|
export { VERSION } from './version.js';
|
|
32
40
|
/** Types of the generated `clikgate.api.*` layer (request bodies and responses, as in openapi.json). */
|
package/dist/esm/index.js
CHANGED
|
@@ -12,12 +12,16 @@
|
|
|
12
12
|
export { Clikgate } from './client.js';
|
|
13
13
|
export { ClickIds, clickIds, isValid as isValidClickId, CLICK_ID_PATTERN, CLICK_ID_HEADER, KEPT_COOKIE, KEPT_BY, BROWSER_ENGINES, PLATFORMS, } from './click-ids.js';
|
|
14
14
|
export { webhooks } from './webhooks.js';
|
|
15
|
+
export { parseInstallationHeader, installationFromRequest, INSTALLATION_HEADER, INSTALLATION_HEADER_MAX_LENGTH, INSTALLATION_PATTERN, } from './installation.js';
|
|
15
16
|
export { canonicalCustomerId, customerIdWarning, CUSTOMER_ID_MAX_LENGTH } from './customer-id.js';
|
|
16
17
|
export { KNOWN_CUSTOMERS_BATCH } from './known-customers.js';
|
|
17
18
|
export { createIdentityToken, IDENTITY_SECRET_ENV, IDENTITY_SECRETS_ENV } from './identity.js';
|
|
18
19
|
export { formatValue } from './money.js';
|
|
19
20
|
export { hashForAds } from './ads-hashing.js';
|
|
20
21
|
export { GoalKind, GoalStatus, Provider } from './enums.js';
|
|
22
|
+
export { REFERRER_IMPORT_BATCH } from './referrals.js';
|
|
23
|
+
export { EventType } from './event-types.js';
|
|
24
|
+
export { currencyExponent, minorToAmount } from './currency.js';
|
|
21
25
|
export { buildFromPaystack, buildFromFlutterwave, buildFromMonnify, buildFromStripe, } from './payments.js';
|
|
22
26
|
export { ClikgateError, ConfigurationError, AuthenticationError, PermissionError, InvalidRequestError, PrivateModeFieldRejectedError, NotFoundError, ConflictError, LinkLockedError, IdempotencyError, RateLimitError, ServerError, NetworkError, TimeoutError, SignatureVerificationError, ClikgateServerOnlyError, } from './errors.js';
|
|
23
27
|
export { VERSION } from './version.js';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `Clikgate-Installation` header (SPEC section 24): the mobile SDKs give the app a value
|
|
3
|
+
* `<app_id>:<installation_id>` to send to its own backend at sign-in and on signed-in requests. It is
|
|
4
|
+
* not a secret. Your server passes it to `identifyUser({ installation })`, so it never needs to know
|
|
5
|
+
* which Clikgate app ID belongs to which platform.
|
|
6
|
+
*
|
|
7
|
+
* The header only names the app installation. The customer ID always comes from your own signed-in
|
|
8
|
+
* user, never from the request.
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
/** The header name the app sends to your backend. */
|
|
13
|
+
export declare const INSTALLATION_HEADER = "Clikgate-Installation";
|
|
14
|
+
/** Longer header values are refused before they are looked at. */
|
|
15
|
+
export declare const INSTALLATION_HEADER_MAX_LENGTH = 128;
|
|
16
|
+
/** `app_` + a 26-character ID, one colon, a lowercase UUID. */
|
|
17
|
+
export declare const INSTALLATION_PATTERN: RegExp;
|
|
18
|
+
/** An app installation read from the `Clikgate-Installation` header. */
|
|
19
|
+
export interface Installation {
|
|
20
|
+
/** The Clikgate app ID (`app_…`). */
|
|
21
|
+
appId: string;
|
|
22
|
+
/** The SDK's installation ID (a lowercase UUID). */
|
|
23
|
+
installationId: string;
|
|
24
|
+
}
|
|
25
|
+
/** A request with headers: Node's `IncomingMessage`, Express, Fastify, a Fetch `Request` or `{ headers }`. */
|
|
26
|
+
export interface HeadersLike {
|
|
27
|
+
headers?: Headers | Record<string, string | string[] | undefined> | {
|
|
28
|
+
get(name: string): string | null;
|
|
29
|
+
} | null;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Parse a `Clikgate-Installation` header value. Returns `null` for anything that isn't exactly
|
|
33
|
+
* `<app_id>:<installation_id>` (after trimming, at most 128 characters, lowercase UUID). Never throws.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* const installation = parseInstallationHeader(req.get('Clikgate-Installation'));
|
|
37
|
+
* // { appId: 'app_01J…', installationId: '3f2b…' } or null
|
|
38
|
+
*/
|
|
39
|
+
export declare function parseInstallationHeader(value: unknown): Installation | null;
|
|
40
|
+
/**
|
|
41
|
+
* The installation from a request's `Clikgate-Installation` header, or `null` when it is missing or
|
|
42
|
+
* invalid. Never throws.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* const installation = installationFromRequest(req);
|
|
46
|
+
*/
|
|
47
|
+
export declare function installationFromRequest(request: HeadersLike | null | undefined): Installation | null;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `Clikgate-Installation` header (SPEC section 24): the mobile SDKs give the app a value
|
|
3
|
+
* `<app_id>:<installation_id>` to send to its own backend at sign-in and on signed-in requests. It is
|
|
4
|
+
* not a secret. Your server passes it to `identifyUser({ installation })`, so it never needs to know
|
|
5
|
+
* which Clikgate app ID belongs to which platform.
|
|
6
|
+
*
|
|
7
|
+
* The header only names the app installation. The customer ID always comes from your own signed-in
|
|
8
|
+
* user, never from the request.
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
/** The header name the app sends to your backend. */
|
|
13
|
+
export const INSTALLATION_HEADER = 'Clikgate-Installation';
|
|
14
|
+
/** Longer header values are refused before they are looked at. */
|
|
15
|
+
export const INSTALLATION_HEADER_MAX_LENGTH = 128;
|
|
16
|
+
/** `app_` + a 26-character ID, one colon, a lowercase UUID. */
|
|
17
|
+
export const INSTALLATION_PATTERN = /^(app_[0-9A-Z]{26}):([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/;
|
|
18
|
+
/**
|
|
19
|
+
* Parse a `Clikgate-Installation` header value. Returns `null` for anything that isn't exactly
|
|
20
|
+
* `<app_id>:<installation_id>` (after trimming, at most 128 characters, lowercase UUID). Never throws.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const installation = parseInstallationHeader(req.get('Clikgate-Installation'));
|
|
24
|
+
* // { appId: 'app_01J…', installationId: '3f2b…' } or null
|
|
25
|
+
*/
|
|
26
|
+
export function parseInstallationHeader(value) {
|
|
27
|
+
if (typeof value !== 'string' || value.length > INSTALLATION_HEADER_MAX_LENGTH)
|
|
28
|
+
return null;
|
|
29
|
+
const match = INSTALLATION_PATTERN.exec(value.replace(/^[ \t\r\n\f\v]+|[ \t\r\n\f\v]+$/g, ''));
|
|
30
|
+
return match ? { appId: match[1], installationId: match[2] } : null;
|
|
31
|
+
}
|
|
32
|
+
function headerValue(headers) {
|
|
33
|
+
if (!headers)
|
|
34
|
+
return undefined;
|
|
35
|
+
if (typeof headers.get === 'function') {
|
|
36
|
+
return headers.get(INSTALLATION_HEADER);
|
|
37
|
+
}
|
|
38
|
+
const record = headers;
|
|
39
|
+
const wanted = INSTALLATION_HEADER.toLowerCase();
|
|
40
|
+
for (const key of Object.keys(record)) {
|
|
41
|
+
if (key.toLowerCase() === wanted) {
|
|
42
|
+
const raw = record[key];
|
|
43
|
+
// Several headers with this name: refused, never guessed
|
|
44
|
+
return Array.isArray(raw) ? (raw.length === 1 ? raw[0] : undefined) : raw;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The installation from a request's `Clikgate-Installation` header, or `null` when it is missing or
|
|
51
|
+
* invalid. Never throws.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* const installation = installationFromRequest(req);
|
|
55
|
+
*/
|
|
56
|
+
export function installationFromRequest(request) {
|
|
57
|
+
try {
|
|
58
|
+
return parseInstallationHeader(headerValue(request?.headers));
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* @internal An installation from either the raw `Clikgate-Installation` header or a parsed {@link Installation}
|
|
66
|
+
* (`req.clikgate.installation`, `getInstallation(...)`). Both go through the same strict check; anything else is `null`.
|
|
67
|
+
*/
|
|
68
|
+
export function toInstallation(value) {
|
|
69
|
+
if (typeof value === 'string')
|
|
70
|
+
return parseInstallationHeader(value);
|
|
71
|
+
if (value && typeof value === 'object') {
|
|
72
|
+
const { appId, installationId } = value;
|
|
73
|
+
if (typeof appId === 'string' && typeof installationId === 'string')
|
|
74
|
+
return parseInstallationHeader(`${appId}:${installationId}`);
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { type RequestOptions } from './http.js';
|
|
2
|
+
import { type PageIterator } from './pager.js';
|
|
3
|
+
import type { CodeRedemption, Install, Person, PersonSearchPage, PersonSummary, PrivacyRequest } from './models.js';
|
|
4
|
+
/** Fields of `privacy.createRequest`. */
|
|
5
|
+
export interface PrivacyRequestParams {
|
|
6
|
+
type: 'access' | 'export' | 'delete' | 'erasure' | (string & {});
|
|
7
|
+
subjectType: 'installation' | 'customer_user' | 'email' | 'phone' | 'person' | 'click' | (string & {});
|
|
8
|
+
subjectId: string;
|
|
9
|
+
appId?: string;
|
|
10
|
+
}
|
|
11
|
+
/** Privacy requests: access, export, delete or erase a subject's data. */
|
|
12
|
+
export declare class Privacy {
|
|
13
|
+
private readonly core;
|
|
14
|
+
/**
|
|
15
|
+
* Ask for a subject's data to be exported, or erased. The request completes in the background.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* const request = await clikgate.privacy.createRequest({ type: 'erasure', subjectType: 'customer_user', subjectId: user.id });
|
|
19
|
+
*/
|
|
20
|
+
createRequest(params: PrivacyRequestParams, requestOptions?: RequestOptions): Promise<PrivacyRequest>;
|
|
21
|
+
/**
|
|
22
|
+
* Fetch a privacy request (an export's `result` has its download link once completed).
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const request = await clikgate.privacy.getRequest('prq_01J…');
|
|
26
|
+
*/
|
|
27
|
+
getRequest(requestId: string, requestOptions?: RequestOptions): Promise<PrivacyRequest>;
|
|
28
|
+
}
|
|
29
|
+
/** Options of `people.searchPage`. */
|
|
30
|
+
export interface PeopleSearchOptions {
|
|
31
|
+
cursor?: string;
|
|
32
|
+
/** 1-50 per page. */
|
|
33
|
+
limit?: number;
|
|
34
|
+
}
|
|
35
|
+
/** People: one customer across clicks, installs and your customer ID. */
|
|
36
|
+
export declare class People {
|
|
37
|
+
private readonly core;
|
|
38
|
+
/**
|
|
39
|
+
* Fetch a person.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* const person = await clikgate.people.get('per_01J…');
|
|
43
|
+
*/
|
|
44
|
+
get(personId: string, requestOptions?: RequestOptions): Promise<Person>;
|
|
45
|
+
/**
|
|
46
|
+
* Fetch one page of people matching a label, customer ID or click ID. The text is sent in the body, never in the URL.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const page = await clikgate.people.searchPage('Ada', { limit: 20 });
|
|
50
|
+
*/
|
|
51
|
+
searchPage(q: string, options?: PeopleSearchOptions, requestOptions?: RequestOptions): Promise<PersonSearchPage>;
|
|
52
|
+
/**
|
|
53
|
+
* Iterate over every person matching the text, fetching pages lazily.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* for await (const person of clikgate.people.search('Ada')) console.log(person.id, person.label);
|
|
57
|
+
*/
|
|
58
|
+
search(q: string, options?: Omit<PeopleSearchOptions, 'cursor'>, requestOptions?: RequestOptions): PageIterator<PersonSummary>;
|
|
59
|
+
/**
|
|
60
|
+
* Set a person's label (`null` clears it).
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* await clikgate.people.setLabel('per_01J…', 'Ada (VIP)');
|
|
64
|
+
*/
|
|
65
|
+
setLabel(personId: string, label: string | null, requestOptions?: RequestOptions): Promise<Person>;
|
|
66
|
+
}
|
|
67
|
+
/** Installs of your apps. */
|
|
68
|
+
export declare class Installs {
|
|
69
|
+
private readonly core;
|
|
70
|
+
/**
|
|
71
|
+
* The latest install of one of your customers (the customer ID you sent with `identifyUser`).
|
|
72
|
+
* The API currently needs `appId`.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* const install = await clikgate.installs.getByCustomer(user.id, { appId: 'app_01J…' });
|
|
76
|
+
*/
|
|
77
|
+
getByCustomer(customerId: string, options?: {
|
|
78
|
+
appId?: string;
|
|
79
|
+
}, requestOptions?: RequestOptions): Promise<Install>;
|
|
80
|
+
/**
|
|
81
|
+
* An install by its installation ID (from the `Clikgate-Installation` header). The API currently needs `appId`.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* const install = await clikgate.installs.getByInstallation(installation.installationId, { appId: installation.appId });
|
|
85
|
+
*/
|
|
86
|
+
getByInstallation(installationId: string, options?: {
|
|
87
|
+
appId?: string;
|
|
88
|
+
}, requestOptions?: RequestOptions): Promise<Install>;
|
|
89
|
+
}
|
|
90
|
+
/** Fields of `codes.redeem`. */
|
|
91
|
+
export interface CodeRedeemParams {
|
|
92
|
+
/** Your ID for this redemption (a receipt or ticket number). */
|
|
93
|
+
externalId: string;
|
|
94
|
+
code: string;
|
|
95
|
+
channel: 'ussd' | 'sms_keyword' | 'agent' | 'pos' | 'in_store' | 'call_center' | 'event' | 'print' | 'radio' | 'other' | (string & {});
|
|
96
|
+
appId?: string;
|
|
97
|
+
occurredAt?: Date | string;
|
|
98
|
+
/** Your own free-form data. */
|
|
99
|
+
metadata?: Record<string, unknown>;
|
|
100
|
+
/** Who redeemed it: `{ type, id? }` (e.g. `{ type: 'customer_user', id: user.id }`), sent as given. */
|
|
101
|
+
subject?: {
|
|
102
|
+
type: string;
|
|
103
|
+
id?: string | null;
|
|
104
|
+
[key: string]: unknown;
|
|
105
|
+
};
|
|
106
|
+
/** The agent who took the redemption. */
|
|
107
|
+
agentId?: string;
|
|
108
|
+
/** Where: `{ country?, region?, city?, store_id? }`, sent as given. */
|
|
109
|
+
location?: {
|
|
110
|
+
country?: string | null;
|
|
111
|
+
region?: string | null;
|
|
112
|
+
city?: string | null;
|
|
113
|
+
store_id?: string | null;
|
|
114
|
+
[key: string]: unknown;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/** Offline and referral codes. */
|
|
118
|
+
export declare class Codes {
|
|
119
|
+
private readonly core;
|
|
120
|
+
/**
|
|
121
|
+
* Redeem a code received offline (USSD, a till, an agent). A referral code can create a referral.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* const redemption = await clikgate.codes.redeem({ externalId: 'POS-991', code: 'ADA42', channel: 'pos' });
|
|
125
|
+
* if (redemption.referral) console.log(redemption.referral.id);
|
|
126
|
+
*/
|
|
127
|
+
redeem(params: CodeRedeemParams, requestOptions?: RequestOptions): Promise<CodeRedemption>;
|
|
128
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { encodePathSegment, formatDate, requireId } from './http.js';
|
|
2
|
+
import { toReferral } from './currency.js';
|
|
3
|
+
import { defined, paginate } from './pager.js';
|
|
4
|
+
/** Privacy requests: access, export, delete or erase a subject's data. */
|
|
5
|
+
export class Privacy {
|
|
6
|
+
core;
|
|
7
|
+
/** @internal */
|
|
8
|
+
constructor(core) {
|
|
9
|
+
this.core = core;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Ask for a subject's data to be exported, or erased. The request completes in the background.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const request = await clikgate.privacy.createRequest({ type: 'erasure', subjectType: 'customer_user', subjectId: user.id });
|
|
16
|
+
*/
|
|
17
|
+
async createRequest(params, requestOptions = {}) {
|
|
18
|
+
const body = defined({ type: params.type, subject_type: params.subjectType, subject_id: params.subjectId, app_id: params.appId });
|
|
19
|
+
const { data } = await this.core.requester.request({ method: 'POST', path: '/v1/privacy/requests', body, ...requestOptions });
|
|
20
|
+
return data;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Fetch a privacy request (an export's `result` has its download link once completed).
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* const request = await clikgate.privacy.getRequest('prq_01J…');
|
|
27
|
+
*/
|
|
28
|
+
async getRequest(requestId, requestOptions = {}) {
|
|
29
|
+
const path = `/v1/privacy/requests/${encodePathSegment(requireId(requestId, 'request_id'))}`;
|
|
30
|
+
const { data } = await this.core.requester.request({ method: 'GET', path, ...requestOptions });
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** People: one customer across clicks, installs and your customer ID. */
|
|
35
|
+
export class People {
|
|
36
|
+
core;
|
|
37
|
+
/** @internal */
|
|
38
|
+
constructor(core) {
|
|
39
|
+
this.core = core;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Fetch a person.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* const person = await clikgate.people.get('per_01J…');
|
|
46
|
+
*/
|
|
47
|
+
async get(personId, requestOptions = {}) {
|
|
48
|
+
const { data } = await this.core.requester.request({ method: 'GET', path: `/v1/people/${encodePathSegment(requireId(personId, 'person_id'))}`, ...requestOptions });
|
|
49
|
+
return data;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Fetch one page of people matching a label, customer ID or click ID. The text is sent in the body, never in the URL.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* const page = await clikgate.people.searchPage('Ada', { limit: 20 });
|
|
56
|
+
*/
|
|
57
|
+
async searchPage(q, options = {}, requestOptions = {}) {
|
|
58
|
+
const body = defined({ q, cursor: options.cursor, limit: options.limit });
|
|
59
|
+
const { data } = await this.core.requester.request({ method: 'POST', path: '/v1/people/search', body, ...requestOptions });
|
|
60
|
+
return data;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Iterate over every person matching the text, fetching pages lazily.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* for await (const person of clikgate.people.search('Ada')) console.log(person.id, person.label);
|
|
67
|
+
*/
|
|
68
|
+
search(q, options = {}, requestOptions = {}) {
|
|
69
|
+
return paginate((cursor) => this.searchPage(q, { ...options, cursor: cursor ?? undefined }, requestOptions));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Set a person's label (`null` clears it).
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* await clikgate.people.setLabel('per_01J…', 'Ada (VIP)');
|
|
76
|
+
*/
|
|
77
|
+
async setLabel(personId, label, requestOptions = {}) {
|
|
78
|
+
const { data } = await this.core.requester.request({ method: 'PATCH', path: `/v1/people/${encodePathSegment(requireId(personId, 'person_id'))}`, body: { label }, ...requestOptions });
|
|
79
|
+
return data;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** Installs of your apps. */
|
|
83
|
+
export class Installs {
|
|
84
|
+
core;
|
|
85
|
+
/** @internal */
|
|
86
|
+
constructor(core) {
|
|
87
|
+
this.core = core;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The latest install of one of your customers (the customer ID you sent with `identifyUser`).
|
|
91
|
+
* The API currently needs `appId`.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* const install = await clikgate.installs.getByCustomer(user.id, { appId: 'app_01J…' });
|
|
95
|
+
*/
|
|
96
|
+
async getByCustomer(customerId, options = {}, requestOptions = {}) {
|
|
97
|
+
const path = `/v1/installs/by-customer-user/${encodePathSegment(requireId(customerId, 'customer_id'))}`;
|
|
98
|
+
const { data } = await this.core.requester.request({ method: 'GET', path, query: defined({ app_id: options.appId }), ...requestOptions });
|
|
99
|
+
return data;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* An install by its installation ID (from the `Clikgate-Installation` header). The API currently needs `appId`.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* const install = await clikgate.installs.getByInstallation(installation.installationId, { appId: installation.appId });
|
|
106
|
+
*/
|
|
107
|
+
async getByInstallation(installationId, options = {}, requestOptions = {}) {
|
|
108
|
+
const path = `/v1/installs/by-installation/${encodePathSegment(requireId(installationId, 'installation_id'))}`;
|
|
109
|
+
const { data } = await this.core.requester.request({ method: 'GET', path, query: defined({ app_id: options.appId }), ...requestOptions });
|
|
110
|
+
return data;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/** Offline and referral codes. */
|
|
114
|
+
export class Codes {
|
|
115
|
+
core;
|
|
116
|
+
/** @internal */
|
|
117
|
+
constructor(core) {
|
|
118
|
+
this.core = core;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Redeem a code received offline (USSD, a till, an agent). A referral code can create a referral.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* const redemption = await clikgate.codes.redeem({ externalId: 'POS-991', code: 'ADA42', channel: 'pos' });
|
|
125
|
+
* if (redemption.referral) console.log(redemption.referral.id);
|
|
126
|
+
*/
|
|
127
|
+
async redeem(params, requestOptions = {}) {
|
|
128
|
+
const body = defined({
|
|
129
|
+
external_id: params.externalId,
|
|
130
|
+
code: params.code,
|
|
131
|
+
channel: params.channel,
|
|
132
|
+
app_id: params.appId,
|
|
133
|
+
occurred_at: params.occurredAt === undefined || params.occurredAt === null ? undefined : formatDate(params.occurredAt),
|
|
134
|
+
metadata: params.metadata ?? undefined,
|
|
135
|
+
subject: params.subject ?? undefined,
|
|
136
|
+
agent_id: params.agentId ?? undefined,
|
|
137
|
+
location: params.location ?? undefined,
|
|
138
|
+
});
|
|
139
|
+
const { data } = await this.core.requester.request({ method: 'POST', path: '/v1/codes/redeem', body, ...requestOptions });
|
|
140
|
+
return data && data.referral ? { ...data, referral: toReferral(data.referral) } : data;
|
|
141
|
+
}
|
|
142
|
+
}
|