@atlasauth/js 0.14.0 → 0.16.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 +31 -0
- package/dist/account-hints.d.ts +53 -0
- package/dist/account-hints.js +114 -0
- package/dist/account-hints.js.map +1 -0
- package/dist/attempt.d.ts +3 -1
- package/dist/attempt.js.map +1 -1
- package/dist/captcha-controller.d.ts +21 -0
- package/dist/captcha-controller.js +35 -0
- package/dist/captcha-controller.js.map +1 -1
- package/dist/dev-browser.d.ts +30 -0
- package/dist/dev-browser.js +175 -0
- package/dist/dev-browser.js.map +1 -0
- package/dist/environment.d.ts +48 -0
- package/dist/environment.js +54 -1
- package/dist/environment.js.map +1 -1
- package/dist/fapi.d.ts +42 -3
- package/dist/fapi.js +94 -9
- package/dist/fapi.js.map +1 -1
- package/dist/impersonation.d.ts +44 -0
- package/dist/impersonation.js +47 -0
- package/dist/impersonation.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +30 -1
- package/dist/index.js.map +1 -1
- package/dist/instance-settings.d.ts +7 -1
- package/dist/instance-settings.js +15 -1
- package/dist/instance-settings.js.map +1 -1
- package/dist/mfa-enrollment.d.ts +154 -0
- package/dist/mfa-enrollment.js +288 -0
- package/dist/mfa-enrollment.js.map +1 -0
- package/dist/organization-audit-log.d.ts +63 -0
- package/dist/organization-audit-log.js +96 -0
- package/dist/organization-audit-log.js.map +1 -0
- package/dist/organizations.d.ts +330 -0
- package/dist/organizations.js +375 -0
- package/dist/organizations.js.map +1 -0
- package/dist/passkey-sign-in.d.ts +40 -0
- package/dist/passkey-sign-in.js +41 -0
- package/dist/passkey-sign-in.js.map +1 -0
- package/dist/passkey-sign-up.d.ts +46 -0
- package/dist/passkey-sign-up.js +98 -0
- package/dist/passkey-sign-up.js.map +1 -0
- package/dist/password-reset.d.ts +12 -0
- package/dist/password-reset.js +15 -0
- package/dist/password-reset.js.map +1 -1
- package/dist/phone-numbers.d.ts +43 -0
- package/dist/phone-numbers.js +65 -0
- package/dist/phone-numbers.js.map +1 -0
- package/dist/profile.d.ts +24 -0
- package/dist/profile.js +24 -0
- package/dist/profile.js.map +1 -0
- package/dist/referral-detect.d.ts +90 -0
- package/dist/referral-detect.js +432 -0
- package/dist/referral-detect.js.map +1 -0
- package/dist/referral.d.ts +59 -29
- package/dist/referral.js +96 -47
- package/dist/referral.js.map +1 -1
- package/dist/sign-out-guard.d.ts +8 -0
- package/dist/sign-out-guard.js +15 -0
- package/dist/sign-out-guard.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/dist/password-reset.d.ts
CHANGED
|
@@ -16,6 +16,12 @@ import type { FapiClient } from './fapi';
|
|
|
16
16
|
export interface ResetAttempt {
|
|
17
17
|
id: string;
|
|
18
18
|
status: string;
|
|
19
|
+
/**
|
|
20
|
+
* Present when the application resets by emailed link: poll
|
|
21
|
+
* {@link pollPasswordReset} with it until the link is opened (perhaps on
|
|
22
|
+
* another device), then carry on from the new status.
|
|
23
|
+
*/
|
|
24
|
+
poll_secret?: string;
|
|
19
25
|
}
|
|
20
26
|
export interface ResetFlowState {
|
|
21
27
|
attempt: ResetAttempt | null;
|
|
@@ -39,3 +45,9 @@ export declare function advancePasswordReset(client: FapiClient, state: ResetFlo
|
|
|
39
45
|
/** The step a reset flow is on — what the UI should collect next. */
|
|
40
46
|
export type ResetStep = 'request' | 'collect_email_code' | 'collect_second_factor' | 'collect_new_password' | 'done' | 'unknown';
|
|
41
47
|
export declare function resetStep(state: ResetFlowState): ResetStep;
|
|
48
|
+
/**
|
|
49
|
+
* Link mode: check whether the emailed reset link was opened. Resolves the
|
|
50
|
+
* flow at its current status (`needs_new_password` / `needs_second_factor`
|
|
51
|
+
* once it was); unchanged while still waiting or when the server can't say.
|
|
52
|
+
*/
|
|
53
|
+
export declare function pollPasswordReset(client: FapiClient, state: ResetFlowState): Promise<ResetFlowState>;
|
package/dist/password-reset.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.initialResetFlow = void 0;
|
|
|
4
4
|
exports.startPasswordReset = startPasswordReset;
|
|
5
5
|
exports.advancePasswordReset = advancePasswordReset;
|
|
6
6
|
exports.resetStep = resetStep;
|
|
7
|
+
exports.pollPasswordReset = pollPasswordReset;
|
|
7
8
|
exports.initialResetFlow = {
|
|
8
9
|
attempt: null,
|
|
9
10
|
errors: [],
|
|
@@ -77,4 +78,18 @@ function resetStep(state) {
|
|
|
77
78
|
return 'unknown';
|
|
78
79
|
}
|
|
79
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Link mode: check whether the emailed reset link was opened. Resolves the
|
|
83
|
+
* flow at its current status (`needs_new_password` / `needs_second_factor`
|
|
84
|
+
* once it was); unchanged while still waiting or when the server can't say.
|
|
85
|
+
*/
|
|
86
|
+
async function pollPasswordReset(client, state) {
|
|
87
|
+
const attempt = state.attempt;
|
|
88
|
+
if (!attempt?.poll_secret)
|
|
89
|
+
return state;
|
|
90
|
+
const res = await client.get(`/v1/client/password_resets/${attempt.id}?poll_secret=${encodeURIComponent(attempt.poll_secret)}`);
|
|
91
|
+
if (!res.ok || !res.data)
|
|
92
|
+
return state;
|
|
93
|
+
return { ...state, attempt: { id: res.data.id, status: res.data.status, poll_secret: attempt.poll_secret } };
|
|
94
|
+
}
|
|
80
95
|
//# sourceMappingURL=password-reset.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"password-reset.js","sourceRoot":"","sources":["../src/password-reset.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"password-reset.js","sourceRoot":"","sources":["../src/password-reset.ts"],"names":[],"mappings":";;;AA2CA,gDAWC;AAOD,oDAuCC;AAWD,8BAeC;AAOD,8CAQC;AA1GY,QAAA,gBAAgB,GAAmB;IAC9C,OAAO,EAAE,IAAI;IACb,MAAM,EAAE,EAAE;IACV,IAAI,EAAE,KAAK;IACX,MAAM,EAAE,IAAI;CACb,CAAC;AAEF,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O,EAAE,WAAW;QAAE,OAAO,KAAK,CAAC;IACxC,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,GAAG,CAC1B,8BAA8B,OAAO,CAAC,EAAE,gBAAgB,kBAAkB,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAClG,CAAC;IACF,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI;QAAE,OAAO,KAAK,CAAC;IACvC,OAAO,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;AAC/G,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { FapiClient } from './fapi';
|
|
2
|
+
/**
|
|
3
|
+
* Self-service phone numbers — a signed-in user adds, verifies (texted code),
|
|
4
|
+
* picks a primary and removes their OWN numbers over `/v1/client/me/phone_numbers`.
|
|
5
|
+
* Cookie-authenticated through the {@link FapiClient}.
|
|
6
|
+
*
|
|
7
|
+
* Adding a number from a session that has not re-authenticated recently, and
|
|
8
|
+
* making one primary or removing one at any time after the step-up window,
|
|
9
|
+
* fails with a {@link PhoneNumberRequestError} whose `code` is
|
|
10
|
+
* `STEP_UP_REQUIRED`. Re-authenticate (`reauthenticate()`), then retry.
|
|
11
|
+
*/
|
|
12
|
+
export interface UserPhoneNumber {
|
|
13
|
+
object: 'phone_number';
|
|
14
|
+
id: string;
|
|
15
|
+
/** E.164. */
|
|
16
|
+
phone_number: string;
|
|
17
|
+
verified: boolean;
|
|
18
|
+
/** Where account SMS goes. Only a verified number can be primary. */
|
|
19
|
+
primary: boolean;
|
|
20
|
+
created_at?: number;
|
|
21
|
+
}
|
|
22
|
+
/** A refused request. `code` is the server's stable error code. */
|
|
23
|
+
export declare class PhoneNumberRequestError extends Error {
|
|
24
|
+
readonly code: string;
|
|
25
|
+
readonly status: number;
|
|
26
|
+
readonly param?: string;
|
|
27
|
+
readonly reason?: string;
|
|
28
|
+
constructor(status: number, code: string, message: string, param?: string, reason?: string);
|
|
29
|
+
/** True when the action needs a fresh re-authentication first. */
|
|
30
|
+
get needsReverification(): boolean;
|
|
31
|
+
}
|
|
32
|
+
/** The user's numbers, verified or not. */
|
|
33
|
+
export declare function listPhoneNumbers(client: FapiClient): Promise<UserPhoneNumber[]>;
|
|
34
|
+
/** Add a number (E.164, e.g. `+15551234567`); a verification code is texted to it. */
|
|
35
|
+
export declare function addPhoneNumber(client: FapiClient, phoneNumber: string): Promise<UserPhoneNumber>;
|
|
36
|
+
/** Text a fresh code to a number the user holds but has not verified. */
|
|
37
|
+
export declare function preparePhoneNumberVerification(client: FapiClient, id: string): Promise<UserPhoneNumber>;
|
|
38
|
+
/** Verify a number with the texted code. The first verified number becomes primary. */
|
|
39
|
+
export declare function attemptPhoneNumberVerification(client: FapiClient, id: string, code: string): Promise<UserPhoneNumber>;
|
|
40
|
+
/** Make a verified number primary. Needs a recent re-authentication. */
|
|
41
|
+
export declare function setPrimaryPhoneNumber(client: FapiClient, id: string): Promise<UserPhoneNumber>;
|
|
42
|
+
/** Remove a number. Needs a recent re-authentication; the last way to sign in is refused. */
|
|
43
|
+
export declare function removePhoneNumber(client: FapiClient, id: string): Promise<void>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PhoneNumberRequestError = void 0;
|
|
4
|
+
exports.listPhoneNumbers = listPhoneNumbers;
|
|
5
|
+
exports.addPhoneNumber = addPhoneNumber;
|
|
6
|
+
exports.preparePhoneNumberVerification = preparePhoneNumberVerification;
|
|
7
|
+
exports.attemptPhoneNumberVerification = attemptPhoneNumberVerification;
|
|
8
|
+
exports.setPrimaryPhoneNumber = setPrimaryPhoneNumber;
|
|
9
|
+
exports.removePhoneNumber = removePhoneNumber;
|
|
10
|
+
/** A refused request. `code` is the server's stable error code. */
|
|
11
|
+
class PhoneNumberRequestError extends Error {
|
|
12
|
+
code;
|
|
13
|
+
status;
|
|
14
|
+
param;
|
|
15
|
+
reason;
|
|
16
|
+
constructor(status, code, message, param, reason) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = 'PhoneNumberRequestError';
|
|
19
|
+
this.status = status;
|
|
20
|
+
this.code = code;
|
|
21
|
+
this.param = param;
|
|
22
|
+
if (reason)
|
|
23
|
+
this.reason = reason;
|
|
24
|
+
}
|
|
25
|
+
/** True when the action needs a fresh re-authentication first. */
|
|
26
|
+
get needsReverification() {
|
|
27
|
+
return this.code === 'STEP_UP_REQUIRED';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.PhoneNumberRequestError = PhoneNumberRequestError;
|
|
31
|
+
const BASE = '/v1/client/me/phone_numbers';
|
|
32
|
+
async function call(client, path, init = {}) {
|
|
33
|
+
const res = await client.request(path, init);
|
|
34
|
+
if (!res.ok || !res.data) {
|
|
35
|
+
const first = res.errors[0];
|
|
36
|
+
throw new PhoneNumberRequestError(res.status, first?.code ?? 'UNKNOWN', first?.message ?? 'The request failed.', first?.param, first?.reason);
|
|
37
|
+
}
|
|
38
|
+
return res.data;
|
|
39
|
+
}
|
|
40
|
+
const json = (body) => ({ method: 'POST', body: JSON.stringify(body) });
|
|
41
|
+
/** The user's numbers, verified or not. */
|
|
42
|
+
async function listPhoneNumbers(client) {
|
|
43
|
+
return (await call(client, BASE, { method: 'GET' })).data ?? [];
|
|
44
|
+
}
|
|
45
|
+
/** Add a number (E.164, e.g. `+15551234567`); a verification code is texted to it. */
|
|
46
|
+
function addPhoneNumber(client, phoneNumber) {
|
|
47
|
+
return call(client, BASE, json({ phone_number: phoneNumber }));
|
|
48
|
+
}
|
|
49
|
+
/** Text a fresh code to a number the user holds but has not verified. */
|
|
50
|
+
function preparePhoneNumberVerification(client, id) {
|
|
51
|
+
return call(client, `${BASE}/${encodeURIComponent(id)}/prepare_verification`, { method: 'POST' });
|
|
52
|
+
}
|
|
53
|
+
/** Verify a number with the texted code. The first verified number becomes primary. */
|
|
54
|
+
function attemptPhoneNumberVerification(client, id, code) {
|
|
55
|
+
return call(client, `${BASE}/${encodeURIComponent(id)}/attempt_verification`, json({ code }));
|
|
56
|
+
}
|
|
57
|
+
/** Make a verified number primary. Needs a recent re-authentication. */
|
|
58
|
+
function setPrimaryPhoneNumber(client, id) {
|
|
59
|
+
return call(client, `${BASE}/${encodeURIComponent(id)}/primary`, { method: 'POST' });
|
|
60
|
+
}
|
|
61
|
+
/** Remove a number. Needs a recent re-authentication; the last way to sign in is refused. */
|
|
62
|
+
async function removePhoneNumber(client, id) {
|
|
63
|
+
await call(client, `${BASE}/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=phone-numbers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phone-numbers.js","sourceRoot":"","sources":["../src/phone-numbers.ts"],"names":[],"mappings":";;;AAkEA,4CAEC;AAGD,wCAEC;AAGD,wEAEC;AAGD,wEAMC;AAGD,sDAEC;AAGD,8CAEC;AAzED,mEAAmE;AACnE,MAAa,uBAAwB,SAAQ,KAAK;IACvC,IAAI,CAAS;IACb,MAAM,CAAS;IACf,KAAK,CAAU;IACf,MAAM,CAAU;IAEzB,YAAY,MAAc,EAAE,IAAY,EAAE,OAAe,EAAE,KAAc,EAAE,MAAe;QACxF,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,MAAM;YAAE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACnC,CAAC;IAED,kEAAkE;IACl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AACzE,SAAgB,8BAA8B,CAAC,MAAkB,EAAE,EAAU;IAC3E,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,IAAI,kBAAkB,CAAC,EAAE,CAAC,uBAAuB,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;AACpG,CAAC;AAED,uFAAuF;AACvF,SAAgB,8BAA8B,CAC5C,MAAkB,EAClB,EAAU,EACV,IAAY;IAEZ,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,IAAI,kBAAkB,CAAC,EAAE,CAAC,uBAAuB,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AAChG,CAAC;AAED,wEAAwE;AACxE,SAAgB,qBAAqB,CAAC,MAAkB,EAAE,EAAU;IAClE,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,IAAI,kBAAkB,CAAC,EAAE,CAAC,UAAU,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;AACvF,CAAC;AAED,6FAA6F;AACtF,KAAK,UAAU,iBAAiB,CAAC,MAAkB,EAAE,EAAU;IACpE,MAAM,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,IAAI,kBAAkB,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;AAChF,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { FapiClient } from './fapi';
|
|
2
|
+
import type { FieldError } from './attempt';
|
|
3
|
+
/**
|
|
4
|
+
* Update the signed-in user's own profile (`PATCH /v1/client/me`). `traits`
|
|
5
|
+
* sets identity traits the application marked user-editable — each is typed
|
|
6
|
+
* and checked by the server against the trait schema (a refused value comes
|
|
7
|
+
* back as an error whose `param` is `traits.<key>`); `null` removes an optional
|
|
8
|
+
* one. Cookie-authenticated through the {@link FapiClient}.
|
|
9
|
+
*/
|
|
10
|
+
export interface ProfileUpdate {
|
|
11
|
+
firstName?: string;
|
|
12
|
+
lastName?: string;
|
|
13
|
+
username?: string;
|
|
14
|
+
locale?: string;
|
|
15
|
+
unsafeMetadata?: Record<string, unknown>;
|
|
16
|
+
traits?: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
export declare function updateProfile(client: FapiClient, update: ProfileUpdate): Promise<{
|
|
19
|
+
ok: true;
|
|
20
|
+
user: Record<string, unknown>;
|
|
21
|
+
} | {
|
|
22
|
+
ok: false;
|
|
23
|
+
errors: FieldError[];
|
|
24
|
+
}>;
|
package/dist/profile.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateProfile = updateProfile;
|
|
4
|
+
async function updateProfile(client, update) {
|
|
5
|
+
const body = {};
|
|
6
|
+
if (update.firstName !== undefined)
|
|
7
|
+
body.first_name = update.firstName;
|
|
8
|
+
if (update.lastName !== undefined)
|
|
9
|
+
body.last_name = update.lastName;
|
|
10
|
+
if (update.username !== undefined)
|
|
11
|
+
body.username = update.username;
|
|
12
|
+
if (update.locale !== undefined)
|
|
13
|
+
body.locale = update.locale;
|
|
14
|
+
if (update.unsafeMetadata !== undefined)
|
|
15
|
+
body.unsafe_metadata = update.unsafeMetadata;
|
|
16
|
+
if (update.traits !== undefined)
|
|
17
|
+
body.traits = update.traits;
|
|
18
|
+
const response = await client.request('/v1/client/me', {
|
|
19
|
+
method: 'PATCH',
|
|
20
|
+
body: JSON.stringify(body),
|
|
21
|
+
});
|
|
22
|
+
return response.ok && response.data ? { ok: true, user: response.data } : { ok: false, errors: response.errors };
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=profile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile.js","sourceRoot":"","sources":["../src/profile.ts"],"names":[],"mappings":";;AAmBA,sCAgBC;AAhBM,KAAK,UAAU,aAAa,CACjC,MAAkB,EAClB,MAAqB;IAErB,MAAM,IAAI,GAA4B,EAAE,CAAC;IACzC,IAAI,MAAM,CAAC,SAAS,KAAK,SAAS;QAAE,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC;IACvE,IAAI,MAAM,CAAC,QAAQ,KAAK,SAAS;QAAE,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC;IACpE,IAAI,MAAM,CAAC,QAAQ,KAAK,SAAS;QAAE,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;IACnE,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS;QAAE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7D,IAAI,MAAM,CAAC,cAAc,KAAK,SAAS;QAAE,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,cAAc,CAAC;IACtF,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS;QAAE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7D,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CAA0B,eAAe,EAAE;QAC9E,MAAM,EAAE,OAAO;QACf,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;KAC3B,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC,EAAE,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;AACnH,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Referral sources and consent managers the SDK recognises on the page, so
|
|
3
|
+
* referral capture works with any referral program and any consent manager.
|
|
4
|
+
*
|
|
5
|
+
* Sources: the referral script or cookie a program puts on the merchant's
|
|
6
|
+
* site. Each reader returns `{code, clickId, anonId}` (and `capturedAt` when
|
|
7
|
+
* the source says when): the code is the referrer's, the ids are the
|
|
8
|
+
* visitor's (sent only with consent). The instance lists which sources to read
|
|
9
|
+
* (`browser_sources`), so one program's script never feeds another program's
|
|
10
|
+
* connection. A custom program passes its own reader as `referralSource`.
|
|
11
|
+
*
|
|
12
|
+
* Consent: the first consent manager found on the page decides whether the
|
|
13
|
+
* referral cookie's ids may be read, for the instance's consent category, else
|
|
14
|
+
* its fallback category. The visitor's answer in a consent manager is the
|
|
15
|
+
* source of truth: the app's own decision (`referralConsent`) applies only
|
|
16
|
+
* when no manager is on the page, or when the instance says the app decides
|
|
17
|
+
* (`consent_provider: 'app'`). Common names map onto each manager's own:
|
|
18
|
+
* `marketing` (also advertising / targeting), `statistics` (analytics /
|
|
19
|
+
* performance) and `preferences` (functional / personalization); any other
|
|
20
|
+
* name is looked up as the manager's own category id. IAB TCF v2 managers
|
|
21
|
+
* answer with Purpose 1 (store and access information on a device).
|
|
22
|
+
*
|
|
23
|
+
* Every reader is defensive: a missing, half-loaded or throwing script reads
|
|
24
|
+
* as "nothing here". The ES5 copy in the Atlas API (hosted pages and the Sign
|
|
25
|
+
* in with Atlas button) follows the same rules and is tested against the same
|
|
26
|
+
* fixtures.
|
|
27
|
+
*/
|
|
28
|
+
/** What a browser source holds. */
|
|
29
|
+
export interface DetectedReferral {
|
|
30
|
+
/** The source id (e.g. `rewardful`), or `custom` for the app's own reader. */
|
|
31
|
+
source: string;
|
|
32
|
+
code: string | null;
|
|
33
|
+
clickId: string | null;
|
|
34
|
+
anonId: string | null;
|
|
35
|
+
/** ISO 8601, when the source says when it captured the referral. */
|
|
36
|
+
capturedAt?: string;
|
|
37
|
+
}
|
|
38
|
+
/** The app's own reader, for a referral program the SDK doesn't know. */
|
|
39
|
+
export type ReferralSourceReader = () => {
|
|
40
|
+
code?: string | null;
|
|
41
|
+
clickId?: string | null;
|
|
42
|
+
anonId?: string | null;
|
|
43
|
+
capturedAt?: string | number | null;
|
|
44
|
+
} | null | undefined;
|
|
45
|
+
/** The browser sources the SDK reads, in the order it tries them. */
|
|
46
|
+
export declare const REFERRAL_BROWSER_SOURCES: readonly ["referally", "rewardful", "tolt", "promotekit", "firstpromoter", "partnerstack", "dub"];
|
|
47
|
+
export type ReferralBrowserSource = (typeof REFERRAL_BROWSER_SOURCES)[number];
|
|
48
|
+
/** The consent managers the SDK reads, in the order `auto` tries them. */
|
|
49
|
+
export declare const CONSENT_PROVIDERS: readonly ["cookiemunch", "onetrust", "cookiebot", "didomi", "usercentrics", "osano", "cookieyes", "complianz", "klaro", "tcf", "consent_mode"];
|
|
50
|
+
export type ConsentProvider = (typeof CONSENT_PROVIDERS)[number];
|
|
51
|
+
/** The page as the readers see it: `window`, and `document.cookie`. */
|
|
52
|
+
export interface DetectPage {
|
|
53
|
+
win: unknown;
|
|
54
|
+
cookies: string | null | undefined;
|
|
55
|
+
}
|
|
56
|
+
/** The app's own reader, as a detected referral (source `custom`). Never throws. */
|
|
57
|
+
export declare function customReferral(reader: ReferralSourceReader | undefined): DetectedReferral | null;
|
|
58
|
+
/** The first of `sources` with a referral on the page, or null. Unknown ids are skipped. */
|
|
59
|
+
export declare function detectReferralSource(page: DetectPage, sources: readonly string[]): DetectedReferral | null;
|
|
60
|
+
type Canonical = 'necessary' | 'preferences' | 'statistics' | 'marketing';
|
|
61
|
+
/** A consent category's common meaning, if it has one. */
|
|
62
|
+
export declare function canonicalCategory(name: string): Canonical | null;
|
|
63
|
+
/**
|
|
64
|
+
* Start listening to an IAB TCF v2 manager (`__tcfapi`), so its answer is
|
|
65
|
+
* ready synchronously when a sign-in starts. Safe to call more than once.
|
|
66
|
+
*/
|
|
67
|
+
export declare function listenForTcfConsent(win: unknown): void;
|
|
68
|
+
/** Forget the cached TCF data (tests). */
|
|
69
|
+
export declare function resetConsentDetection(): void;
|
|
70
|
+
/** A consent decision and who made it (`app`, a manager id, or `none`). */
|
|
71
|
+
export interface ConsentDecision {
|
|
72
|
+
granted: boolean;
|
|
73
|
+
by: string;
|
|
74
|
+
}
|
|
75
|
+
/** The app's own decision (`referralConsent`), when definite. */
|
|
76
|
+
export type AppConsent = 'granted' | 'denied' | boolean | (() => 'granted' | 'denied' | boolean | null | undefined);
|
|
77
|
+
/**
|
|
78
|
+
* Whether the referral cookie's ids may be read, and who decided. A consent
|
|
79
|
+
* manager on the page decides (`provider`: `auto` tries each in order, a
|
|
80
|
+
* manager id asks only that one); a manager that doesn't know either category
|
|
81
|
+
* answers no. With no manager, or `provider: 'app'`, the app's definite answer
|
|
82
|
+
* decides; else no.
|
|
83
|
+
*/
|
|
84
|
+
export declare function detectConsent(win: unknown, categories: readonly (string | null | undefined)[], options?: {
|
|
85
|
+
provider?: string | null;
|
|
86
|
+
appConsent?: AppConsent;
|
|
87
|
+
}): ConsentDecision;
|
|
88
|
+
/** Which consent manager is on the page (`auto` order), or null. For diagnostics. */
|
|
89
|
+
export declare function detectConsentProvider(win: unknown): ConsentProvider | null;
|
|
90
|
+
export {};
|