@chanomhub/sdk 1.2.4 → 1.2.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 (41) hide show
  1. package/README.md +1 -1
  2. package/dist/__tests__/mocks/handlers.d.ts.map +1 -1
  3. package/dist/__tests__/mocks/handlers.js +232 -184
  4. package/dist/__tests__/mocks/handlers.js.map +1 -1
  5. package/dist/__tests__/real_api.test.d.ts +2 -0
  6. package/dist/__tests__/real_api.test.d.ts.map +1 -0
  7. package/dist/__tests__/real_api.test.js +44 -0
  8. package/dist/__tests__/real_api.test.js.map +1 -0
  9. package/dist/__tests__/repositories.test.js +19 -0
  10. package/dist/__tests__/repositories.test.js.map +1 -1
  11. package/dist/client.d.ts.map +1 -1
  12. package/dist/client.js +2 -1
  13. package/dist/client.js.map +1 -1
  14. package/dist/index.d.ts +5 -3
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +4 -2
  17. package/dist/index.js.map +1 -1
  18. package/dist/repositories/articleRepository.d.ts +6 -0
  19. package/dist/repositories/articleRepository.d.ts.map +1 -1
  20. package/dist/repositories/articleRepository.js +97 -40
  21. package/dist/repositories/articleRepository.js.map +1 -1
  22. package/dist/repositories/index.d.ts +1 -0
  23. package/dist/repositories/index.d.ts.map +1 -1
  24. package/dist/repositories/index.js +3 -1
  25. package/dist/repositories/index.js.map +1 -1
  26. package/dist/repositories/searchRepository.d.ts.map +1 -1
  27. package/dist/repositories/searchRepository.js +7 -5
  28. package/dist/repositories/searchRepository.js.map +1 -1
  29. package/dist/repositories/subscriptionsRepository.d.ts +44 -0
  30. package/dist/repositories/subscriptionsRepository.d.ts.map +1 -0
  31. package/dist/repositories/subscriptionsRepository.js +74 -0
  32. package/dist/repositories/subscriptionsRepository.js.map +1 -0
  33. package/dist/types/index.d.ts +1 -0
  34. package/dist/types/index.d.ts.map +1 -1
  35. package/dist/types/index.js +1 -0
  36. package/dist/types/index.js.map +1 -1
  37. package/dist/types/subscription.d.ts +63 -0
  38. package/dist/types/subscription.d.ts.map +1 -0
  39. package/dist/types/subscription.js +6 -0
  40. package/dist/types/subscription.js.map +1 -0
  41. package/package.json +1 -1
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ /**
3
+ * Chanomhub SDK - Subscriptions Repository
4
+ *
5
+ * Provides API methods for managing subscriptions and plans.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.createSubscriptionsRepository = createSubscriptionsRepository;
9
+ const errors_1 = require("../errors");
10
+ /**
11
+ * Creates a subscriptions repository with the given REST client
12
+ */
13
+ function createSubscriptionsRepository(fetcher, config) {
14
+ function requireAuth() {
15
+ if (!config.token) {
16
+ throw new errors_1.AuthenticationError('Authentication required for subscriptions management. Use createAuthenticatedClient() or provide a token.');
17
+ }
18
+ }
19
+ async function create(data) {
20
+ requireAuth();
21
+ const { data: response, error } = await fetcher('/api/subscriptions', { method: 'POST', body: data });
22
+ if (error) {
23
+ console.error('Failed to create subscription:', error);
24
+ return null;
25
+ }
26
+ return response;
27
+ }
28
+ async function getAll() {
29
+ requireAuth();
30
+ const { data, error } = await fetcher('/api/subscriptions', { method: 'GET' });
31
+ if (error) {
32
+ console.error('Failed to get subscriptions:', error);
33
+ return [];
34
+ }
35
+ return data !== null && data !== void 0 ? data : [];
36
+ }
37
+ async function cancel(id) {
38
+ requireAuth();
39
+ const { data: response, error } = await fetcher(`/api/subscriptions/${id}`, { method: 'DELETE' });
40
+ if (error) {
41
+ console.error('Failed to cancel subscription:', error);
42
+ return null;
43
+ }
44
+ return response;
45
+ }
46
+ async function createPlan(data) {
47
+ requireAuth();
48
+ const { data: response, error } = await fetcher('/api/subscriptions/plans', { method: 'POST', body: data });
49
+ if (error) {
50
+ console.error('Failed to create subscription plan:', error);
51
+ return null;
52
+ }
53
+ return response;
54
+ }
55
+ async function getPlans(refresh) {
56
+ const url = refresh
57
+ ? '/api/subscriptions/plans?refresh=true'
58
+ : '/api/subscriptions/plans';
59
+ const { data, error } = await fetcher(url, { method: 'GET' });
60
+ if (error) {
61
+ console.error('Failed to get subscription plans:', error);
62
+ return [];
63
+ }
64
+ return data !== null && data !== void 0 ? data : [];
65
+ }
66
+ return {
67
+ create,
68
+ getAll,
69
+ cancel,
70
+ createPlan,
71
+ getPlans,
72
+ };
73
+ }
74
+ //# sourceMappingURL=subscriptionsRepository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscriptionsRepository.js","sourceRoot":"","sources":["../../repositories/subscriptionsRepository.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAmDH,sEAqGC;AApJD,sCAAgD;AA4ChD;;GAEG;AACH,SAAgB,6BAA6B,CACzC,OAAoB,EACpB,MAAuB;IAEvB,SAAS,WAAW;QAChB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YAChB,MAAM,IAAI,4BAAmB,CACzB,2GAA2G,CAC9G,CAAC;QACN,CAAC;IACL,CAAC;IAED,KAAK,UAAU,MAAM,CAAC,IAA+B;QACjD,WAAW,EAAE,CAAC;QAEd,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,MAAM,OAAO,CAC3C,oBAAoB,EACpB,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAA0C,EAAE,CACvE,CAAC;QAEF,IAAI,KAAK,EAAE,CAAC;YACR,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;YACvD,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED,KAAK,UAAU,MAAM;QACjB,WAAW,EAAE,CAAC;QAEd,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,OAAO,CACjC,oBAAoB,EACpB,EAAE,MAAM,EAAE,KAAK,EAAE,CACpB,CAAC;QAEF,IAAI,KAAK,EAAE,CAAC;YACR,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAC;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C;QACd,CAAC;QAED,OAAO,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE,CAAC;IACtB,CAAC;IAED,OAAO;QACH,MAAM;QACN,MAAM;QACN,MAAM;QACN,UAAU;QACV,QAAQ;KACX,CAAC;AACN,CAAC"}
@@ -7,4 +7,5 @@ export * from './user';
7
7
  export type { SocialMediaLink } from './user';
