@pisti-paypiller/backend 0.0.0-stage → 0.7.1
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/LICENSE +21 -0
- package/README.md +133 -2
- package/dist/errors.d.ts +6 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +11 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/keys.d.ts +12 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/keys.js +45 -0
- package/dist/keys.js.map +1 -0
- package/dist/management-types.d.ts +311 -0
- package/dist/management-types.d.ts.map +1 -0
- package/dist/management-types.js +2 -0
- package/dist/management-types.js.map +1 -0
- package/dist/management.d.ts +162 -0
- package/dist/management.d.ts.map +1 -0
- package/dist/management.js +432 -0
- package/dist/management.js.map +1 -0
- package/dist/tokens.d.ts +43 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +458 -0
- package/dist/tokens.js.map +1 -0
- package/dist/types.d.ts +170 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/webhooks.d.ts +94 -0
- package/dist/webhooks.d.ts.map +1 -0
- package/dist/webhooks.js +117 -0
- package/dist/webhooks.js.map +1 -0
- package/package.json +43 -4
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import type { AcceptsToken, AuthenticateRequestOptions, AuthObjectFor, RequestState, SessionClaims, VerifyTokenOptions } from "./types.js";
|
|
2
|
+
import type { ManagementClientOptions, ManagementRequestOptions, ManagedInstance, ManagementListOptions, ManagementPage, User, EmailAddress, CreateUserInput, UpdateUserInput, UserStatus, DirectoryExternalAccount, Session, SessionListOptions, ApiKey, ApiKeyListOptions, UpdateApiKeyInput, Metadata, ManagedOrganization, CreateOrganizationInput, UpdateOrganizationInput, ManagedOrganizationMember, ManagedInvitation, InvitationResult, ManagedRole, RoleInput, ManagedPermission, DeletionBlocker, ManagedExternalProvider, CreateExternalProviderInput, UpdateExternalProviderInput, WebhookEndpointInput, UpdateWebhookEndpointInput, ManagedWebhookEndpoint, WebhookSecretResult, WebhookEventType, WebhookDeliveryListOptions, ManagedWebhookDelivery, WebhookDeliveryDetails } from "./management-types.js";
|
|
3
|
+
export type * from "./management-types.js";
|
|
4
|
+
/** Structured service failure. No credentials or raw requests are retained. */
|
|
5
|
+
export declare class PistiManagementError extends Error {
|
|
6
|
+
readonly status: number;
|
|
7
|
+
readonly requestId: string | null;
|
|
8
|
+
readonly code: string | null;
|
|
9
|
+
readonly retryAfterSeconds: number | null;
|
|
10
|
+
readonly fieldErrors: Readonly<Record<string, string[]>>;
|
|
11
|
+
readonly blockers: readonly DeletionBlocker[];
|
|
12
|
+
constructor(message: string, status: number, requestId?: string | null, code?: string | null, retryAfterSeconds?: number | null, fieldErrors?: Readonly<Record<string, string[]>>, blockers?: readonly DeletionBlocker[]);
|
|
13
|
+
}
|
|
14
|
+
type RequestResource = <T>(method: string, path: string, body?: unknown, options?: ManagementRequestOptions) => Promise<T>;
|
|
15
|
+
/** Server-side client for one environment: request authentication and the management API. */
|
|
16
|
+
export declare class PistiClient {
|
|
17
|
+
#private;
|
|
18
|
+
readonly users: ManagementUsers;
|
|
19
|
+
readonly organizations: ManagementOrganizations;
|
|
20
|
+
readonly sessions: ManagementSessions;
|
|
21
|
+
readonly externalProviders: ManagementExternalProviders;
|
|
22
|
+
readonly webhooks: ManagementWebhooks;
|
|
23
|
+
readonly apiKeys: ManagementApiKeys;
|
|
24
|
+
constructor(options?: ManagementClientOptions);
|
|
25
|
+
/**
|
|
26
|
+
* Authenticates a Fetch API `Request` using this client's publishable key. Never throws for a
|
|
27
|
+
* missing or bad token; check `isAuthenticated` and call `toAuth()`.
|
|
28
|
+
*/
|
|
29
|
+
authenticateRequest<T extends AcceptsToken = "session_token">(request: Request, options?: AuthenticateRequestOptions & {
|
|
30
|
+
acceptsToken?: T;
|
|
31
|
+
}): Promise<RequestState<AuthObjectFor<T>>>;
|
|
32
|
+
/** Verifies a session token and returns its claims. */
|
|
33
|
+
verifyToken(token: string, options?: VerifyTokenOptions): Promise<SessionClaims>;
|
|
34
|
+
/** The environment the secret key belongs to. */
|
|
35
|
+
getInstance(options?: ManagementRequestOptions): Promise<ManagedInstance>;
|
|
36
|
+
}
|
|
37
|
+
export declare class ManagementUsers {
|
|
38
|
+
private readonly request;
|
|
39
|
+
constructor(request: RequestResource);
|
|
40
|
+
getUserList: (options?: ManagementListOptions & {
|
|
41
|
+
status?: UserStatus;
|
|
42
|
+
}) => Promise<ManagementPage<User>>;
|
|
43
|
+
getUserListAll(options?: Omit<ManagementListOptions, "cursor"> & {
|
|
44
|
+
status?: UserStatus;
|
|
45
|
+
}): AsyncGenerator<User>;
|
|
46
|
+
/** The number of users matching `search` and `status`. */
|
|
47
|
+
getCount: (options?: Omit<ManagementListOptions, "cursor" | "limit"> & {
|
|
48
|
+
status?: UserStatus;
|
|
49
|
+
}) => Promise<number>;
|
|
50
|
+
getUser: (id: string, options?: ManagementRequestOptions) => Promise<User>;
|
|
51
|
+
createUser: (input: CreateUserInput, options?: ManagementRequestOptions) => Promise<User>;
|
|
52
|
+
updateUser: (id: string, input: UpdateUserInput, options?: ManagementRequestOptions) => Promise<void>;
|
|
53
|
+
private setStatus;
|
|
54
|
+
/** Disables the account and ends its sessions. */
|
|
55
|
+
banUser: (id: string, options?: ManagementRequestOptions) => Promise<void>;
|
|
56
|
+
unbanUser: (id: string, options?: ManagementRequestOptions) => Promise<void>;
|
|
57
|
+
lockUser: (id: string, options?: ManagementRequestOptions) => Promise<void>;
|
|
58
|
+
unlockUser: (id: string, options?: ManagementRequestOptions) => Promise<void>;
|
|
59
|
+
deleteUser: (id: string, options?: ManagementRequestOptions) => Promise<void>;
|
|
60
|
+
getUserEmailAddressList: (id: string, options?: ManagementRequestOptions) => Promise<EmailAddress[]>;
|
|
61
|
+
addEmailAddress: (id: string, input: {
|
|
62
|
+
email: string;
|
|
63
|
+
status: "verified" | "unverified";
|
|
64
|
+
isPrimary?: boolean;
|
|
65
|
+
verificationReason?: string;
|
|
66
|
+
}, options?: ManagementRequestOptions) => Promise<{
|
|
67
|
+
id: string;
|
|
68
|
+
}>;
|
|
69
|
+
setEmailVerification: (id: string, emailId: string, status: "verified" | "unverified", options?: ManagementRequestOptions & {
|
|
70
|
+
verificationReason?: string;
|
|
71
|
+
}) => Promise<void>;
|
|
72
|
+
setPrimaryEmail: (id: string, emailId: string, options?: ManagementRequestOptions) => Promise<void>;
|
|
73
|
+
removeEmailAddress: (id: string, emailId: string, options?: ManagementRequestOptions) => Promise<void>;
|
|
74
|
+
getUserExternalAccountList: (id: string, options?: ManagementRequestOptions) => Promise<DirectoryExternalAccount[]>;
|
|
75
|
+
}
|
|
76
|
+
export declare class ManagementExternalProviders {
|
|
77
|
+
private readonly request;
|
|
78
|
+
constructor(request: RequestResource);
|
|
79
|
+
list: (options?: ManagementRequestOptions) => Promise<ManagedExternalProvider[]>;
|
|
80
|
+
create: (input: CreateExternalProviderInput, options?: ManagementRequestOptions) => Promise<ManagedExternalProvider>;
|
|
81
|
+
update: (id: string, input: UpdateExternalProviderInput, options?: ManagementRequestOptions) => Promise<ManagedExternalProvider>;
|
|
82
|
+
delete: (id: string, options?: ManagementRequestOptions) => Promise<void>;
|
|
83
|
+
}
|
|
84
|
+
export declare class ManagementWebhooks {
|
|
85
|
+
private readonly request;
|
|
86
|
+
constructor(request: RequestResource);
|
|
87
|
+
catalog: (options?: ManagementRequestOptions) => Promise<WebhookEventType[]>;
|
|
88
|
+
endpoints: (options?: ManagementRequestOptions) => Promise<ManagedWebhookEndpoint[]>;
|
|
89
|
+
createEndpoint: (input: WebhookEndpointInput, options?: ManagementRequestOptions) => Promise<WebhookSecretResult>;
|
|
90
|
+
updateEndpoint: (id: string, input: UpdateWebhookEndpointInput, options?: ManagementRequestOptions) => Promise<ManagedWebhookEndpoint>;
|
|
91
|
+
archiveEndpoint: (id: string, expectedUpdatedAt: string, options?: ManagementRequestOptions) => Promise<void>;
|
|
92
|
+
rotateSecret: (id: string, expectedUpdatedAt: string, options?: ManagementRequestOptions) => Promise<WebhookSecretResult>;
|
|
93
|
+
sendTest: (id: string, options?: ManagementRequestOptions) => Promise<{
|
|
94
|
+
id: string;
|
|
95
|
+
eventId: string;
|
|
96
|
+
}>;
|
|
97
|
+
deliveries: (options?: WebhookDeliveryListOptions) => Promise<ManagementPage<ManagedWebhookDelivery>>;
|
|
98
|
+
delivery: (id: string, options?: ManagementRequestOptions) => Promise<WebhookDeliveryDetails>;
|
|
99
|
+
replay: (id: string, options?: ManagementRequestOptions) => Promise<void>;
|
|
100
|
+
}
|
|
101
|
+
export declare class ManagementApiKeys {
|
|
102
|
+
private readonly request;
|
|
103
|
+
constructor(request: RequestResource);
|
|
104
|
+
getApiKeyList: (options?: ApiKeyListOptions) => Promise<ManagementPage<ApiKey>>;
|
|
105
|
+
getApiKey: (id: string, options?: ManagementRequestOptions) => Promise<ApiKey>;
|
|
106
|
+
/** Sets what a key may do in your API. Only your backend grants scopes and claims; the key's owner cannot. */
|
|
107
|
+
updateApiKey: (id: string, input: UpdateApiKeyInput, options?: ManagementRequestOptions) => Promise<ApiKey>;
|
|
108
|
+
revokeApiKey: (id: string, options?: ManagementRequestOptions & {
|
|
109
|
+
revocationReason?: string;
|
|
110
|
+
}) => Promise<void>;
|
|
111
|
+
/** Verifies a presented `ak_` secret. Throws `PistiManagementError` (401) for unknown, expired or revoked keys. */
|
|
112
|
+
verifySecret: (secret: string, options?: ManagementRequestOptions) => Promise<ApiKey>;
|
|
113
|
+
}
|
|
114
|
+
export declare class ManagementSessions {
|
|
115
|
+
private readonly request;
|
|
116
|
+
constructor(request: RequestResource);
|
|
117
|
+
/** Sessions in the environment, newest first. Filter by `userId` and `status`. */
|
|
118
|
+
getSessionList: (options?: SessionListOptions) => Promise<ManagementPage<Session>>;
|
|
119
|
+
getSession: (id: string, options?: ManagementRequestOptions) => Promise<Session>;
|
|
120
|
+
revokeSession: (id: string, options?: ManagementRequestOptions) => Promise<void>;
|
|
121
|
+
}
|
|
122
|
+
export declare class ManagementOrganizations {
|
|
123
|
+
private readonly request;
|
|
124
|
+
constructor(request: RequestResource);
|
|
125
|
+
getOrganizationList: (options?: ManagementListOptions) => Promise<ManagementPage<ManagedOrganization>>;
|
|
126
|
+
getOrganization: (id: string, options?: ManagementRequestOptions) => Promise<{
|
|
127
|
+
organization: ManagedOrganization;
|
|
128
|
+
privateMetadata: Metadata;
|
|
129
|
+
}>;
|
|
130
|
+
createOrganization: (input: CreateOrganizationInput, options?: ManagementRequestOptions) => Promise<{
|
|
131
|
+
id: string;
|
|
132
|
+
}>;
|
|
133
|
+
updateOrganization: (id: string, input: UpdateOrganizationInput, options?: ManagementRequestOptions) => Promise<void>;
|
|
134
|
+
deleteOrganization: (id: string, options?: ManagementRequestOptions) => Promise<void>;
|
|
135
|
+
getOrganizationMembershipList: (id: string, options?: ManagementListOptions) => Promise<ManagementPage<ManagedOrganizationMember>>;
|
|
136
|
+
updateOrganizationMembership: (id: string, memberId: string, roleId: string, options?: ManagementRequestOptions) => Promise<void>;
|
|
137
|
+
deleteOrganizationMembership: (id: string, memberId: string, options?: ManagementRequestOptions) => Promise<void>;
|
|
138
|
+
getOrganizationInvitationList: (id: string, options?: ManagementListOptions) => Promise<ManagementPage<ManagedInvitation>>;
|
|
139
|
+
createOrganizationInvitation: (id: string, input: {
|
|
140
|
+
email: string;
|
|
141
|
+
roleId: string;
|
|
142
|
+
lifetimeDays?: number;
|
|
143
|
+
}, options?: ManagementRequestOptions) => Promise<InvitationResult>;
|
|
144
|
+
reissueOrganizationInvitation: (id: string, invitationId: string, input: {
|
|
145
|
+
expectedExpiresAt: string;
|
|
146
|
+
lifetimeDays?: number;
|
|
147
|
+
}, options?: ManagementRequestOptions) => Promise<InvitationResult>;
|
|
148
|
+
revokeOrganizationInvitation: (id: string, invitationId: string, options?: ManagementRequestOptions) => Promise<void>;
|
|
149
|
+
getRoleList: (id: string, options?: ManagementRequestOptions) => Promise<ManagedRole[]>;
|
|
150
|
+
createRole: (id: string, input: RoleInput, options?: ManagementRequestOptions) => Promise<{
|
|
151
|
+
id: string;
|
|
152
|
+
}>;
|
|
153
|
+
updateRole: (id: string, roleId: string, input: RoleInput, options?: ManagementRequestOptions) => Promise<void>;
|
|
154
|
+
deleteRole: (id: string, roleId: string, options?: ManagementRequestOptions) => Promise<void>;
|
|
155
|
+
getPermissionList: (options?: ManagementRequestOptions) => Promise<ManagedPermission[]>;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Creates a backend client, like Clerk's `createClerkClient`. Without options it reads
|
|
159
|
+
* `PISTI_PUBLISHABLE_KEY`, `PISTI_SECRET_KEY` and `PISTI_AUTHORIZED_PARTIES`.
|
|
160
|
+
*/
|
|
161
|
+
export declare function createPistiClient(options?: ManagementClientOptions): PistiClient;
|
|
162
|
+
//# sourceMappingURL=management.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"management.d.ts","sourceRoot":"","sources":["../src/management.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,0BAA0B,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAC3I,OAAO,KAAK,EACR,uBAAuB,EACvB,wBAAwB,EACxB,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,IAAI,EACJ,YAAY,EACZ,eAAe,EACf,eAAe,EACf,UAAU,EACV,wBAAwB,EACxB,OAAO,EACP,kBAAkB,EAClB,MAAM,EACN,iBAAiB,EACjB,iBAAiB,EACjB,QAAQ,EACR,mBAAmB,EACnB,uBAAuB,EACvB,uBAAuB,EACvB,yBAAyB,EACzB,iBAAiB,EACjB,gBAAgB,EAChB,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,eAAe,EACf,uBAAuB,EACvB,2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AE,YACjD,wBAAwB,KACnC,OAAO,CAAC,gBAAgB,CAAC,CAMtB;IACN,4BAA4B,OACpB,MAAM,gBACI,MAAM,YACV,wBAAwB,KACnC,OAAO,CAAC,IAAI,CAAC,CAMV;IACN,WAAW,OACH,MAAM,YACA,wBAAwB,KACnC,OAAO,CAAC,WAAW,EAAE,CAAC,CAMnB;IACN,UAAU,OACF,MAAM,SACH,SAAS,YACN,wBAAwB,KACnC,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAMpB;IACN,UAAU,OACF,MAAM,UACF,MAAM,SACP,SAAS,YACN,wBAAwB,KACnC,OAAO,CAAC,IAAI,CAAC,CAMV;IACN,UAAU,OACF,MAAM,UACF,MAAM,YACJ,wBAAwB,KACnC,OAAO,CAAC,IAAI,CAAC,CAMV;IACN,iBAAiB,aACH,wBAAwB,KACnC,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAC6B;CAC/D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,CAAC,EAAE,uBAAuB,GAAG,WAAW,CAEhF"}
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
import { parsePublishableKey } from "./keys.js";
|
|
2
|
+
import { authenticateRequest, verifyToken } from "./tokens.js";
|
|
3
|
+
/** Structured service failure. No credentials or raw requests are retained. */
|
|
4
|
+
export class PistiManagementError extends Error {
|
|
5
|
+
status;
|
|
6
|
+
requestId;
|
|
7
|
+
code;
|
|
8
|
+
retryAfterSeconds;
|
|
9
|
+
fieldErrors;
|
|
10
|
+
blockers;
|
|
11
|
+
constructor(message, status, requestId = null, code = null, retryAfterSeconds = null, fieldErrors = {}, blockers = []) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.status = status;
|
|
14
|
+
this.requestId = requestId;
|
|
15
|
+
this.code = code;
|
|
16
|
+
this.retryAfterSeconds = retryAfterSeconds;
|
|
17
|
+
this.fieldErrors = fieldErrors;
|
|
18
|
+
this.blockers = blockers;
|
|
19
|
+
this.name = "PistiManagementError";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function integerId(value) {
|
|
23
|
+
if (!/^[1-9]\d{0,9}$/.test(value) || Number(value) > 2_147_483_647)
|
|
24
|
+
throw new Error("Provide a positive resource ID.");
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
function sessionId(value) {
|
|
28
|
+
if (!/^[1-9]\d{0,18}$/.test(value) ||
|
|
29
|
+
BigInt(value) > 9223372036854775807n)
|
|
30
|
+
throw new Error("Provide a valid session ID.");
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
function userId(value) {
|
|
34
|
+
if (!/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(value))
|
|
35
|
+
throw new Error("Provide a valid user ID.");
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
function listQuery(options = {}) {
|
|
39
|
+
const query = new URLSearchParams({ paged: "true" });
|
|
40
|
+
if (options.limit !== undefined) {
|
|
41
|
+
if (!Number.isInteger(options.limit) ||
|
|
42
|
+
options.limit < 1 ||
|
|
43
|
+
options.limit > 100)
|
|
44
|
+
throw new Error("Use a page limit between 1 and 100.");
|
|
45
|
+
query.set("limit", String(options.limit));
|
|
46
|
+
}
|
|
47
|
+
if (options.cursor !== undefined) {
|
|
48
|
+
if (options.cursor.length > 128)
|
|
49
|
+
throw new Error("The pagination cursor is too long.");
|
|
50
|
+
query.set("cursor", options.cursor);
|
|
51
|
+
}
|
|
52
|
+
if (options.search !== undefined) {
|
|
53
|
+
if (options.search.length > 200)
|
|
54
|
+
throw new Error("Search must be at most 200 characters.");
|
|
55
|
+
query.set("search", options.search);
|
|
56
|
+
}
|
|
57
|
+
if (options.status !== undefined)
|
|
58
|
+
query.set("status", options.status);
|
|
59
|
+
return "?" + query;
|
|
60
|
+
}
|
|
61
|
+
async function readJson(response) {
|
|
62
|
+
const reader = response.body?.getReader();
|
|
63
|
+
if (!reader)
|
|
64
|
+
return null;
|
|
65
|
+
const chunks = [];
|
|
66
|
+
let length = 0;
|
|
67
|
+
try {
|
|
68
|
+
while (true) {
|
|
69
|
+
const part = await reader.read();
|
|
70
|
+
if (part.done)
|
|
71
|
+
break;
|
|
72
|
+
length += part.value.byteLength;
|
|
73
|
+
if (length > 1_048_576) {
|
|
74
|
+
await reader.cancel();
|
|
75
|
+
throw new PistiManagementError("The service response is too large.", 502);
|
|
76
|
+
}
|
|
77
|
+
chunks.push(part.value);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
reader.releaseLock();
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
return JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function object(value) {
|
|
91
|
+
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
92
|
+
? value
|
|
93
|
+
: null;
|
|
94
|
+
}
|
|
95
|
+
/** Server-side client for one environment: request authentication and the management API. */
|
|
96
|
+
export class PistiClient {
|
|
97
|
+
#issuer;
|
|
98
|
+
#secretKey;
|
|
99
|
+
#publishableKey;
|
|
100
|
+
#authorizedParties;
|
|
101
|
+
#basePath;
|
|
102
|
+
#timeoutMs;
|
|
103
|
+
users;
|
|
104
|
+
organizations;
|
|
105
|
+
sessions;
|
|
106
|
+
externalProviders;
|
|
107
|
+
webhooks;
|
|
108
|
+
apiKeys;
|
|
109
|
+
constructor(options = {}) {
|
|
110
|
+
if (typeof window !== "undefined" && typeof document !== "undefined")
|
|
111
|
+
throw new Error("The Pisti backend client belongs only in your server environment.");
|
|
112
|
+
const secretKey = options.secretKey ?? process.env.PISTI_SECRET_KEY;
|
|
113
|
+
const publishableKey = options.publishableKey ?? process.env.PISTI_PUBLISHABLE_KEY;
|
|
114
|
+
if (!publishableKey)
|
|
115
|
+
throw new Error("Missing Pisti publishable key. Set PISTI_PUBLISHABLE_KEY (copy it from your application's Home page in the Pisti console) or pass { publishableKey }.");
|
|
116
|
+
const key = parsePublishableKey(publishableKey);
|
|
117
|
+
if (secretKey !== undefined) {
|
|
118
|
+
if (!/^sk_(?:test|live)_[a-f0-9]{16}\.[a-f0-9]{64}$/.test(secretKey))
|
|
119
|
+
throw new Error("PISTI_SECRET_KEY doesn’t look like a Pisti secret key (sk_test_… or sk_live_…).");
|
|
120
|
+
if ((key.environment === "live") !== secretKey.startsWith("sk_live_"))
|
|
121
|
+
throw new Error("The secret key and publishable key belong to different environments.");
|
|
122
|
+
if (key.issuer.protocol === "http:" && secretKey.startsWith("sk_live_"))
|
|
123
|
+
throw new Error("Production credentials require HTTPS.");
|
|
124
|
+
}
|
|
125
|
+
this.#issuer = key.issuer;
|
|
126
|
+
this.#secretKey = secretKey;
|
|
127
|
+
this.#publishableKey = publishableKey;
|
|
128
|
+
this.#authorizedParties = options.authorizedParties;
|
|
129
|
+
this.#timeoutMs = options.timeoutMs ?? 10_000;
|
|
130
|
+
if (!Number.isInteger(this.#timeoutMs) ||
|
|
131
|
+
this.#timeoutMs < 1000 ||
|
|
132
|
+
this.#timeoutMs > 60_000)
|
|
133
|
+
throw new Error("Use a timeout between 1000 and 60000 milliseconds.");
|
|
134
|
+
const request = async (method, path, body, requestOptions) => this.#request(method, (await this.#instancePath()) + path, body, requestOptions);
|
|
135
|
+
this.users = new ManagementUsers(request);
|
|
136
|
+
this.organizations = new ManagementOrganizations(request);
|
|
137
|
+
this.sessions = new ManagementSessions(request);
|
|
138
|
+
this.externalProviders = new ManagementExternalProviders(request);
|
|
139
|
+
this.webhooks = new ManagementWebhooks(request);
|
|
140
|
+
this.apiKeys = new ManagementApiKeys(request);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Authenticates a Fetch API `Request` using this client's publishable key. Never throws for a
|
|
144
|
+
* missing or bad token; check `isAuthenticated` and call `toAuth()`.
|
|
145
|
+
*/
|
|
146
|
+
authenticateRequest(request, options = {}) {
|
|
147
|
+
return authenticateRequest(request, {
|
|
148
|
+
publishableKey: this.#publishableKey,
|
|
149
|
+
...(this.#secretKey ? { secretKey: this.#secretKey } : {}),
|
|
150
|
+
...(this.#authorizedParties ? { authorizedParties: this.#authorizedParties } : {}),
|
|
151
|
+
...options,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
/** Verifies a session token and returns its claims. */
|
|
155
|
+
verifyToken(token, options = {}) {
|
|
156
|
+
return verifyToken(token, {
|
|
157
|
+
publishableKey: this.#publishableKey,
|
|
158
|
+
...(this.#authorizedParties ? { authorizedParties: this.#authorizedParties } : {}),
|
|
159
|
+
...options,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
/** The environment the secret key belongs to. */
|
|
163
|
+
getInstance(options = {}) {
|
|
164
|
+
return this.#request("GET", "/v1/instance", undefined, options);
|
|
165
|
+
}
|
|
166
|
+
#requireSecretKey() {
|
|
167
|
+
if (!this.#secretKey)
|
|
168
|
+
throw new Error("Missing Pisti secret key. Create one under API keys in the Pisti console and set PISTI_SECRET_KEY, or pass { secretKey }.");
|
|
169
|
+
return this.#secretKey;
|
|
170
|
+
}
|
|
171
|
+
// The secret key identifies its environment; resolve the management path from it once.
|
|
172
|
+
#instancePath() {
|
|
173
|
+
return (this.#basePath ??= this.getInstance()
|
|
174
|
+
.then((instance) => `/v1/management/instances/${integerId(instance.id)}`)
|
|
175
|
+
.catch((error) => {
|
|
176
|
+
this.#basePath = undefined;
|
|
177
|
+
throw error;
|
|
178
|
+
}));
|
|
179
|
+
}
|
|
180
|
+
async #request(method, path, body, options = {}) {
|
|
181
|
+
const serialized = body === undefined ? undefined : JSON.stringify(body);
|
|
182
|
+
if (serialized && Buffer.byteLength(serialized) > 65_536)
|
|
183
|
+
throw new Error("The management request exceeds 64 KiB.");
|
|
184
|
+
let response;
|
|
185
|
+
let payload;
|
|
186
|
+
const timeout = AbortSignal.timeout(this.#timeoutMs);
|
|
187
|
+
try {
|
|
188
|
+
response = await fetch(new URL(path.slice(1), this.#issuer), {
|
|
189
|
+
method,
|
|
190
|
+
headers: {
|
|
191
|
+
Authorization: "Bearer " + this.#requireSecretKey(),
|
|
192
|
+
Accept: "application/json",
|
|
193
|
+
...(serialized === undefined
|
|
194
|
+
? {}
|
|
195
|
+
: { "Content-Type": "application/json" }),
|
|
196
|
+
},
|
|
197
|
+
...(serialized === undefined ? {} : { body: serialized }),
|
|
198
|
+
signal: options.signal
|
|
199
|
+
? AbortSignal.any([timeout, options.signal])
|
|
200
|
+
: timeout,
|
|
201
|
+
redirect: "error",
|
|
202
|
+
});
|
|
203
|
+
if (response.status === 204)
|
|
204
|
+
return undefined;
|
|
205
|
+
payload = await readJson(response);
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
if (error instanceof PistiManagementError)
|
|
209
|
+
throw error;
|
|
210
|
+
throw new PistiManagementError(options.signal?.aborted
|
|
211
|
+
? "The management request was canceled."
|
|
212
|
+
: "The management service could not be reached. Try again shortly.", 0, null, options.signal?.aborted
|
|
213
|
+
? "request_cancelled"
|
|
214
|
+
: timeout.aborted
|
|
215
|
+
? "request_timeout"
|
|
216
|
+
: "service_unavailable");
|
|
217
|
+
}
|
|
218
|
+
const value = object(payload);
|
|
219
|
+
const meta = object(value?.meta);
|
|
220
|
+
const requestId = typeof value?.requestId === "string"
|
|
221
|
+
? value.requestId
|
|
222
|
+
: typeof meta?.requestId === "string"
|
|
223
|
+
? meta.requestId
|
|
224
|
+
: response.headers.get("X-Request-ID");
|
|
225
|
+
if (!response.ok) {
|
|
226
|
+
const fields = Object.create(null);
|
|
227
|
+
for (const [name, messages] of Object.entries(object(value?.errors) ?? {}))
|
|
228
|
+
if (Array.isArray(messages))
|
|
229
|
+
fields[name] = messages.filter((message) => typeof message === "string");
|
|
230
|
+
const blockers = Array.isArray(value?.blockers)
|
|
231
|
+
? value.blockers.flatMap((item) => {
|
|
232
|
+
const blocker = object(item);
|
|
233
|
+
return blocker &&
|
|
234
|
+
typeof blocker.resource === "string" &&
|
|
235
|
+
typeof blocker.count === "number" &&
|
|
236
|
+
typeof blocker.resolution === "string"
|
|
237
|
+
? [
|
|
238
|
+
{
|
|
239
|
+
resource: blocker.resource,
|
|
240
|
+
count: blocker.count,
|
|
241
|
+
resolution: blocker.resolution,
|
|
242
|
+
},
|
|
243
|
+
]
|
|
244
|
+
: [];
|
|
245
|
+
})
|
|
246
|
+
: [];
|
|
247
|
+
const retry = response.headers.get("Retry-After");
|
|
248
|
+
const retrySeconds = retry && /^\d{1,10}$/.test(retry) ? Number(retry) : null;
|
|
249
|
+
throw new PistiManagementError(typeof value?.detail === "string"
|
|
250
|
+
? value.detail
|
|
251
|
+
: typeof value?.title === "string"
|
|
252
|
+
? value.title
|
|
253
|
+
: "The management request failed.", response.status, requestId, typeof value?.code === "string" ? value.code : null, retrySeconds, fields, blockers);
|
|
254
|
+
}
|
|
255
|
+
if (!value ||
|
|
256
|
+
!("data" in value) ||
|
|
257
|
+
!meta ||
|
|
258
|
+
typeof meta.requestId !== "string")
|
|
259
|
+
throw new PistiManagementError("The management service returned an invalid response.", 502, requestId);
|
|
260
|
+
return value.data;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
export class ManagementUsers {
|
|
264
|
+
request;
|
|
265
|
+
constructor(request) {
|
|
266
|
+
this.request = request;
|
|
267
|
+
}
|
|
268
|
+
getUserList = (options = {}) => this.request("GET", "/users" + listQuery(options), undefined, options);
|
|
269
|
+
async *getUserListAll(options = {}) {
|
|
270
|
+
let cursor;
|
|
271
|
+
const seen = new Set();
|
|
272
|
+
do {
|
|
273
|
+
const page = await this.getUserList({
|
|
274
|
+
...options,
|
|
275
|
+
...(cursor ? { cursor } : {}),
|
|
276
|
+
});
|
|
277
|
+
for (const user of page.items)
|
|
278
|
+
yield user;
|
|
279
|
+
if (!page.hasMore)
|
|
280
|
+
return;
|
|
281
|
+
if (!page.nextCursor || seen.has(page.nextCursor))
|
|
282
|
+
throw new PistiManagementError("The service returned an invalid pagination cursor.", 502);
|
|
283
|
+
cursor = page.nextCursor;
|
|
284
|
+
seen.add(cursor);
|
|
285
|
+
} while (true);
|
|
286
|
+
}
|
|
287
|
+
/** The number of users matching `search` and `status`. */
|
|
288
|
+
getCount = async (options = {}) => (await this.request("GET", "/users/count" + listQuery(options), undefined, options)).totalCount;
|
|
289
|
+
getUser = (id, options) => this.request("GET", `/users/${userId(id)}`, undefined, options);
|
|
290
|
+
createUser = (input, options) => this.request("POST", "/users", input, options);
|
|
291
|
+
updateUser = (id, input, options) => this.request("PUT", `/users/${userId(id)}`, input, options);
|
|
292
|
+
setStatus = (id, status, options) => this.request("PUT", `/users/${userId(id)}/status`, { status }, options);
|
|
293
|
+
/** Disables the account and ends its sessions. */
|
|
294
|
+
banUser = (id, options) => this.setStatus(id, "disabled", options);
|
|
295
|
+
unbanUser = (id, options) => this.setStatus(id, "active", options);
|
|
296
|
+
lockUser = (id, options) => this.setStatus(id, "locked", options);
|
|
297
|
+
unlockUser = (id, options) => this.setStatus(id, "active", options);
|
|
298
|
+
deleteUser = (id, options) => this.request("DELETE", `/users/${userId(id)}`, undefined, options);
|
|
299
|
+
getUserEmailAddressList = (id, options) => this.request("GET", `/users/${userId(id)}/email-addresses`, undefined, options);
|
|
300
|
+
addEmailAddress = (id, input, options) => this.request("POST", `/users/${userId(id)}/email-addresses`, input, options);
|
|
301
|
+
setEmailVerification = (id, emailId, status, options) => this.request("PUT", `/users/${userId(id)}/email-addresses/${integerId(emailId)}`, {
|
|
302
|
+
status,
|
|
303
|
+
...(options?.verificationReason
|
|
304
|
+
? { verificationReason: options.verificationReason }
|
|
305
|
+
: {}),
|
|
306
|
+
}, options);
|
|
307
|
+
setPrimaryEmail = (id, emailId, options) => this.request("PUT", `/users/${userId(id)}/email-addresses/${integerId(emailId)}/primary`, undefined, options);
|
|
308
|
+
removeEmailAddress = (id, emailId, options) => this.request("DELETE", `/users/${userId(id)}/email-addresses/${integerId(emailId)}`, undefined, options);
|
|
309
|
+
getUserExternalAccountList = (id, options) => this.request("GET", `/users/${userId(id)}/external-accounts`, undefined, options);
|
|
310
|
+
}
|
|
311
|
+
export class ManagementExternalProviders {
|
|
312
|
+
request;
|
|
313
|
+
constructor(request) {
|
|
314
|
+
this.request = request;
|
|
315
|
+
}
|
|
316
|
+
list = (options) => this.request("GET", "/external-providers", undefined, options);
|
|
317
|
+
create = (input, options) => this.request("POST", "/external-providers", input, options);
|
|
318
|
+
update = (id, input, options) => this.request("PUT", `/external-providers/${integerId(id)}`, input, options);
|
|
319
|
+
delete = (id, options) => this.request("DELETE", `/external-providers/${integerId(id)}`, undefined, options);
|
|
320
|
+
}
|
|
321
|
+
export class ManagementWebhooks {
|
|
322
|
+
request;
|
|
323
|
+
constructor(request) {
|
|
324
|
+
this.request = request;
|
|
325
|
+
}
|
|
326
|
+
catalog = (options) => this.request("GET", "/webhooks/catalog", undefined, options);
|
|
327
|
+
endpoints = (options) => this.request("GET", "/webhooks/endpoints", undefined, options);
|
|
328
|
+
createEndpoint = (input, options) => this.request("POST", "/webhooks/endpoints", input, options);
|
|
329
|
+
updateEndpoint = (id, input, options) => this.request("PUT", `/webhooks/endpoints/${integerId(id)}`, input, options);
|
|
330
|
+
archiveEndpoint = (id, expectedUpdatedAt, options) => this.request("POST", `/webhooks/endpoints/${integerId(id)}/archive`, { expectedUpdatedAt }, options);
|
|
331
|
+
rotateSecret = (id, expectedUpdatedAt, options) => this.request("POST", `/webhooks/endpoints/${integerId(id)}/rotate-secret`, { expectedUpdatedAt }, options);
|
|
332
|
+
sendTest = (id, options) => this.request("POST", `/webhooks/endpoints/${integerId(id)}/test`, undefined, options);
|
|
333
|
+
deliveries = (options = {}) => {
|
|
334
|
+
const query = new URLSearchParams(listQuery({
|
|
335
|
+
...(options.limit === undefined
|
|
336
|
+
? {}
|
|
337
|
+
: { limit: options.limit }),
|
|
338
|
+
...(options.cursor === undefined
|
|
339
|
+
? {}
|
|
340
|
+
: { cursor: options.cursor }),
|
|
341
|
+
}).slice(1));
|
|
342
|
+
if (options.endpointId !== undefined)
|
|
343
|
+
query.set("endpointId", integerId(options.endpointId));
|
|
344
|
+
if (options.status !== undefined)
|
|
345
|
+
query.set("status", options.status);
|
|
346
|
+
return this.request("GET", "/webhooks/deliveries?" + query, undefined, options);
|
|
347
|
+
};
|
|
348
|
+
delivery = (id, options) => this.request("GET", `/webhooks/deliveries/${sessionId(id)}`, undefined, options);
|
|
349
|
+
replay = (id, options) => this.request("POST", `/webhooks/deliveries/${sessionId(id)}/replay`, undefined, options);
|
|
350
|
+
}
|
|
351
|
+
export class ManagementApiKeys {
|
|
352
|
+
request;
|
|
353
|
+
constructor(request) {
|
|
354
|
+
this.request = request;
|
|
355
|
+
}
|
|
356
|
+
getApiKeyList = (options = {}) => {
|
|
357
|
+
const query = new URLSearchParams();
|
|
358
|
+
if (options.userId !== undefined)
|
|
359
|
+
query.set("userId", userId(options.userId));
|
|
360
|
+
if (options.includeRevoked)
|
|
361
|
+
query.set("includeRevoked", "true");
|
|
362
|
+
if (options.limit !== undefined) {
|
|
363
|
+
if (!Number.isInteger(options.limit) || options.limit < 1 || options.limit > 100)
|
|
364
|
+
throw new Error("Use a page limit between 1 and 100.");
|
|
365
|
+
query.set("limit", String(options.limit));
|
|
366
|
+
}
|
|
367
|
+
if (options.cursor !== undefined)
|
|
368
|
+
query.set("cursor", options.cursor);
|
|
369
|
+
return this.request("GET", "/api-keys" + (query.size ? "?" + query : ""), undefined, options);
|
|
370
|
+
};
|
|
371
|
+
getApiKey = (id, options) => this.request("GET", `/api-keys/${sessionId(id)}`, undefined, options);
|
|
372
|
+
/** Sets what a key may do in your API. Only your backend grants scopes and claims; the key's owner cannot. */
|
|
373
|
+
updateApiKey = (id, input, options) => this.request("PUT", `/api-keys/${sessionId(id)}`, { scopes: input.scopes, claims: input.claims ?? null }, options);
|
|
374
|
+
revokeApiKey = (id, options = {}) => this.request("POST", `/api-keys/${sessionId(id)}/revoke`, { revocationReason: options.revocationReason ?? null }, options);
|
|
375
|
+
/** Verifies a presented `ak_` secret. Throws `PistiManagementError` (401) for unknown, expired or revoked keys. */
|
|
376
|
+
verifySecret = (secret, options) => this.request("POST", "/api-keys/verify", { secret }, options);
|
|
377
|
+
}
|
|
378
|
+
export class ManagementSessions {
|
|
379
|
+
request;
|
|
380
|
+
constructor(request) {
|
|
381
|
+
this.request = request;
|
|
382
|
+
}
|
|
383
|
+
/** Sessions in the environment, newest first. Filter by `userId` and `status`. */
|
|
384
|
+
getSessionList = (options = {}) => {
|
|
385
|
+
const query = new URLSearchParams();
|
|
386
|
+
if (options.userId !== undefined)
|
|
387
|
+
query.set("userId", userId(options.userId));
|
|
388
|
+
if (options.status !== undefined)
|
|
389
|
+
query.set("status", options.status);
|
|
390
|
+
if (options.limit !== undefined) {
|
|
391
|
+
if (!Number.isInteger(options.limit) || options.limit < 1 || options.limit > 100)
|
|
392
|
+
throw new Error("Use a page limit between 1 and 100.");
|
|
393
|
+
query.set("limit", String(options.limit));
|
|
394
|
+
}
|
|
395
|
+
if (options.cursor !== undefined)
|
|
396
|
+
query.set("cursor", options.cursor);
|
|
397
|
+
return this.request("GET", "/sessions" + (query.size ? "?" + query : ""), undefined, options);
|
|
398
|
+
};
|
|
399
|
+
getSession = (id, options) => this.request("GET", `/sessions/${sessionId(id)}`, undefined, options);
|
|
400
|
+
revokeSession = (id, options) => this.request("DELETE", `/sessions/${sessionId(id)}`, undefined, options);
|
|
401
|
+
}
|
|
402
|
+
export class ManagementOrganizations {
|
|
403
|
+
request;
|
|
404
|
+
constructor(request) {
|
|
405
|
+
this.request = request;
|
|
406
|
+
}
|
|
407
|
+
getOrganizationList = (options = {}) => this.request("GET", "/organizations" + listQuery(options), undefined, options);
|
|
408
|
+
getOrganization = (id, options) => this.request("GET", `/organizations/${integerId(id)}`, undefined, options);
|
|
409
|
+
createOrganization = (input, options) => this.request("POST", "/organizations", input, options);
|
|
410
|
+
updateOrganization = (id, input, options) => this.request("PUT", `/organizations/${integerId(id)}`, input, options);
|
|
411
|
+
deleteOrganization = (id, options) => this.request("DELETE", `/organizations/${integerId(id)}`, undefined, options);
|
|
412
|
+
getOrganizationMembershipList = (id, options = {}) => this.request("GET", `/organizations/${integerId(id)}/memberships` + listQuery(options), undefined, options);
|
|
413
|
+
updateOrganizationMembership = (id, memberId, roleId, options) => this.request("PUT", `/organizations/${integerId(id)}/memberships/${userId(memberId)}`, { roleId: Number(integerId(roleId)) }, options);
|
|
414
|
+
deleteOrganizationMembership = (id, memberId, options) => this.request("DELETE", `/organizations/${integerId(id)}/memberships/${userId(memberId)}`, undefined, options);
|
|
415
|
+
getOrganizationInvitationList = (id, options = {}) => this.request("GET", `/organizations/${integerId(id)}/invitations` + listQuery(options), undefined, options);
|
|
416
|
+
createOrganizationInvitation = (id, input, options) => this.request("POST", `/organizations/${integerId(id)}/invitations`, { ...input, roleId: Number(integerId(input.roleId)) }, options);
|
|
417
|
+
reissueOrganizationInvitation = (id, invitationId, input, options) => this.request("POST", `/organizations/${integerId(id)}/invitations/${integerId(invitationId)}/reissue`, input, options);
|
|
418
|
+
revokeOrganizationInvitation = (id, invitationId, options) => this.request("DELETE", `/organizations/${integerId(id)}/invitations/${integerId(invitationId)}`, undefined, options);
|
|
419
|
+
getRoleList = (id, options) => this.request("GET", `/organizations/${integerId(id)}/roles`, undefined, options);
|
|
420
|
+
createRole = (id, input, options) => this.request("POST", `/organizations/${integerId(id)}/roles`, input, options);
|
|
421
|
+
updateRole = (id, roleId, input, options) => this.request("PUT", `/organizations/${integerId(id)}/roles/${integerId(roleId)}`, input, options);
|
|
422
|
+
deleteRole = (id, roleId, options) => this.request("DELETE", `/organizations/${integerId(id)}/roles/${integerId(roleId)}`, undefined, options);
|
|
423
|
+
getPermissionList = (options) => this.request("GET", "/permissions", undefined, options);
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Creates a backend client, like Clerk's `createClerkClient`. Without options it reads
|
|
427
|
+
* `PISTI_PUBLISHABLE_KEY`, `PISTI_SECRET_KEY` and `PISTI_AUTHORIZED_PARTIES`.
|
|
428
|
+
*/
|
|
429
|
+
export function createPistiClient(options) {
|
|
430
|
+
return new PistiClient(options);
|
|
431
|
+
}
|
|
432
|
+
//# sourceMappingURL=management.js.map
|