ppussh 0.2.1 → 0.2.2
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/dist/accounts/index.d.ts +1 -2
- package/dist/accounts/index.d.ts.map +1 -1
- package/dist/accounts/index.js +1 -3
- package/dist/accounts/index.js.map +1 -1
- package/dist/accounts/namespace.d.ts +17 -142
- package/dist/accounts/namespace.d.ts.map +1 -1
- package/dist/accounts/namespace.js +19 -237
- package/dist/accounts/namespace.js.map +1 -1
- package/dist/accounts/types.d.ts +0 -32
- package/dist/accounts/types.d.ts.map +1 -1
- package/dist/accounts/types.js +0 -5
- package/dist/accounts/types.js.map +1 -1
- package/dist/client.d.ts +1 -4
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1 -4
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +4 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/accounts/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export type { EntitlementResponse,
|
|
2
|
-
export { effectiveAccessToken } from "./types";
|
|
1
|
+
export type { EntitlementResponse, SessionResponse, UserProfile, VerifyTokenResult, } from "./types";
|
|
3
2
|
export { AccountsNamespace } from "./namespace";
|
|
4
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/accounts/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,mBAAmB,EACnB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/accounts/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,mBAAmB,EACnB,eAAe,EACf,WAAW,EACX,iBAAiB,GAClB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/accounts/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AccountsNamespace =
|
|
4
|
-
var types_1 = require("./types");
|
|
5
|
-
Object.defineProperty(exports, "effectiveAccessToken", { enumerable: true, get: function () { return types_1.effectiveAccessToken; } });
|
|
3
|
+
exports.AccountsNamespace = void 0;
|
|
6
4
|
var namespace_1 = require("./namespace");
|
|
7
5
|
Object.defineProperty(exports, "AccountsNamespace", { enumerable: true, get: function () { return namespace_1.AccountsNamespace; } });
|
|
8
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/accounts/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/accounts/index.ts"],"names":[],"mappings":";;;AAOA,yCAAgD;AAAvC,8GAAA,iBAAiB,OAAA"}
|
|
@@ -1,166 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* AccountsNamespace —
|
|
2
|
+
* AccountsNamespace — stateless helpers for Accounts service API calls.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* getUser() → fetch the full user profile for the stored access token
|
|
13
|
-
* getEntitlements() → list entitlements for the authenticated user
|
|
4
|
+
* The product backend handles the OIDC flow (login, callback, token exchange)
|
|
5
|
+
* and cookie management itself. This namespace provides lightweight wrappers
|
|
6
|
+
* for the few server-side calls the product backend needs:
|
|
7
|
+
*
|
|
8
|
+
* buildLoginUrl() → build the redirect URL to send the user to Accounts
|
|
9
|
+
* verifyToken() → validate an incoming access token (from request cookies)
|
|
10
|
+
* getUser() → fetch the full user profile
|
|
11
|
+
* getEntitlements() → list products the user has granted consent to
|
|
14
12
|
* getSessions() → list active sessions for the authenticated user
|
|
13
|
+
* revokeSession() → revoke a single session by ID
|
|
15
14
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* _accessToken — attached automatically to getUser() / getEntitlements() / getSessions()
|
|
19
|
-
* _refreshToken — used automatically by refresh() and logout() if not passed explicitly
|
|
20
|
-
* _tokenExpiresAt — informational; not used for auto-refresh (caller's responsibility)
|
|
15
|
+
* No tokens are stored internally — every method requiring authentication
|
|
16
|
+
* expects an explicit ``accessToken`` parameter.
|
|
21
17
|
*/
|
|
22
18
|
import { HttpTransport } from "../http";
|
|
23
|
-
import { EntitlementResponse,
|
|
19
|
+
import { EntitlementResponse, SessionResponse, UserProfile, VerifyTokenResult } from "./types";
|
|
24
20
|
export declare class AccountsNamespace {
|
|
25
21
|
private readonly _http;
|
|
26
22
|
private readonly _clientId;
|
|
27
23
|
private readonly _clientSecret;
|
|
28
24
|
private readonly _accountsUrl;
|
|
29
25
|
private readonly _accountsFrontendUrl;
|
|
30
|
-
private _accessToken;
|
|
31
|
-
private _refreshToken;
|
|
32
|
-
private _tokenExpiresAt;
|
|
33
26
|
constructor(transport: HttpTransport, options: {
|
|
34
27
|
clientId: string;
|
|
35
28
|
clientSecret: string;
|
|
36
29
|
accountsUrl: string;
|
|
37
30
|
accountsFrontendUrl: string;
|
|
38
31
|
});
|
|
39
|
-
/**
|
|
40
|
-
* Build the URL to redirect the user's browser to the Accounts login page.
|
|
41
|
-
*
|
|
42
|
-
* This is step 2 of the OIDC flow — call this in your route handler and
|
|
43
|
-
* issue a 302 redirect to the returned URL. The Accounts frontend handles
|
|
44
|
-
* email/password login as well as Google and GitHub social login; the
|
|
45
|
-
* product backend never needs to call social-auth endpoints directly.
|
|
46
|
-
*
|
|
47
|
-
* @param redirectUri Must exactly match the redirect_uri registered for your product.
|
|
48
|
-
* @param state A cryptographically random string stored in the user's session
|
|
49
|
-
* to prevent CSRF attacks.
|
|
50
|
-
* @param opts.nextUrl Optional URL the Accounts frontend redirects to after login
|
|
51
|
-
* within its own domain (rarely needed).
|
|
52
|
-
* @returns The full login URL, e.g. `https://accounts.example.com/login?client_id=...`
|
|
53
|
-
*/
|
|
54
32
|
buildLoginUrl(redirectUri: string, state: string, opts?: {
|
|
55
33
|
nextUrl?: string;
|
|
56
34
|
}): string;
|
|
57
|
-
/**
|
|
58
|
-
* Exchange the authorization code received on your callback URL for tokens.
|
|
59
|
-
*
|
|
60
|
-
* This is step 6 of the OIDC flow — called by your server after the
|
|
61
|
-
* Accounts frontend redirects the user back to your redirectUri with
|
|
62
|
-
* `?code=...&state=...` in the query string.
|
|
63
|
-
*
|
|
64
|
-
* @param code The raw 64-char hex auth code from the callback URL.
|
|
65
|
-
* @param redirectUri Must exactly match the redirect_uri registered for your product.
|
|
66
|
-
* @returns TokenResponse — contains tokens and an embedded UserInToken.
|
|
67
|
-
* Tokens are also stored internally for subsequent calls.
|
|
68
|
-
* @throws PpusshAuthError If the code is invalid, expired, or already used.
|
|
69
|
-
* @throws PpusshConsentRequired If the user has not consented to your product.
|
|
70
|
-
* @throws PpusshNetworkError If the request fails after all retries.
|
|
71
|
-
*/
|
|
72
|
-
exchangeCode(code: string, redirectUri: string): Promise<TokenResponse>;
|
|
73
|
-
/**
|
|
74
|
-
* Rotate tokens using a refresh token.
|
|
75
|
-
*
|
|
76
|
-
* If refreshToken is omitted, the internally stored refresh token
|
|
77
|
-
* from the last exchangeCode() / refresh() call is used.
|
|
78
|
-
*
|
|
79
|
-
* @throws PpusshAuthError If the refresh token is invalid, expired, or replayed.
|
|
80
|
-
* Note: a replayed token causes ALL sessions to be revoked
|
|
81
|
-
* server-side — this is a security feature, not a bug.
|
|
82
|
-
*/
|
|
83
|
-
refresh(refreshToken?: string): Promise<TokenResponse>;
|
|
84
|
-
/**
|
|
85
|
-
* Validate an access token your server received from an end-user request.
|
|
86
|
-
*
|
|
87
|
-
* Use this in your middleware / request handler to verify that the Bearer
|
|
88
|
-
* token a user sent to your product's API is valid and not expired.
|
|
89
|
-
*
|
|
90
|
-
* @param accessToken The raw JWT string from the `Authorization: Bearer ...` header.
|
|
91
|
-
* @returns VerifyTokenResult with valid, type, user_id, and email.
|
|
92
|
-
* @throws PpusshAuthError If the token is invalid, expired, or the account is deleted.
|
|
93
|
-
*/
|
|
94
35
|
verifyToken(accessToken: string): Promise<VerifyTokenResult>;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
* per-session logout that also notifies downstream products via webhooks.
|
|
100
|
-
*
|
|
101
|
-
* If refreshToken is omitted, the internally stored refresh token is used.
|
|
102
|
-
* On success, stored tokens are cleared from the client instance.
|
|
103
|
-
*
|
|
104
|
-
* Logout is always safe to call — if the token is already invalid or the session
|
|
105
|
-
* doesn't exist, the Accounts server returns ok=true silently.
|
|
106
|
-
*
|
|
107
|
-
* @throws PpusshAuthError If client_id or client_secret are invalid.
|
|
108
|
-
*/
|
|
109
|
-
logout(refreshToken?: string): Promise<LogoutResult>;
|
|
110
|
-
/**
|
|
111
|
-
* Revoke **all** sessions for the current user immediately.
|
|
112
|
-
*
|
|
113
|
-
* Uses POST /auth/logout with the access token (Bearer header).
|
|
114
|
-
* Unlike logout(), this does not require a refresh token and revokes every
|
|
115
|
-
* active session across all devices — useful for "sign out everywhere" UX.
|
|
116
|
-
*
|
|
117
|
-
* On success, stored tokens are cleared from the client instance.
|
|
118
|
-
*
|
|
119
|
-
* @param accessToken JWT access token. Optional if stored internally.
|
|
120
|
-
* @throws PpusshAuthError If the token is invalid or expired.
|
|
121
|
-
*/
|
|
122
|
-
logoutAll(accessToken?: string): Promise<void>;
|
|
123
|
-
/**
|
|
124
|
-
* Revoke a specific session by its ID.
|
|
125
|
-
*
|
|
126
|
-
* Uses DELETE /auth/sessions/{sessionId} — the user can only revoke their
|
|
127
|
-
* own sessions. Useful for "sign out of this device" UX in a session
|
|
128
|
-
* management screen.
|
|
129
|
-
*
|
|
130
|
-
* @param sessionId The UUID of the session to revoke (from getSessions()).
|
|
131
|
-
* @param accessToken JWT access token. Optional if stored internally.
|
|
132
|
-
* @throws PpusshAuthError If the token is invalid or the session does not
|
|
133
|
-
* belong to the authenticated user.
|
|
134
|
-
*/
|
|
135
|
-
revokeSession(sessionId: string, accessToken?: string): Promise<void>;
|
|
136
|
-
/**
|
|
137
|
-
* Fetch the full user profile for an access token.
|
|
138
|
-
*
|
|
139
|
-
* If accessToken is omitted, the internally stored token from the last
|
|
140
|
-
* exchangeCode() or refresh() is used.
|
|
141
|
-
*
|
|
142
|
-
* @throws PpusshAuthError If the token is invalid or expired.
|
|
143
|
-
*/
|
|
144
|
-
getUser(accessToken?: string): Promise<UserProfile>;
|
|
145
|
-
/**
|
|
146
|
-
* List products the user has granted consent to (their entitlements).
|
|
147
|
-
*
|
|
148
|
-
* @param accessToken JWT access token. Optional if stored internally.
|
|
149
|
-
*/
|
|
150
|
-
getEntitlements(accessToken?: string): Promise<EntitlementResponse[]>;
|
|
151
|
-
/**
|
|
152
|
-
* List all active sessions for the authenticated user.
|
|
153
|
-
*
|
|
154
|
-
* @param accessToken JWT access token. Optional if stored internally.
|
|
155
|
-
*/
|
|
156
|
-
getSessions(accessToken?: string): Promise<SessionResponse[]>;
|
|
157
|
-
private _storeTokens;
|
|
158
|
-
private _clearTokens;
|
|
159
|
-
/** The currently stored access token, if any. */
|
|
160
|
-
get accessToken(): string | null;
|
|
161
|
-
/** The currently stored refresh token, if any. */
|
|
162
|
-
get refreshToken(): string | null;
|
|
163
|
-
/** UTC Date at which the stored access token expires, if known. */
|
|
164
|
-
get tokenExpiresAt(): Date | null;
|
|
36
|
+
getUser(accessToken: string): Promise<UserProfile>;
|
|
37
|
+
getEntitlements(accessToken: string): Promise<EntitlementResponse[]>;
|
|
38
|
+
getSessions(accessToken: string): Promise<SessionResponse[]>;
|
|
39
|
+
revokeSession(sessionId: string, accessToken: string): Promise<void>;
|
|
165
40
|
}
|
|
166
41
|
//# sourceMappingURL=namespace.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"namespace.d.ts","sourceRoot":"","sources":["../../src/accounts/namespace.ts"],"names":[],"mappings":"AACA
|
|
1
|
+
{"version":3,"file":"namespace.d.ts","sourceRoot":"","sources":["../../src/accounts/namespace.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,WAAW,EACX,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAEjB,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgB;IACtC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAS;gBAG5C,SAAS,EAAE,aAAa,EACxB,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,mBAAmB,EAAE,MAAM,CAAA;KAAE;IAWvG,aAAa,CACX,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,IAAI,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAC1B,MAAM;IAcH,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAS5D,OAAO,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IASlD,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC;IAOpE,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAO5D,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAK3E"}
|
|
@@ -1,34 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// ppussh/src/accounts/namespace.ts
|
|
3
3
|
/**
|
|
4
|
-
* AccountsNamespace —
|
|
4
|
+
* AccountsNamespace — stateless helpers for Accounts service API calls.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* getUser() → fetch the full user profile for the stored access token
|
|
15
|
-
* getEntitlements() → list entitlements for the authenticated user
|
|
6
|
+
* The product backend handles the OIDC flow (login, callback, token exchange)
|
|
7
|
+
* and cookie management itself. This namespace provides lightweight wrappers
|
|
8
|
+
* for the few server-side calls the product backend needs:
|
|
9
|
+
*
|
|
10
|
+
* buildLoginUrl() → build the redirect URL to send the user to Accounts
|
|
11
|
+
* verifyToken() → validate an incoming access token (from request cookies)
|
|
12
|
+
* getUser() → fetch the full user profile
|
|
13
|
+
* getEntitlements() → list products the user has granted consent to
|
|
16
14
|
* getSessions() → list active sessions for the authenticated user
|
|
15
|
+
* revokeSession() → revoke a single session by ID
|
|
17
16
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* _accessToken — attached automatically to getUser() / getEntitlements() / getSessions()
|
|
21
|
-
* _refreshToken — used automatically by refresh() and logout() if not passed explicitly
|
|
22
|
-
* _tokenExpiresAt — informational; not used for auto-refresh (caller's responsibility)
|
|
17
|
+
* No tokens are stored internally — every method requiring authentication
|
|
18
|
+
* expects an explicit ``accessToken`` parameter.
|
|
23
19
|
*/
|
|
24
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
21
|
exports.AccountsNamespace = void 0;
|
|
26
|
-
const types_1 = require("./types");
|
|
27
22
|
class AccountsNamespace {
|
|
28
23
|
constructor(transport, options) {
|
|
29
|
-
this._accessToken = null;
|
|
30
|
-
this._refreshToken = null;
|
|
31
|
-
this._tokenExpiresAt = null;
|
|
32
24
|
this._http = transport;
|
|
33
25
|
this._clientId = options.clientId;
|
|
34
26
|
this._clientSecret = options.clientSecret;
|
|
@@ -36,21 +28,6 @@ class AccountsNamespace {
|
|
|
36
28
|
this._accountsFrontendUrl = options.accountsFrontendUrl;
|
|
37
29
|
}
|
|
38
30
|
// ── Login URL builder ──────────────────────────────────────────────────────
|
|
39
|
-
/**
|
|
40
|
-
* Build the URL to redirect the user's browser to the Accounts login page.
|
|
41
|
-
*
|
|
42
|
-
* This is step 2 of the OIDC flow — call this in your route handler and
|
|
43
|
-
* issue a 302 redirect to the returned URL. The Accounts frontend handles
|
|
44
|
-
* email/password login as well as Google and GitHub social login; the
|
|
45
|
-
* product backend never needs to call social-auth endpoints directly.
|
|
46
|
-
*
|
|
47
|
-
* @param redirectUri Must exactly match the redirect_uri registered for your product.
|
|
48
|
-
* @param state A cryptographically random string stored in the user's session
|
|
49
|
-
* to prevent CSRF attacks.
|
|
50
|
-
* @param opts.nextUrl Optional URL the Accounts frontend redirects to after login
|
|
51
|
-
* within its own domain (rarely needed).
|
|
52
|
-
* @returns The full login URL, e.g. `https://accounts.example.com/login?client_id=...`
|
|
53
|
-
*/
|
|
54
31
|
buildLoginUrl(redirectUri, state, opts) {
|
|
55
32
|
const params = new URLSearchParams({
|
|
56
33
|
client_id: this._clientId,
|
|
@@ -62,232 +39,37 @@ class AccountsNamespace {
|
|
|
62
39
|
}
|
|
63
40
|
return `${this._accountsFrontendUrl}/login?${params.toString()}`;
|
|
64
41
|
}
|
|
65
|
-
// ── OIDC token exchange ────────────────────────────────────────────────────
|
|
66
|
-
/**
|
|
67
|
-
* Exchange the authorization code received on your callback URL for tokens.
|
|
68
|
-
*
|
|
69
|
-
* This is step 6 of the OIDC flow — called by your server after the
|
|
70
|
-
* Accounts frontend redirects the user back to your redirectUri with
|
|
71
|
-
* `?code=...&state=...` in the query string.
|
|
72
|
-
*
|
|
73
|
-
* @param code The raw 64-char hex auth code from the callback URL.
|
|
74
|
-
* @param redirectUri Must exactly match the redirect_uri registered for your product.
|
|
75
|
-
* @returns TokenResponse — contains tokens and an embedded UserInToken.
|
|
76
|
-
* Tokens are also stored internally for subsequent calls.
|
|
77
|
-
* @throws PpusshAuthError If the code is invalid, expired, or already used.
|
|
78
|
-
* @throws PpusshConsentRequired If the user has not consented to your product.
|
|
79
|
-
* @throws PpusshNetworkError If the request fails after all retries.
|
|
80
|
-
*/
|
|
81
|
-
async exchangeCode(code, redirectUri) {
|
|
82
|
-
const response = await this._http.request("POST", "/oauth/token", {
|
|
83
|
-
form: {
|
|
84
|
-
grant_type: "authorization_code",
|
|
85
|
-
code,
|
|
86
|
-
client_id: this._clientId,
|
|
87
|
-
client_secret: this._clientSecret,
|
|
88
|
-
redirect_uri: redirectUri,
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
const token = response.data;
|
|
92
|
-
this._storeTokens(token);
|
|
93
|
-
return token;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Rotate tokens using a refresh token.
|
|
97
|
-
*
|
|
98
|
-
* If refreshToken is omitted, the internally stored refresh token
|
|
99
|
-
* from the last exchangeCode() / refresh() call is used.
|
|
100
|
-
*
|
|
101
|
-
* @throws PpusshAuthError If the refresh token is invalid, expired, or replayed.
|
|
102
|
-
* Note: a replayed token causes ALL sessions to be revoked
|
|
103
|
-
* server-side — this is a security feature, not a bug.
|
|
104
|
-
*/
|
|
105
|
-
async refresh(refreshToken) {
|
|
106
|
-
const tokenToUse = refreshToken ?? this._refreshToken;
|
|
107
|
-
if (!tokenToUse) {
|
|
108
|
-
throw new Error("No refreshToken provided and none stored. " +
|
|
109
|
-
"Call exchangeCode() first or pass refreshToken explicitly.");
|
|
110
|
-
}
|
|
111
|
-
const response = await this._http.request("POST", "/oauth/token", {
|
|
112
|
-
form: {
|
|
113
|
-
grant_type: "refresh_token",
|
|
114
|
-
refresh_token: tokenToUse,
|
|
115
|
-
client_id: this._clientId,
|
|
116
|
-
client_secret: this._clientSecret,
|
|
117
|
-
},
|
|
118
|
-
});
|
|
119
|
-
const token = response.data;
|
|
120
|
-
this._storeTokens(token);
|
|
121
|
-
return token;
|
|
122
|
-
}
|
|
123
42
|
// ── Token verification ─────────────────────────────────────────────────────
|
|
124
|
-
/**
|
|
125
|
-
* Validate an access token your server received from an end-user request.
|
|
126
|
-
*
|
|
127
|
-
* Use this in your middleware / request handler to verify that the Bearer
|
|
128
|
-
* token a user sent to your product's API is valid and not expired.
|
|
129
|
-
*
|
|
130
|
-
* @param accessToken The raw JWT string from the `Authorization: Bearer ...` header.
|
|
131
|
-
* @returns VerifyTokenResult with valid, type, user_id, and email.
|
|
132
|
-
* @throws PpusshAuthError If the token is invalid, expired, or the account is deleted.
|
|
133
|
-
*/
|
|
134
43
|
async verifyToken(accessToken) {
|
|
135
44
|
const response = await this._http.request("GET", "/auth/verify-token", {
|
|
136
45
|
headers: { Authorization: `Bearer ${accessToken}` },
|
|
137
46
|
});
|
|
138
47
|
return response.data;
|
|
139
48
|
}
|
|
140
|
-
// ── Logout ─────────────────────────────────────────────────────────────────
|
|
141
|
-
/**
|
|
142
|
-
* Revoke a session and trigger front-channel logout to all connected products.
|
|
143
|
-
*
|
|
144
|
-
* Uses POST /oauth/logout with the refresh token — this is the standard
|
|
145
|
-
* per-session logout that also notifies downstream products via webhooks.
|
|
146
|
-
*
|
|
147
|
-
* If refreshToken is omitted, the internally stored refresh token is used.
|
|
148
|
-
* On success, stored tokens are cleared from the client instance.
|
|
149
|
-
*
|
|
150
|
-
* Logout is always safe to call — if the token is already invalid or the session
|
|
151
|
-
* doesn't exist, the Accounts server returns ok=true silently.
|
|
152
|
-
*
|
|
153
|
-
* @throws PpusshAuthError If client_id or client_secret are invalid.
|
|
154
|
-
*/
|
|
155
|
-
async logout(refreshToken) {
|
|
156
|
-
const tokenToUse = refreshToken ?? this._refreshToken;
|
|
157
|
-
if (!tokenToUse) {
|
|
158
|
-
throw new Error("No refreshToken provided and none stored. " +
|
|
159
|
-
"Call exchangeCode() first or pass refreshToken explicitly.");
|
|
160
|
-
}
|
|
161
|
-
const response = await this._http.request("POST", "/oauth/logout", {
|
|
162
|
-
json: {
|
|
163
|
-
refresh_token: tokenToUse,
|
|
164
|
-
client_id: this._clientId,
|
|
165
|
-
client_secret: this._clientSecret,
|
|
166
|
-
},
|
|
167
|
-
});
|
|
168
|
-
const result = response.data;
|
|
169
|
-
this._clearTokens();
|
|
170
|
-
return result;
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Revoke **all** sessions for the current user immediately.
|
|
174
|
-
*
|
|
175
|
-
* Uses POST /auth/logout with the access token (Bearer header).
|
|
176
|
-
* Unlike logout(), this does not require a refresh token and revokes every
|
|
177
|
-
* active session across all devices — useful for "sign out everywhere" UX.
|
|
178
|
-
*
|
|
179
|
-
* On success, stored tokens are cleared from the client instance.
|
|
180
|
-
*
|
|
181
|
-
* @param accessToken JWT access token. Optional if stored internally.
|
|
182
|
-
* @throws PpusshAuthError If the token is invalid or expired.
|
|
183
|
-
*/
|
|
184
|
-
async logoutAll(accessToken) {
|
|
185
|
-
const tokenToUse = accessToken ?? this._accessToken;
|
|
186
|
-
if (!tokenToUse) {
|
|
187
|
-
throw new Error("No accessToken provided and none stored. " +
|
|
188
|
-
"Call exchangeCode() first or pass accessToken explicitly.");
|
|
189
|
-
}
|
|
190
|
-
await this._http.request("POST", "/auth/logout", {
|
|
191
|
-
headers: { Authorization: `Bearer ${tokenToUse}` },
|
|
192
|
-
});
|
|
193
|
-
this._clearTokens();
|
|
194
|
-
}
|
|
195
|
-
// ── Session management ─────────────────────────────────────────────────────
|
|
196
|
-
/**
|
|
197
|
-
* Revoke a specific session by its ID.
|
|
198
|
-
*
|
|
199
|
-
* Uses DELETE /auth/sessions/{sessionId} — the user can only revoke their
|
|
200
|
-
* own sessions. Useful for "sign out of this device" UX in a session
|
|
201
|
-
* management screen.
|
|
202
|
-
*
|
|
203
|
-
* @param sessionId The UUID of the session to revoke (from getSessions()).
|
|
204
|
-
* @param accessToken JWT access token. Optional if stored internally.
|
|
205
|
-
* @throws PpusshAuthError If the token is invalid or the session does not
|
|
206
|
-
* belong to the authenticated user.
|
|
207
|
-
*/
|
|
208
|
-
async revokeSession(sessionId, accessToken) {
|
|
209
|
-
const tokenToUse = accessToken ?? this._accessToken;
|
|
210
|
-
if (!tokenToUse) {
|
|
211
|
-
throw new Error("No accessToken provided and none stored. " +
|
|
212
|
-
"Call exchangeCode() first or pass accessToken explicitly.");
|
|
213
|
-
}
|
|
214
|
-
await this._http.request("DELETE", `/auth/sessions/${sessionId}`, {
|
|
215
|
-
headers: { Authorization: `Bearer ${tokenToUse}` },
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
49
|
// ── User profile ───────────────────────────────────────────────────────────
|
|
219
|
-
/**
|
|
220
|
-
* Fetch the full user profile for an access token.
|
|
221
|
-
*
|
|
222
|
-
* If accessToken is omitted, the internally stored token from the last
|
|
223
|
-
* exchangeCode() or refresh() is used.
|
|
224
|
-
*
|
|
225
|
-
* @throws PpusshAuthError If the token is invalid or expired.
|
|
226
|
-
*/
|
|
227
50
|
async getUser(accessToken) {
|
|
228
|
-
const tokenToUse = accessToken ?? this._accessToken;
|
|
229
|
-
if (!tokenToUse) {
|
|
230
|
-
throw new Error("No accessToken provided and none stored. " +
|
|
231
|
-
"Call exchangeCode() first or pass accessToken explicitly.");
|
|
232
|
-
}
|
|
233
51
|
const response = await this._http.request("GET", "/users/me", {
|
|
234
|
-
headers: { Authorization: `Bearer ${
|
|
52
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
235
53
|
});
|
|
236
54
|
return response.data;
|
|
237
55
|
}
|
|
238
56
|
// ── Entitlements & sessions ────────────────────────────────────────────────
|
|
239
|
-
/**
|
|
240
|
-
* List products the user has granted consent to (their entitlements).
|
|
241
|
-
*
|
|
242
|
-
* @param accessToken JWT access token. Optional if stored internally.
|
|
243
|
-
*/
|
|
244
57
|
async getEntitlements(accessToken) {
|
|
245
|
-
const tokenToUse = accessToken ?? this._accessToken;
|
|
246
|
-
if (!tokenToUse) {
|
|
247
|
-
throw new Error("No accessToken provided and none stored.");
|
|
248
|
-
}
|
|
249
58
|
const response = await this._http.request("GET", "/users/me/entitlements", {
|
|
250
|
-
headers: { Authorization: `Bearer ${
|
|
59
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
251
60
|
});
|
|
252
61
|
return response.data;
|
|
253
62
|
}
|
|
254
|
-
/**
|
|
255
|
-
* List all active sessions for the authenticated user.
|
|
256
|
-
*
|
|
257
|
-
* @param accessToken JWT access token. Optional if stored internally.
|
|
258
|
-
*/
|
|
259
63
|
async getSessions(accessToken) {
|
|
260
|
-
const tokenToUse = accessToken ?? this._accessToken;
|
|
261
|
-
if (!tokenToUse) {
|
|
262
|
-
throw new Error("No accessToken provided and none stored.");
|
|
263
|
-
}
|
|
264
64
|
const response = await this._http.request("GET", "/users/me/sessions", {
|
|
265
|
-
headers: { Authorization: `Bearer ${
|
|
65
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
266
66
|
});
|
|
267
67
|
return response.data;
|
|
268
68
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
this._tokenExpiresAt = new Date(Date.now() + token.expires_in * 1000);
|
|
274
|
-
}
|
|
275
|
-
_clearTokens() {
|
|
276
|
-
this._accessToken = null;
|
|
277
|
-
this._refreshToken = null;
|
|
278
|
-
this._tokenExpiresAt = null;
|
|
279
|
-
}
|
|
280
|
-
/** The currently stored access token, if any. */
|
|
281
|
-
get accessToken() {
|
|
282
|
-
return this._accessToken;
|
|
283
|
-
}
|
|
284
|
-
/** The currently stored refresh token, if any. */
|
|
285
|
-
get refreshToken() {
|
|
286
|
-
return this._refreshToken;
|
|
287
|
-
}
|
|
288
|
-
/** UTC Date at which the stored access token expires, if known. */
|
|
289
|
-
get tokenExpiresAt() {
|
|
290
|
-
return this._tokenExpiresAt;
|
|
69
|
+
async revokeSession(sessionId, accessToken) {
|
|
70
|
+
await this._http.request("DELETE", `/auth/sessions/${sessionId}`, {
|
|
71
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
72
|
+
});
|
|
291
73
|
}
|
|
292
74
|
}
|
|
293
75
|
exports.AccountsNamespace = AccountsNamespace;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"namespace.js","sourceRoot":"","sources":["../../src/accounts/namespace.ts"],"names":[],"mappings":";AAAA,mCAAmC;AACnC
|
|
1
|
+
{"version":3,"file":"namespace.js","sourceRoot":"","sources":["../../src/accounts/namespace.ts"],"names":[],"mappings":";AAAA,mCAAmC;AACnC;;;;;;;;;;;;;;;;GAgBG;;;AAUH,MAAa,iBAAiB;IAO5B,YACE,SAAwB,EACxB,OAAqG;QAErG,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC;QAClC,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;QAC1C,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC;QACxC,IAAI,CAAC,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAC1D,CAAC;IAED,8EAA8E;IAE9E,aAAa,CACX,WAAmB,EACnB,KAAa,EACb,IAA2B;QAE3B,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC;YACjC,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,YAAY,EAAE,WAAW;YACzB,KAAK;SACN,CAAC,CAAC;QACH,IAAI,IAAI,EAAE,OAAO,EAAE,CAAC;YAClB,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACnC,CAAC;QACD,OAAO,GAAG,IAAI,CAAC,oBAAoB,UAAU,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;IACnE,CAAC;IAED,8EAA8E;IAE9E,KAAK,CAAC,WAAW,CAAC,WAAmB;QACnC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,oBAAoB,EAAE;YACrE,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE;SACpD,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,IAAyB,CAAC;IAC5C,CAAC;IAED,8EAA8E;IAE9E,KAAK,CAAC,OAAO,CAAC,WAAmB;QAC/B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE;YAC5D,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE;SACpD,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,IAAmB,CAAC;IACtC,CAAC;IAED,8EAA8E;IAE9E,KAAK,CAAC,eAAe,CAAC,WAAmB;QACvC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,wBAAwB,EAAE;YACzE,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE;SACpD,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,IAA6B,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,WAAmB;QACnC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,oBAAoB,EAAE;YACrE,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE;SACpD,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,IAAyB,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,SAAiB,EAAE,WAAmB;QACxD,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,kBAAkB,SAAS,EAAE,EAAE;YAChE,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE;SACpD,CAAC,CAAC;IACL,CAAC;CACF;AA3ED,8CA2EC"}
|
package/dist/accounts/types.d.ts
CHANGED
|
@@ -3,32 +3,6 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Mirror of the Python SDK's accounts/models.py — kept in sync manually.
|
|
5
5
|
*/
|
|
6
|
-
/** Minimal user profile embedded inside a TokenResponse. */
|
|
7
|
-
export interface UserInToken {
|
|
8
|
-
id: string;
|
|
9
|
-
email: string;
|
|
10
|
-
name: string | null;
|
|
11
|
-
email_verified: boolean;
|
|
12
|
-
picture_url: string | null;
|
|
13
|
-
is_superuser: boolean;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Response from POST /oauth/token (both grant types).
|
|
17
|
-
*
|
|
18
|
-
* Exactly one of access_token / admin_access_token is populated:
|
|
19
|
-
* - Regular users → access_token is set, admin_access_token is null.
|
|
20
|
-
* - Superusers → admin_access_token is set, access_token is null.
|
|
21
|
-
*/
|
|
22
|
-
export interface TokenResponse {
|
|
23
|
-
access_token: string | null;
|
|
24
|
-
admin_access_token: string | null;
|
|
25
|
-
refresh_token: string;
|
|
26
|
-
token_type: string;
|
|
27
|
-
expires_in: number;
|
|
28
|
-
user: UserInToken;
|
|
29
|
-
}
|
|
30
|
-
/** Returns whichever access token is present (regular or admin). */
|
|
31
|
-
export declare function effectiveAccessToken(token: TokenResponse): string | null;
|
|
32
6
|
/** Response from GET /auth/verify-token. */
|
|
33
7
|
export interface VerifyTokenResult {
|
|
34
8
|
valid: boolean;
|
|
@@ -48,12 +22,6 @@ export interface UserProfile {
|
|
|
48
22
|
created_at: string;
|
|
49
23
|
updated_at: string | null;
|
|
50
24
|
}
|
|
51
|
-
/** Response from POST /oauth/logout. */
|
|
52
|
-
export interface LogoutResult {
|
|
53
|
-
ok: boolean;
|
|
54
|
-
sessions_revoked: number;
|
|
55
|
-
products_notified: number;
|
|
56
|
-
}
|
|
57
25
|
/** Single entitlement entry from GET /users/me/entitlements. */
|
|
58
26
|
export interface EntitlementResponse {
|
|
59
27
|
product_id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/accounts/types.ts"],"names":[],"mappings":"AACA;;;;GAIG;AAIH,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/accounts/types.ts"],"names":[],"mappings":"AACA;;;;GAIG;AAIH,4CAA4C;AAC5C,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,QAAQ,GAAG,cAAc,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAID,mDAAmD;AACnD,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,YAAY,EAAE,OAAO,CAAC;IACtB,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAID,gEAAgE;AAChE,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACpB;AAID,wDAAwD;AACxD,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;CACrB"}
|
package/dist/accounts/types.js
CHANGED
|
@@ -6,9 +6,4 @@
|
|
|
6
6
|
* Mirror of the Python SDK's accounts/models.py — kept in sync manually.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.effectiveAccessToken = effectiveAccessToken;
|
|
10
|
-
/** Returns whichever access token is present (regular or admin). */
|
|
11
|
-
function effectiveAccessToken(token) {
|
|
12
|
-
return token.access_token ?? token.admin_access_token;
|
|
13
|
-
}
|
|
14
9
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/accounts/types.ts"],"names":[],"mappings":";AAAA,+BAA+B;AAC/B;;;;GAIG
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/accounts/types.ts"],"names":[],"mappings":";AAAA,+BAA+B;AAC/B;;;;GAIG"}
|
package/dist/client.d.ts
CHANGED
|
@@ -18,14 +18,11 @@
|
|
|
18
18
|
* paymentsAdminKey: "your-payments-admin-key", // optional
|
|
19
19
|
* });
|
|
20
20
|
*
|
|
21
|
-
* // OIDC callback handler (e.g. Express / Fastify route)
|
|
22
|
-
* const token = await client.accounts.exchangeCode(code, redirectUri);
|
|
23
|
-
*
|
|
24
21
|
* // Token verification middleware
|
|
25
22
|
* const result = await client.accounts.verifyToken(bearerToken);
|
|
26
23
|
*
|
|
27
24
|
* // Billing
|
|
28
|
-
* const customer = await client.payments.createCustomer(
|
|
25
|
+
* const customer = await client.payments.createCustomer(userId);
|
|
29
26
|
*/
|
|
30
27
|
import { AccountsNamespace } from "./accounts/namespace";
|
|
31
28
|
import { PaymentsNamespace } from "./payments/namespace";
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAkBzD,MAAM,WAAW,mBAAmB;IAClC,uEAAuE;IACvE,QAAQ,EAAE,MAAM,CAAC;IACjB,qFAAqF;IACrF,YAAY,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,YAAY;IACvB,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAC;IACrC,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAC;IAErC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAS;IAC9C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAgB;IACnD,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAgB;gBAEvC,OAAO,EAAE,mBAAmB;IAsBxC,0CAA0C;IAC1C,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,mDAAmD;IACnD,IAAI,mBAAmB,IAAI,MAAM,CAEhC;IAED,0CAA0C;IAC1C,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,QAAQ,IAAI,MAAM;CAGnB"}
|
package/dist/client.js
CHANGED
|
@@ -20,14 +20,11 @@
|
|
|
20
20
|
* paymentsAdminKey: "your-payments-admin-key", // optional
|
|
21
21
|
* });
|
|
22
22
|
*
|
|
23
|
-
* // OIDC callback handler (e.g. Express / Fastify route)
|
|
24
|
-
* const token = await client.accounts.exchangeCode(code, redirectUri);
|
|
25
|
-
*
|
|
26
23
|
* // Token verification middleware
|
|
27
24
|
* const result = await client.accounts.verifyToken(bearerToken);
|
|
28
25
|
*
|
|
29
26
|
* // Billing
|
|
30
|
-
* const customer = await client.payments.createCustomer(
|
|
27
|
+
* const customer = await client.payments.createCustomer(userId);
|
|
31
28
|
*/
|
|
32
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
30
|
exports.PpusshClient = void 0;
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";AAAA,uBAAuB;AACvB
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";AAAA,uBAAuB;AACvB;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;AAEH,oDAAyD;AACzD,iCAAuC;AACvC,oDAAyD;AAEzD,gFAAgF;AAChF,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AAC/C,MAAM,yBAAyB,GAAG,8BAA8B,CAAC;AACjE,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AAE/C,SAAS,UAAU,CAAC,KAAyB,EAAE,MAAc,EAAE,KAAa;IAC1E,IAAI,KAAK;QAAE,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC3C,MAAM,MAAM,GACV,OAAO,OAAO,KAAK,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACnE,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC7C,MAAM,IAAI,KAAK,CACb,GAAG,KAAK,oBAAoB;QAC1B,8CAA8C,MAAM,wBAAwB,CAC/E,CAAC;AACJ,CAAC;AA8BD,MAAa,YAAY;IAUvB,YAAY,OAA4B;QACtC,IAAI,CAAC,OAAO,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACtE,IAAI,CAAC,OAAO,CAAC,YAAY;YAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QAE9E,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,OAAO,CAAC,WAAW,EAAE,gBAAgB,EAAE,UAAU,CAAC,CAAC;QAClF,IAAI,CAAC,oBAAoB,GAAG,UAAU,CAAC,OAAO,CAAC,mBAAmB,EAAE,yBAAyB,EAAE,mBAAmB,CAAC,CAAA;QACnH,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,OAAO,CAAC,WAAW,EAAE,gBAAgB,EAAE,UAAU,CAAC,CAAC;QAClF,IAAI,CAAC,kBAAkB,GAAG,IAAI,oBAAa,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC/D,IAAI,CAAC,kBAAkB,GAAG,IAAI,oBAAa,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAE/D,IAAI,CAAC,QAAQ,GAAG,IAAI,6BAAiB,CAAC,IAAI,CAAC,kBAAkB,EAAE;YAC7D,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,WAAW,EAAE,IAAI,CAAC,YAAY;YAC9B,mBAAmB,EAAE,IAAI,CAAC,oBAAoB;SAC/C,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,GAAG,IAAI,6BAAiB,CAAC,IAAI,CAAC,kBAAkB,EAAE;YAC7D,UAAU,EAAE,OAAO,CAAC,kBAAkB;SACvC,CAAC,CAAC;IACL,CAAC;IAED,0CAA0C;IAC1C,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,mDAAmD;IACnD,IAAI,mBAAmB;QACrB,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACnC,CAAC;IAED,0CAA0C;IAC1C,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,QAAQ;QACN,OAAO,4BAA4B,IAAI,CAAC,YAAY,yBAAyB,IAAI,CAAC,oBAAoB,iBAAiB,IAAI,CAAC,YAAY,GAAG,CAAC;IAC9I,CAAC;CACF;AAlDD,oCAkDC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,20 +8,17 @@
|
|
|
8
8
|
* const client = new PpusshClient({
|
|
9
9
|
* clientId: "your-client-id",
|
|
10
10
|
* clientSecret: "your-client-secret",
|
|
11
|
-
*
|
|
11
|
+
* paymentsProductKey: "your-payments-product-key", // optional
|
|
12
12
|
* });
|
|
13
13
|
*
|
|
14
14
|
* // Build the login redirect URL
|
|
15
15
|
* const loginUrl = client.accounts.buildLoginUrl(redirectUri, state);
|
|
16
16
|
*
|
|
17
|
-
* // OIDC callback
|
|
18
|
-
* const token = await client.accounts.exchangeCode(code, redirectUri);
|
|
19
|
-
*
|
|
20
17
|
* // Middleware token check
|
|
21
18
|
* const result = await client.accounts.verifyToken(bearer);
|
|
22
19
|
*
|
|
23
20
|
* // Billing
|
|
24
|
-
* const customer = await client.payments.createCustomer(
|
|
21
|
+
* const customer = await client.payments.createCustomer(userId);
|
|
25
22
|
*
|
|
26
23
|
* All errors are subclasses of PpusshError:
|
|
27
24
|
*
|
|
@@ -39,9 +36,8 @@
|
|
|
39
36
|
export { PpusshClient } from "./client";
|
|
40
37
|
export type { PpusshClientOptions } from "./client";
|
|
41
38
|
export { PpusshAuthError, PpusshConsentRequired, PpusshError, PpusshNetworkError, PpusshPaymentError, } from "./errors";
|
|
42
|
-
export type { EntitlementResponse,
|
|
43
|
-
export {
|
|
44
|
-
export type { CustomerCreateRequest, CustomerResponse, MRRByPlan, MRRByProduct, MRRResponse, PaymentProductResponse, PlanResponse, SubscriptionCancelRequest, SubscriptionCreateRequest, SubscriptionListResponse, SubscriptionResponse, SubscriptionStatus, } from "./payments/types";
|
|
39
|
+
export type { EntitlementResponse, SessionResponse, UserProfile, VerifyTokenResult, } from "./accounts/types";
|
|
40
|
+
export type { AccessResult, CustomerCreateRequest, CustomerResponse, MRRByPlan, MRRByProduct, MRRResponse, PaymentProductResponse, PlanResponse, SubscriptionCancelRequest, SubscriptionCreateRequest, SubscriptionListResponse, SubscriptionResponse, SubscriptionStatus, } from "./payments/types";
|
|
45
41
|
export { verifyWebhook } from "./webhooks";
|
|
46
42
|
export type { WebhookEvent, WebhookEventType } from "./webhooks";
|
|
47
43
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,YAAY,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAGpD,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,WAAW,EACX,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,UAAU,CAAC;AAGlB,YAAY,EACV,mBAAmB,EACnB,eAAe,EACf,WAAW,EACX,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAG1B,YAAY,EACV,YAAY,EACZ,qBAAqB,EACrB,gBAAgB,EAChB,SAAS,EACT,YAAY,EACZ,WAAW,EACX,sBAAsB,EACtB,YAAY,EACZ,yBAAyB,EACzB,yBAAyB,EACzB,wBAAwB,EACxB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -10,20 +10,17 @@
|
|
|
10
10
|
* const client = new PpusshClient({
|
|
11
11
|
* clientId: "your-client-id",
|
|
12
12
|
* clientSecret: "your-client-secret",
|
|
13
|
-
*
|
|
13
|
+
* paymentsProductKey: "your-payments-product-key", // optional
|
|
14
14
|
* });
|
|
15
15
|
*
|
|
16
16
|
* // Build the login redirect URL
|
|
17
17
|
* const loginUrl = client.accounts.buildLoginUrl(redirectUri, state);
|
|
18
18
|
*
|
|
19
|
-
* // OIDC callback
|
|
20
|
-
* const token = await client.accounts.exchangeCode(code, redirectUri);
|
|
21
|
-
*
|
|
22
19
|
* // Middleware token check
|
|
23
20
|
* const result = await client.accounts.verifyToken(bearer);
|
|
24
21
|
*
|
|
25
22
|
* // Billing
|
|
26
|
-
* const customer = await client.payments.createCustomer(
|
|
23
|
+
* const customer = await client.payments.createCustomer(userId);
|
|
27
24
|
*
|
|
28
25
|
* All errors are subclasses of PpusshError:
|
|
29
26
|
*
|
|
@@ -39,7 +36,7 @@
|
|
|
39
36
|
* const event: WebhookEvent = JSON.parse(rawBody);
|
|
40
37
|
*/
|
|
41
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.verifyWebhook = exports.
|
|
39
|
+
exports.verifyWebhook = exports.PpusshPaymentError = exports.PpusshNetworkError = exports.PpusshError = exports.PpusshConsentRequired = exports.PpusshAuthError = exports.PpusshClient = void 0;
|
|
43
40
|
// ── Client ───────────────────────────────────────────────────────────────────
|
|
44
41
|
var client_1 = require("./client");
|
|
45
42
|
Object.defineProperty(exports, "PpusshClient", { enumerable: true, get: function () { return client_1.PpusshClient; } });
|
|
@@ -50,8 +47,6 @@ Object.defineProperty(exports, "PpusshConsentRequired", { enumerable: true, get:
|
|
|
50
47
|
Object.defineProperty(exports, "PpusshError", { enumerable: true, get: function () { return errors_1.PpusshError; } });
|
|
51
48
|
Object.defineProperty(exports, "PpusshNetworkError", { enumerable: true, get: function () { return errors_1.PpusshNetworkError; } });
|
|
52
49
|
Object.defineProperty(exports, "PpusshPaymentError", { enumerable: true, get: function () { return errors_1.PpusshPaymentError; } });
|
|
53
|
-
var types_1 = require("./accounts/types");
|
|
54
|
-
Object.defineProperty(exports, "effectiveAccessToken", { enumerable: true, get: function () { return types_1.effectiveAccessToken; } });
|
|
55
50
|
// ── Webhooks ──────────────────────────────────────────────────────────────────
|
|
56
51
|
var webhooks_1 = require("./webhooks");
|
|
57
52
|
Object.defineProperty(exports, "verifyWebhook", { enumerable: true, get: function () { return webhooks_1.verifyWebhook; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,sBAAsB;AACtB
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,sBAAsB;AACtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;;;AAEH,gFAAgF;AAChF,mCAAwC;AAA/B,sGAAA,YAAY,OAAA;AAGrB,gFAAgF;AAChF,mCAMkB;AALhB,yGAAA,eAAe,OAAA;AACf,+GAAA,qBAAqB,OAAA;AACrB,qGAAA,WAAW,OAAA;AACX,4GAAA,kBAAkB,OAAA;AAClB,4GAAA,kBAAkB,OAAA;AA4BpB,iFAAiF;AACjF,uCAA2C;AAAlC,yGAAA,aAAa,OAAA"}
|