ad2app-lib 1.41.0 → 1.42.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.
|
@@ -26,14 +26,63 @@ export declare const ACCESS_DENIAL_CODES: {
|
|
|
26
26
|
readonly ENTITLEMENT_PRECONDITION: "entitlement-precondition";
|
|
27
27
|
};
|
|
28
28
|
export type AccessDenialCode = (typeof ACCESS_DENIAL_CODES)[keyof typeof ACCESS_DENIAL_CODES];
|
|
29
|
+
/**
|
|
30
|
+
* WHICH precondition the entitlement wall refused on (backend#305, spec 170).
|
|
31
|
+
*
|
|
32
|
+
* `ENTITLEMENT_PRECONDITION` above is the CLIENT contract: every cause below
|
|
33
|
+
* wants the same behaviour from a client — render the surface's own empty
|
|
34
|
+
* state, do not redirect, never send a paying user to buy a plan they already
|
|
35
|
+
* own — so a fourth code would force every consumer to re-learn a wall it
|
|
36
|
+
* already handles correctly, to carry information no consumer acts on.
|
|
37
|
+
*
|
|
38
|
+
* This is for whoever is READING. There is one throw site in the backend and
|
|
39
|
+
* four ways to reach it, and until now all four answered with the same string:
|
|
40
|
+
* "has no beta place", "subscription lapsed", "has connected nothing yet" and
|
|
41
|
+
* "was left in a state we do not recognise" were indistinguishable outside a
|
|
42
|
+
* database session. One beta tester was refused across /dashboard, /inbox,
|
|
43
|
+
* /settings and a post page — 21 denials in 30 days — and the only way to find
|
|
44
|
+
* out why was to open the database by hand.
|
|
45
|
+
*
|
|
46
|
+
* NOTHING HERE MAY SAY ANYTHING ABOUT THE ACCOUNT beyond which condition
|
|
47
|
+
* failed. These names travel to the browser. `UNRECOGNISED_PLAN` deliberately
|
|
48
|
+
* does not carry WHICH plan value was unrecognised — that belongs in the
|
|
49
|
+
* server-side log.
|
|
50
|
+
*/
|
|
51
|
+
export declare const ENTITLEMENT_PRECONDITIONS: {
|
|
52
|
+
/** No such user row. Unentitled, not merely unconnected. */
|
|
53
|
+
readonly UNKNOWN_ACCOUNT: "unknown-account";
|
|
54
|
+
/**
|
|
55
|
+
* A plan value the allow-list deliberately refuses: 'TRIALING', 'PAST_DUE',
|
|
56
|
+
* a future tier, or a typo. Split out of NO_ENTITLEMENT on purpose — both
|
|
57
|
+
* stay refused, and the fail-closed property of the allow-list is not
|
|
58
|
+
* touched, but a plan value we do not recognise is a DEFECT and a plain free
|
|
59
|
+
* account is not. Reported separately because that distinction is most of
|
|
60
|
+
* what makes a locked-out account diagnosable.
|
|
61
|
+
*/
|
|
62
|
+
readonly UNRECOGNISED_PLAN: "unrecognised-plan";
|
|
63
|
+
/** No paid plan and no live beta place; or a lapsed payer / lapsed place
|
|
64
|
+
* holder, who keeps read-only access to content we hold but has no claim on
|
|
65
|
+
* a live vendor read. */
|
|
66
|
+
readonly NO_ENTITLEMENT: "no-entitlement";
|
|
67
|
+
/** Entitled, and has connected nothing yet. They need an account, NOT a
|
|
68
|
+
* purchase — the distinction spec 144 drew in prose and nothing recorded. */
|
|
69
|
+
readonly NO_CONNECTION: "no-connection";
|
|
70
|
+
};
|
|
71
|
+
export type EntitlementPrecondition = (typeof ENTITLEMENT_PRECONDITIONS)[keyof typeof ENTITLEMENT_PRECONDITIONS];
|
|
29
72
|
/**
|
|
30
73
|
* The body shape those 403s answer with. `statusCode`/`error` are carried
|
|
31
74
|
* explicitly so the response stays byte-identical to Nest's default envelope
|
|
32
75
|
* and `code` is purely additive — no existing consumer sees a change.
|
|
76
|
+
*
|
|
77
|
+
* `precondition` is additive in exactly the same way, and OPTIONAL, which is
|
|
78
|
+
* what makes two promises true by construction: a client that ignores it
|
|
79
|
+
* behaves as it does today, and a response from a backend that predates it is
|
|
80
|
+
* still a valid body rather than something a consumer has to special-case.
|
|
33
81
|
*/
|
|
34
82
|
export interface I_AccessDenialBody {
|
|
35
83
|
statusCode: number;
|
|
36
84
|
error: string;
|
|
37
85
|
message: string;
|
|
38
86
|
code: AccessDenialCode;
|
|
87
|
+
precondition?: EntitlementPrecondition;
|
|
39
88
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ACCESS_DENIAL_CODES = void 0;
|
|
3
|
+
exports.ENTITLEMENT_PRECONDITIONS = exports.ACCESS_DENIAL_CODES = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Why a 403 happened, as a value a client can branch on.
|
|
6
6
|
*
|
|
@@ -28,3 +28,45 @@ exports.ACCESS_DENIAL_CODES = {
|
|
|
28
28
|
*/
|
|
29
29
|
ENTITLEMENT_PRECONDITION: "entitlement-precondition",
|
|
30
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* WHICH precondition the entitlement wall refused on (backend#305, spec 170).
|
|
33
|
+
*
|
|
34
|
+
* `ENTITLEMENT_PRECONDITION` above is the CLIENT contract: every cause below
|
|
35
|
+
* wants the same behaviour from a client — render the surface's own empty
|
|
36
|
+
* state, do not redirect, never send a paying user to buy a plan they already
|
|
37
|
+
* own — so a fourth code would force every consumer to re-learn a wall it
|
|
38
|
+
* already handles correctly, to carry information no consumer acts on.
|
|
39
|
+
*
|
|
40
|
+
* This is for whoever is READING. There is one throw site in the backend and
|
|
41
|
+
* four ways to reach it, and until now all four answered with the same string:
|
|
42
|
+
* "has no beta place", "subscription lapsed", "has connected nothing yet" and
|
|
43
|
+
* "was left in a state we do not recognise" were indistinguishable outside a
|
|
44
|
+
* database session. One beta tester was refused across /dashboard, /inbox,
|
|
45
|
+
* /settings and a post page — 21 denials in 30 days — and the only way to find
|
|
46
|
+
* out why was to open the database by hand.
|
|
47
|
+
*
|
|
48
|
+
* NOTHING HERE MAY SAY ANYTHING ABOUT THE ACCOUNT beyond which condition
|
|
49
|
+
* failed. These names travel to the browser. `UNRECOGNISED_PLAN` deliberately
|
|
50
|
+
* does not carry WHICH plan value was unrecognised — that belongs in the
|
|
51
|
+
* server-side log.
|
|
52
|
+
*/
|
|
53
|
+
exports.ENTITLEMENT_PRECONDITIONS = {
|
|
54
|
+
/** No such user row. Unentitled, not merely unconnected. */
|
|
55
|
+
UNKNOWN_ACCOUNT: "unknown-account",
|
|
56
|
+
/**
|
|
57
|
+
* A plan value the allow-list deliberately refuses: 'TRIALING', 'PAST_DUE',
|
|
58
|
+
* a future tier, or a typo. Split out of NO_ENTITLEMENT on purpose — both
|
|
59
|
+
* stay refused, and the fail-closed property of the allow-list is not
|
|
60
|
+
* touched, but a plan value we do not recognise is a DEFECT and a plain free
|
|
61
|
+
* account is not. Reported separately because that distinction is most of
|
|
62
|
+
* what makes a locked-out account diagnosable.
|
|
63
|
+
*/
|
|
64
|
+
UNRECOGNISED_PLAN: "unrecognised-plan",
|
|
65
|
+
/** No paid plan and no live beta place; or a lapsed payer / lapsed place
|
|
66
|
+
* holder, who keeps read-only access to content we hold but has no claim on
|
|
67
|
+
* a live vendor read. */
|
|
68
|
+
NO_ENTITLEMENT: "no-entitlement",
|
|
69
|
+
/** Entitled, and has connected nothing yet. They need an account, NOT a
|
|
70
|
+
* purchase — the distinction spec 144 drew in prose and nothing recorded. */
|
|
71
|
+
NO_CONNECTION: "no-connection",
|
|
72
|
+
};
|
package/package.json
CHANGED
|
@@ -29,14 +29,66 @@ export const ACCESS_DENIAL_CODES = {
|
|
|
29
29
|
export type AccessDenialCode =
|
|
30
30
|
(typeof ACCESS_DENIAL_CODES)[keyof typeof ACCESS_DENIAL_CODES];
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* WHICH precondition the entitlement wall refused on (backend#305, spec 170).
|
|
34
|
+
*
|
|
35
|
+
* `ENTITLEMENT_PRECONDITION` above is the CLIENT contract: every cause below
|
|
36
|
+
* wants the same behaviour from a client — render the surface's own empty
|
|
37
|
+
* state, do not redirect, never send a paying user to buy a plan they already
|
|
38
|
+
* own — so a fourth code would force every consumer to re-learn a wall it
|
|
39
|
+
* already handles correctly, to carry information no consumer acts on.
|
|
40
|
+
*
|
|
41
|
+
* This is for whoever is READING. There is one throw site in the backend and
|
|
42
|
+
* four ways to reach it, and until now all four answered with the same string:
|
|
43
|
+
* "has no beta place", "subscription lapsed", "has connected nothing yet" and
|
|
44
|
+
* "was left in a state we do not recognise" were indistinguishable outside a
|
|
45
|
+
* database session. One beta tester was refused across /dashboard, /inbox,
|
|
46
|
+
* /settings and a post page — 21 denials in 30 days — and the only way to find
|
|
47
|
+
* out why was to open the database by hand.
|
|
48
|
+
*
|
|
49
|
+
* NOTHING HERE MAY SAY ANYTHING ABOUT THE ACCOUNT beyond which condition
|
|
50
|
+
* failed. These names travel to the browser. `UNRECOGNISED_PLAN` deliberately
|
|
51
|
+
* does not carry WHICH plan value was unrecognised — that belongs in the
|
|
52
|
+
* server-side log.
|
|
53
|
+
*/
|
|
54
|
+
export const ENTITLEMENT_PRECONDITIONS = {
|
|
55
|
+
/** No such user row. Unentitled, not merely unconnected. */
|
|
56
|
+
UNKNOWN_ACCOUNT: "unknown-account",
|
|
57
|
+
/**
|
|
58
|
+
* A plan value the allow-list deliberately refuses: 'TRIALING', 'PAST_DUE',
|
|
59
|
+
* a future tier, or a typo. Split out of NO_ENTITLEMENT on purpose — both
|
|
60
|
+
* stay refused, and the fail-closed property of the allow-list is not
|
|
61
|
+
* touched, but a plan value we do not recognise is a DEFECT and a plain free
|
|
62
|
+
* account is not. Reported separately because that distinction is most of
|
|
63
|
+
* what makes a locked-out account diagnosable.
|
|
64
|
+
*/
|
|
65
|
+
UNRECOGNISED_PLAN: "unrecognised-plan",
|
|
66
|
+
/** No paid plan and no live beta place; or a lapsed payer / lapsed place
|
|
67
|
+
* holder, who keeps read-only access to content we hold but has no claim on
|
|
68
|
+
* a live vendor read. */
|
|
69
|
+
NO_ENTITLEMENT: "no-entitlement",
|
|
70
|
+
/** Entitled, and has connected nothing yet. They need an account, NOT a
|
|
71
|
+
* purchase — the distinction spec 144 drew in prose and nothing recorded. */
|
|
72
|
+
NO_CONNECTION: "no-connection",
|
|
73
|
+
} as const;
|
|
74
|
+
|
|
75
|
+
export type EntitlementPrecondition =
|
|
76
|
+
(typeof ENTITLEMENT_PRECONDITIONS)[keyof typeof ENTITLEMENT_PRECONDITIONS];
|
|
77
|
+
|
|
32
78
|
/**
|
|
33
79
|
* The body shape those 403s answer with. `statusCode`/`error` are carried
|
|
34
80
|
* explicitly so the response stays byte-identical to Nest's default envelope
|
|
35
81
|
* and `code` is purely additive — no existing consumer sees a change.
|
|
82
|
+
*
|
|
83
|
+
* `precondition` is additive in exactly the same way, and OPTIONAL, which is
|
|
84
|
+
* what makes two promises true by construction: a client that ignores it
|
|
85
|
+
* behaves as it does today, and a response from a backend that predates it is
|
|
86
|
+
* still a valid body rather than something a consumer has to special-case.
|
|
36
87
|
*/
|
|
37
88
|
export interface I_AccessDenialBody {
|
|
38
89
|
statusCode: number;
|
|
39
90
|
error: string;
|
|
40
91
|
message: string;
|
|
41
92
|
code: AccessDenialCode;
|
|
93
|
+
precondition?: EntitlementPrecondition;
|
|
42
94
|
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { strict as assert } from 'node:assert';
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
ACCESS_DENIAL_CODES,
|
|
6
|
+
ENTITLEMENT_PRECONDITIONS,
|
|
7
|
+
type EntitlementPrecondition,
|
|
8
|
+
type I_AccessDenialBody,
|
|
9
|
+
} from './I_AccessDenial';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Spec 170 T003. These four strings are a contract between three repos and a
|
|
13
|
+
* PostHog query someone will write against them: a rename is a silent break in
|
|
14
|
+
* whichever of the three does not get rebuilt, and the query just stops
|
|
15
|
+
* matching. Pinned here so a rename has to be a decision.
|
|
16
|
+
*/
|
|
17
|
+
test('the four precondition names are stable strings', () => {
|
|
18
|
+
assert.deepEqual(ENTITLEMENT_PRECONDITIONS, {
|
|
19
|
+
UNKNOWN_ACCOUNT: 'unknown-account',
|
|
20
|
+
UNRECOGNISED_PLAN: 'unrecognised-plan',
|
|
21
|
+
NO_ENTITLEMENT: 'no-entitlement',
|
|
22
|
+
NO_CONNECTION: 'no-connection',
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('the union covers every name and nothing else', () => {
|
|
27
|
+
const all: EntitlementPrecondition[] = Object.values(ENTITLEMENT_PRECONDITIONS);
|
|
28
|
+
assert.equal(new Set(all).size, 4);
|
|
29
|
+
// Exhaustiveness, checked by the compiler: adding a name without handling it
|
|
30
|
+
// here stops building.
|
|
31
|
+
for (const value of all) {
|
|
32
|
+
switch (value) {
|
|
33
|
+
case 'unknown-account':
|
|
34
|
+
case 'unrecognised-plan':
|
|
35
|
+
case 'no-entitlement':
|
|
36
|
+
case 'no-connection':
|
|
37
|
+
break;
|
|
38
|
+
default: {
|
|
39
|
+
const never: never = value;
|
|
40
|
+
throw new Error(`unhandled precondition ${String(never)}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('precondition is optional, so an older backend still sends a valid body', () => {
|
|
47
|
+
// The whole point of the field being optional: this has to compile.
|
|
48
|
+
const withoutIt: I_AccessDenialBody = {
|
|
49
|
+
statusCode: 403,
|
|
50
|
+
error: 'Forbidden',
|
|
51
|
+
message: 'Analytics require a paid plan with a connected Late profile',
|
|
52
|
+
code: ACCESS_DENIAL_CODES.ENTITLEMENT_PRECONDITION,
|
|
53
|
+
};
|
|
54
|
+
assert.equal(withoutIt.precondition, undefined);
|
|
55
|
+
|
|
56
|
+
const withIt: I_AccessDenialBody = {
|
|
57
|
+
...withoutIt,
|
|
58
|
+
precondition: ENTITLEMENT_PRECONDITIONS.NO_CONNECTION,
|
|
59
|
+
};
|
|
60
|
+
assert.equal(withIt.precondition, 'no-connection');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('the denial codes are untouched', () => {
|
|
64
|
+
// FR-003: this feature adds a field, it does not renegotiate `code`.
|
|
65
|
+
assert.deepEqual(ACCESS_DENIAL_CODES, {
|
|
66
|
+
BETA_REQUIRED: 'beta-required',
|
|
67
|
+
SUBSCRIPTION_REQUIRED: 'subscription-required',
|
|
68
|
+
ENTITLEMENT_PRECONDITION: 'entitlement-precondition',
|
|
69
|
+
});
|
|
70
|
+
});
|