@whop/sdk 0.0.5 → 0.0.6

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +0 -4
  3. package/client.d.mts +7 -4
  4. package/client.d.mts.map +1 -1
  5. package/client.d.ts +7 -4
  6. package/client.d.ts.map +1 -1
  7. package/client.js +5 -5
  8. package/client.js.map +1 -1
  9. package/client.mjs +5 -5
  10. package/client.mjs.map +1 -1
  11. package/lib/verify-user-token.d.mts.map +1 -1
  12. package/lib/verify-user-token.d.ts.map +1 -1
  13. package/lib/verify-user-token.js +6 -3
  14. package/lib/verify-user-token.js.map +1 -1
  15. package/lib/verify-user-token.mjs +6 -3
  16. package/lib/verify-user-token.mjs.map +1 -1
  17. package/package.json +1 -1
  18. package/resources/index.d.mts +1 -0
  19. package/resources/index.d.mts.map +1 -1
  20. package/resources/index.d.ts +1 -0
  21. package/resources/index.d.ts.map +1 -1
  22. package/resources/index.js +3 -1
  23. package/resources/index.js.map +1 -1
  24. package/resources/index.mjs +1 -0
  25. package/resources/index.mjs.map +1 -1
  26. package/resources/notifications.d.mts +105 -0
  27. package/resources/notifications.d.mts.map +1 -0
  28. package/resources/notifications.d.ts +105 -0
  29. package/resources/notifications.d.ts.map +1 -0
  30. package/resources/notifications.js +24 -0
  31. package/resources/notifications.js.map +1 -0
  32. package/resources/notifications.mjs +20 -0
  33. package/resources/notifications.mjs.map +1 -0
  34. package/src/client.ts +18 -10
  35. package/src/lib/verify-user-token.ts +6 -3
  36. package/src/resources/index.ts +5 -0
  37. package/src/resources/notifications.ts +131 -0
  38. package/src/version.ts +1 -1
  39. package/version.d.mts +1 -1
  40. package/version.d.ts +1 -1
  41. package/version.js +1 -1
  42. package/version.mjs +1 -1
package/src/client.ts CHANGED
@@ -170,6 +170,11 @@ import {
170
170
  MessageUpdateParams,
171
171
  Messages,
172
172
  } from './resources/messages';