8
8
  export * from './auth';
9
9
  export * from './download';
10
+ export * from './subscription';
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,YAAY,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAC9C,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,YAAY,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAC9C,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC"}
@@ -22,4 +22,5 @@ __exportStar(require("./article"), exports);
22
22
  __exportStar(require("./user"), exports);
23
23
  __exportStar(require("./auth"), exports);
24
24
  __exportStar(require("./download"), exports);
25
+ __exportStar(require("./subscription"), exports);
25
26
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../types/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;AAEH,2CAAyB;AACzB,4CAA0B;AAC1B,yCAAuB;AAEvB,yCAAuB;AACvB,6CAA2B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../types/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;AAEH,2CAAyB;AACzB,4CAA0B;AAC1B,yCAAuB;AAEvB,yCAAuB;AACvB,6CAA2B;AAC3B,iDAA+B"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Chanomhub SDK - Subscription Types
3
+ */
4
+ /** Subscription status */
5
+ export type SubscriptionStatus = 'ACTIVE' | 'CANCELED' | 'SUSPENDED' | 'PAST_DUE' | 'UNPAID';
6
+ /** Payment method */
7
+ export type PaymentMethod = 'POINTS' | 'TRUEMONEY' | 'SLIP2GO';
8
+ /** Subscription entity */
9
+ export interface Subscription {
10
+ id: number;
11
+ userId: number;
12
+ planId: string;
13
+ status: SubscriptionStatus;
14
+ currentPeriodStart: string;
15
+ currentPeriodEnd: string;
16
+ cancelAtPeriodEnd: boolean;
17
+ startDate: string;
18
+ endDate?: string | null;
19
+ createdAt: string;
20
+ updatedAt: string;
21
+ }
22
+ /** Subscription plan entity */
23
+ export interface SubscriptionPlan {
24
+ planId: string;
25
+ name: string;
26
+ description?: string | null;
27
+ pointsCost: number;
28
+ durationDays: number;
29
+ roleId: number;
30
+ isActive: boolean;
31
+ }
32
+ /** Request to create a new subscription */
33
+ export interface CreateSubscriptionRequest {
34
+ planId: string;
35
+ paymentMethod?: PaymentMethod;
36
+ }
37
+ /** Request to create a new subscription plan */
38
+ export interface CreateSubscriptionPlanRequest {
39
+ planId: string;
40
+ name: string;
41
+ description?: string;
42
+ pointsCost: number;
43
+ durationDays: number;
44
+ roleId: number;
45
+ isActive?: boolean;
46
+ }
47
+ /** Response for subscription plan creation */
48
+ export interface SubscriptionPlanResponse {
49
+ plan: SubscriptionPlan;
50
+ }
51
+ /** Response for subscription creation */
52
+ export interface SubscriptionResponse {
53
+ subscription: Subscription;
54
+ }
55
+ /** List of user subscriptions */
56
+ export interface SubscriptionsListResponse {
57
+ subscriptions: Subscription[];
58
+ }
59
+ /** List of subscription plans */
60
+ export interface SubscriptionPlansListResponse {
61
+ plans: SubscriptionPlan[];
62
+ }
63
+ //# sourceMappingURL=subscription.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscription.d.ts","sourceRoot":"","sources":["../../types/subscription.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,0BAA0B;AAC1B,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,UAAU,GAAG,WAAW,GAAG,UAAU,GAAG,QAAQ,CAAC;AAE7F,qBAAqB;AACrB,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,CAAC;AAE/D,0BAA0B;AAC1B,MAAM,WAAW,YAAY;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,kBAAkB,CAAC;IAC3B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,+BAA+B;AAC/B,MAAM,WAAW,gBAAgB;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;CACrB;AAED,2CAA2C;AAC3C,MAAM,WAAW,yBAAyB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,aAAa,CAAC;CACjC;AAED,gDAAgD;AAChD,MAAM,WAAW,6BAA6B;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,8CAA8C;AAC9C,MAAM,WAAW,wBAAwB;IACrC,IAAI,EAAE,gBAAgB,CAAC;CAC1B;AAED,yCAAyC;AACzC,MAAM,WAAW,oBAAoB;IACjC,YAAY,EAAE,YAAY,CAAC;CAC9B;AAED,iCAAiC;AACjC,MAAM,WAAW,yBAAyB;IACtC,aAAa,EAAE,YAAY,EAAE,CAAC;CACjC;AAED,iCAAiC;AACjC,MAAM,WAAW,6BAA6B;IAC1C,KAAK,EAAE,gBAAgB,EAAE,CAAC;CAC7B"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * Chanomhub SDK - Subscription Types
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //# sourceMappingURL=subscription.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscription.js","sourceRoot":"","sources":["../../types/subscription.ts"],"names":[],"mappings":";AAAA;;GAEG"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chanomhub/sdk",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "description": "ChanomHub SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",