173
+ import {
174
+ NotificationCreateParams,
175
+ NotificationCreateResponse,
176
+ Notifications,
177
+ } from './resources/notifications';
173
178
  import {
174
179
  BillingReasons,
175
180
  CardBrands,
@@ -293,9 +298,9 @@ export interface ClientOptions {
293
298
  webhookKey?: string | null | undefined;
294
299
 
295
300
  /**
296
- * Defaults to process.env['WHOP_APP_ID'].
301
+ * When using the SDK in app mode pass this parameter to allow verifying user tokens
297
302
  */
298
- appID?: string | undefined;
303
+ appID?: string | null | undefined;
299
304
 
300
305
  /**
301
306
  * Override the default base URL for the API, e.g., "https://api.example.com/v2/"
@@ -372,7 +377,7 @@ export interface ClientOptions {
372
377
  export class Whop {
373
378
  apiKey: string;
374
379
  webhookKey: string | null;
375
- appID: string;
380
+ appID: string | null;
376
381
 
377
382
  baseURL: string;
378
383
  maxRetries: number;
@@ -391,7 +396,7 @@ export class Whop {
391
396
  *
392
397
  * @param {string | undefined} [opts.apiKey=process.env['WHOP_API_KEY'] ?? undefined]
393
398
  * @param {string | null | undefined} [opts.webhookKey=process.env['WHOP_WEBHOOK_SECRET'] ?? null]
394
- * @param {string | undefined} [opts.appID=process.env['WHOP_APP_ID'] ?? undefined]
399
+ * @param {string | null | undefined} [opts.appID=process.env['WHOP_APP_ID'] ?? null]
395
400
  * @param {string} [opts.baseURL=process.env['WHOP_BASE_URL'] ?? https://api.whop.com/api/v1] - Override the default base URL for the API.
396
401
  * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
397
402
  * @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
@@ -404,7 +409,7 @@ export class Whop {
404
409
  baseURL = readEnv('WHOP_BASE_URL'),
405
410
  apiKey = readEnv('WHOP_API_KEY'),
406
411
  webhookKey = readEnv('WHOP_WEBHOOK_SECRET') ?? null,
407
- appID = readEnv('WHOP_APP_ID'),
412
+ appID = readEnv('WHOP_APP_ID') ?? null,
408
413
  ...opts
409
414
  }: ClientOptions = {}) {
410
415
  if (apiKey === undefined) {
@@ -412,11 +417,6 @@ export class Whop {
412
417
  "The WHOP_API_KEY environment variable is missing or empty; either provide it, or instantiate the Whop client with an apiKey option, like new Whop({ apiKey: 'My API Key' }).",
413
418
  );
414
419
  }
415
- if (appID === undefined) {
416
- throw new Errors.WhopError(
417
- "The WHOP_APP_ID environment variable is missing or empty; either provide it, or instantiate the Whop client with an appID option, like new Whop({ appID: 'app_xxxxxxxxxxxxxx' }).",
418
- );
419
- }
420
420
 
421
421
  const options: ClientOptions = {
422
422
  apiKey,
@@ -1030,6 +1030,7 @@ export class Whop {
1030
1030
  reviews: API.Reviews = new API.Reviews(this);
1031
1031
  courseStudents: API.CourseStudents = new API.CourseStudents(this);
1032
1032
  accessTokens: API.AccessTokens = new API.AccessTokens(this);
1033
+ notifications: API.Notifications = new API.Notifications(this);
1033
1034
  }
1034
1035
 
1035
1036
  Whop.Apps = Apps;
@@ -1064,6 +1065,7 @@ Whop.CourseLessons = CourseLessons;
1064
1065
  Whop.Reviews = Reviews;
1065
1066
  Whop.CourseStudents = CourseStudents;
1066
1067
  Whop.AccessTokens = AccessTokens;
1068
+ Whop.Notifications = Notifications;
1067
1069
 
1068
1070
  export declare namespace Whop {
1069
1071
  export type RequestOptions = Opts.RequestOptions;
@@ -1363,6 +1365,12 @@ export declare namespace Whop {
1363
1365
  type AccessTokenCreateParams as AccessTokenCreateParams,
1364
1366
  };
1365
1367
 
1368
+ export {
1369
+ Notifications as Notifications,
1370
+ type NotificationCreateResponse as NotificationCreateResponse,
1371
+ type NotificationCreateParams as NotificationCreateParams,
1372
+ };
1373
+
1366
1374
  export type AccessLevel = API.AccessLevel;
1367
1375
  export type AccessPassType = API.AccessPassType;
1368
1376
  export type App = API.App;
@@ -55,13 +55,16 @@ export interface VerifyUserTokenOptions<DontThrow extends boolean = false> {
55
55
  }
56
56
 
57
57
  export function makeUserTokenVerifierFromSdk(client: Whop) {
58
- const baseOptions: VerifyUserTokenOptions<false> = {
59
- appId: client.appID,
60
- };
61
58
  return async function verifyUserToken<DT extends boolean = false>(
62
59
  tokenOrHeadersOrRequest: string | Headers | Request | null | undefined,
63
60
  options?: Partial<VerifyUserTokenOptions<DT>>,
64
61
  ) {
62
+ if (!client.appID) {
63
+ throw Error('You must set appID in the Whop client constructor if you want to verify user tokens.');
64
+ }
65
+ const baseOptions: VerifyUserTokenOptions<false> = {
66
+ appId: client.appID,
67
+ };
65
68
  return await internalVerifyUserToken<DT>(tokenOrHeadersOrRequest, {
66
69
  ...baseOptions,
67
70
  ...options,
@@ -157,6 +157,11 @@ export {
157
157
  type MessageListParams,
158
158
  type MessageListResponsesCursorPage,
159
159
  } from './messages';
160
+ export {
161
+ Notifications,
162
+ type NotificationCreateResponse,
163
+ type NotificationCreateParams,
164
+ } from './notifications';
160
165
  export {
161
166
  Payments,
162
167
  type BillingReasons,
@@ -0,0 +1,131 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from '../core/resource';
4
+ import { APIPromise } from '../core/api-promise';
5
+ import { RequestOptions } from '../internal/request-options';
6
+
7
+ export class Notifications extends APIResource {
8
+ /**
9
+ * Queues a notification to be sent to users in an experience or company team
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const notification = await client.notifications.create({
14
+ * company_id: 'biz_xxxxxxxxxxxxxx',
15
+ * content: 'content',
16
+ * title: 'title',
17
+ * });
18
+ * ```
19
+ */
20
+ create(body: NotificationCreateParams, options?: RequestOptions): APIPromise<NotificationCreateResponse> {
21
+ return this._client.post('/notifications', { body, ...options });
22
+ }
23
+ }
24
+
25
+ /**
26
+ * Response from queuing a notification
27
+ */
28
+ export interface NotificationCreateResponse {
29
+ /**
30
+ * Whether the notification was successfully queued for delivery
31
+ */
32
+ success: boolean;
33
+ }
34
+
35
+ export type NotificationCreateParams =
36
+ | NotificationCreateParams.SendNotificationV2InputWithCompanyID
37
+ | NotificationCreateParams.SendNotificationV2InputWithExperienceID;
38
+
39
+ export declare namespace NotificationCreateParams {
40
+ export interface SendNotificationV2InputWithCompanyID {
41
+ /**
42
+ * The id of the company to target. Only team members of this company will receive
43
+ * the notification. When clicked will take the user to your dashboard app view.
44
+ */
45
+ company_id: string;
46
+
47
+ /**
48
+ * The content of the notification
49
+ */
50
+ content: string;
51
+
52
+ /**
53
+ * The title of the notification
54
+ */
55
+ title: string;
56
+
57
+ /**
58
+ * Optional: ID of a Whop user whose profile picture will be used as the
59
+ * notification icon. If not provided, defaults to the experience or company
60
+ * avatar.
61
+ */
62
+ icon_user_id?: string | null;
63
+
64
+ /**
65
+ * The rest path to append to the generated deep link that opens your app. Use
66
+ * [restPath] in your app path in the dashboard to read this parameter.
67
+ */
68
+ rest_path?: string | null;
69
+
70
+ /**
71
+ * The subtitle of the notification
72
+ */
73
+ subtitle?: string | null;
74
+
75
+ /**
76
+ * If provided, this will only send to these users if they are also in the main
77
+ * scope (experience or company)
78
+ */
79
+ user_ids?: Array<string> | null;
80
+ }
81
+
82
+ export interface SendNotificationV2InputWithExperienceID {
83
+ /**
84
+ * The content of the notification
85
+ */
86
+ content: string;
87
+
88
+ /**
89
+ * The id of the experience to target. All users with access to this experience
90
+ * (customers and admins) will receive the notification. When clicked, open your
91
+ * experience view.
92
+ */
93
+ experience_id: string;
94
+
95
+ /**
96
+ * The title of the notification
97
+ */
98
+ title: string;
99
+
100
+ /**
101
+ * Optional: ID of a Whop user whose profile picture will be used as the
102
+ * notification icon. If not provided, defaults to the experience or company
103
+ * avatar.
104
+ */
105
+ icon_user_id?: string | null;
106
+
107
+ /**
108
+ * The rest path to append to the generated deep link that opens your app. Use
109
+ * [restPath] in your app path in the dashboard to read this parameter.
110
+ */
111
+ rest_path?: string | null;
112
+
113
+ /**
114
+ * The subtitle of the notification
115
+ */
116
+ subtitle?: string | null;
117
+
118
+ /**
119
+ * If provided, this will only send to these users if they are also in the main
120
+ * scope (experience or company)
121
+ */
122
+ user_ids?: Array<string> | null;
123
+ }
124
+ }
125
+
126
+ export declare namespace Notifications {
127
+ export {
128
+ type NotificationCreateResponse as NotificationCreateResponse,
129
+ type NotificationCreateParams as NotificationCreateParams,
130
+ };
131
+ }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.0.5'; // x-release-please-version
1
+ export const VERSION = '0.0.6'; // x-release-please-version
package/version.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.0.5";
1
+ export declare const VERSION = "0.0.6";
2
2
  //# sourceMappingURL=version.d.mts.map
package/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.0.5";
1
+ export declare const VERSION = "0.0.6";
2
2
  //# sourceMappingURL=version.d.ts.map
package/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '0.0.5'; // x-release-please-version
4
+ exports.VERSION = '0.0.6'; // x-release-please-version
5
5
  //# sourceMappingURL=version.js.map
package/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.0.5'; // x-release-please-version
1
+ export const VERSION = '0.0.6'; // x-release-please-version
2
2
  //# sourceMappingURL=version.mjs.map