@skillrecordings/sdk 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,6 +19,7 @@ interface SupportIntegration {
19
19
  updateEmail?(params: { userId, newEmail }): Promise<ActionResult>
20
20
  updateName?(params: { userId, newName }): Promise<ActionResult>
21
21
  getClaimedSeats?(bulkCouponId: string): Promise<ClaimedSeat[]>
22
+ searchContent?(request: ContentSearchRequest): Promise<ContentSearchResponse> // v0.3.0+
22
23
  }
23
24
  ```
24
25
 
package/dist/adapter.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Customer, Purchase, RefundRequest, RefundResult } from './types.js';
2
+ import 'zod';
2
3
 
3
4
  /**
4
5
  * Base adapter interface that apps must implement to integrate with the support platform.
@@ -0,0 +1,10 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ export {
8
+ __export
9
+ };
10
+ //# sourceMappingURL=chunk-PZ5AY32C.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/dist/client.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { SupportIntegration } from './integration.js';
2
- import { User, Purchase, Subscription, ActionResult, ClaimedSeat, ContentSearchRequest, ContentSearchResponse } from './types.js';
2
+ import { User, Purchase, Subscription, ActionResult, ClaimedSeat, ContentSearchRequest, ContentSearchResponse, ProductStatus, Promotion, CouponInfo, RefundPolicy, ContentAccess, UserActivity, LicenseInfo, AppInfo } from './types.js';
3
+ import 'zod';
3
4
 
4
5
  /**
5
6
  * Client for calling app integration endpoints with HMAC-signed requests.
@@ -28,15 +29,21 @@ declare class IntegrationClient implements SupportIntegration {
28
29
  });
29
30
  /**
30
31
  * Generate HMAC-SHA256 signature for request body.
31
- * Format: `t=<timestamp>,v1=<signature>`
32
+ * Format: `timestamp=<timestamp>,v1=<signature>`
32
33
  *
33
34
  * Signature is computed as: HMAC-SHA256(timestamp + "." + body, secret)
34
35
  */
35
36
  private generateSignature;
36
37
  /**
37
38
  * Make signed POST request to app integration endpoint.
39
+ * Uses action-based routing: all requests go to /api/support with action in body.
38
40
  */
39
41
  private request;
42
+ /**
43
+ * Make a signed request for an optional method.
44
+ * Returns the fallback value if the app responds with 501 (Not Implemented).
45
+ */
46
+ private requestOptional;
40
47
  lookupUser(email: string): Promise<User | null>;
41
48
  getPurchases(userId: string): Promise<Purchase[]>;
42
49
  getSubscriptions(userId: string): Promise<Subscription[]>;
@@ -66,6 +73,14 @@ declare class IntegrationClient implements SupportIntegration {
66
73
  }): Promise<ActionResult>;
67
74
  getClaimedSeats(bulkCouponId: string): Promise<ClaimedSeat[]>;
68
75
  searchContent(request: ContentSearchRequest): Promise<ContentSearchResponse>;
76
+ getProductStatus(productId: string): Promise<ProductStatus | null>;
77
+ getActivePromotions(): Promise<Promotion[]>;
78
+ getCouponInfo(code: string): Promise<CouponInfo | null>;
79
+ getRefundPolicy(): Promise<RefundPolicy>;
80
+ getContentAccess(userId: string): Promise<ContentAccess>;
81
+ getRecentActivity(userId: string): Promise<UserActivity>;
82
+ getLicenseInfo(purchaseId: string): Promise<LicenseInfo | null>;
83
+ getAppInfo(): Promise<AppInfo>;
69
84
  }
70
85
 
71
86
  export { IntegrationClient };
package/dist/client.js CHANGED
@@ -1,3 +1,5 @@
1
+ import "./chunk-PZ5AY32C.js";
2
+
1
3
  // src/client.ts
2
4
  import { createHmac } from "crypto";
3
5
  var IntegrationClient = class {
@@ -9,7 +11,7 @@ var IntegrationClient = class {
9
11
  }
10
12
  /**
11
13
  * Generate HMAC-SHA256 signature for request body.
12
- * Format: `t=<timestamp>,v1=<signature>`
14
+ * Format: `timestamp=<timestamp>,v1=<signature>`
13
15
  *
14
16
  * Signature is computed as: HMAC-SHA256(timestamp + "." + body, secret)
15
17
  */
@@ -17,15 +19,16 @@ var IntegrationClient = class {
17
19
  const timestamp = Math.floor(Date.now() / 1e3);
18
20
  const signedPayload = `${timestamp}.${body}`;
19
21
  const signature = createHmac("sha256", this.webhookSecret).update(signedPayload).digest("hex");
20
- return `t=${timestamp},v1=${signature}`;
22
+ return `timestamp=${timestamp},v1=${signature}`;
21
23
  }
22
24
  /**
23
25
  * Make signed POST request to app integration endpoint.
26
+ * Uses action-based routing: all requests go to /api/support with action in body.
24
27
  */
25
- async request(endpoint, payload) {
26
- const body = JSON.stringify(payload);
28
+ async request(action, payload) {
29
+ const body = JSON.stringify({ action, ...payload });
27
30
  const signature = this.generateSignature(body);
28
- const response = await fetch(`${this.baseUrl}${endpoint}`, {
31
+ const response = await fetch(this.baseUrl, {
29
32
  method: "POST",
30
33
  headers: {
31
34
  "Content-Type": "application/json",
@@ -51,35 +54,110 @@ var IntegrationClient = class {
51
54
  }
52
55
  return await response.json();
53
56
  }
57
+ /**
58
+ * Make a signed request for an optional method.
59
+ * Returns the fallback value if the app responds with 501 (Not Implemented).
60
+ */
61
+ async requestOptional(action, payload, fallback) {
62
+ const body = JSON.stringify({ action, ...payload });
63
+ const signature = this.generateSignature(body);
64
+ const response = await fetch(this.baseUrl, {
65
+ method: "POST",
66
+ headers: {
67
+ "Content-Type": "application/json",
68
+ "X-Support-Signature": signature
69
+ },
70
+ body
71
+ });
72
+ if (response.status === 501) {
73
+ return fallback;
74
+ }
75
+ if (!response.ok) {
76
+ let errorMessage;
77
+ try {
78
+ const errorBody = await response.json();
79
+ if (errorBody?.error) {
80
+ errorMessage = errorBody.error;
81
+ }
82
+ } catch {
83
+ }
84
+ if (errorMessage) {
85
+ throw new Error(errorMessage);
86
+ }
87
+ throw new Error(
88
+ `Integration request failed: ${response.status} ${response.statusText}`
89
+ );
90
+ }
91
+ return await response.json();
92
+ }
54
93
  async lookupUser(email) {
55
- return this.request("/api/support/lookup-user", { email });
94
+ return this.request("lookupUser", { email });
56
95
  }
57
96
  async getPurchases(userId) {
58
- return this.request("/api/support/get-purchases", { userId });
97
+ return this.request("getPurchases", { userId });
59
98
  }
60
99
  async getSubscriptions(userId) {
61
- return this.request("/api/support/get-subscriptions", { userId });
100
+ return this.request("getSubscriptions", { userId });
62
101
  }
63
102
  async revokeAccess(params) {
64
- return this.request("/api/support/revoke-access", params);
103
+ return this.request("revokeAccess", params);
65
104
  }
66
105
  async transferPurchase(params) {
67
- return this.request("/api/support/transfer-purchase", params);
106
+ return this.request("transferPurchase", params);
68
107
  }
69
108
  async generateMagicLink(params) {
70
- return this.request("/api/support/generate-magic-link", params);
109
+ return this.request("generateMagicLink", params);
71
110
  }
72
111
  async updateEmail(params) {
73
- return this.request("/api/support/update-email", params);
112
+ return this.request("updateEmail", params);
74
113
  }
75
114
  async updateName(params) {
76
- return this.request("/api/support/update-name", params);
115
+ return this.request("updateName", params);
77
116
  }
78
117
  async getClaimedSeats(bulkCouponId) {
79
- return this.request("/api/support/get-claimed-seats", { bulkCouponId });
118
+ return this.request("getClaimedSeats", { bulkCouponId });
80
119
  }
81
120
  async searchContent(request) {
82
- return this.request("/api/support/search-content", request);
121
+ return this.request(
122
+ "searchContent",
123
+ request
124
+ );
125
+ }
126
+ async getProductStatus(productId) {
127
+ return this.request("getProductStatus", { productId });
128
+ }
129
+ // ── Agent Intelligence Methods ─────────────────────────────────────
130
+ // These methods handle 501 (Not Implemented) gracefully by returning
131
+ // null or empty arrays, allowing the agent to function even when
132
+ // the app hasn't implemented optional methods.
133
+ async getActivePromotions() {
134
+ return this.requestOptional("getActivePromotions", {}, []);
135
+ }
136
+ async getCouponInfo(code) {
137
+ return this.requestOptional(
138
+ "getCouponInfo",
139
+ { code },
140
+ null
141
+ );
142
+ }
143
+ async getRefundPolicy() {
144
+ return this.request("getRefundPolicy", {});
145
+ }
146
+ async getContentAccess(userId) {
147
+ return this.request("getContentAccess", { userId });
148
+ }
149
+ async getRecentActivity(userId) {
150
+ return this.request("getRecentActivity", { userId });
151
+ }
152
+ async getLicenseInfo(purchaseId) {
153
+ return this.requestOptional(
154
+ "getLicenseInfo",
155
+ { purchaseId },
156
+ null
157
+ );
158
+ }
159
+ async getAppInfo() {
160
+ return this.request("getAppInfo", {});
83
161
  }
84
162
  };
85
163
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client.ts"],"sourcesContent":["import { createHmac } from 'node:crypto'\nimport type {\n ActionResult,\n ClaimedSeat,\n ContentSearchRequest,\n ContentSearchResponse,\n Purchase,\n Subscription,\n SupportIntegration,\n User,\n} from './integration'\n\n/**\n * Client for calling app integration endpoints with HMAC-signed requests.\n *\n * Used by core to call app-specific support actions (lookupUser, getPurchases, etc.)\n * with Stripe-style HMAC-SHA256 signature verification.\n *\n * @example\n * ```typescript\n * import { IntegrationClient } from '@skillrecordings/sdk/client'\n *\n * const client = new IntegrationClient({\n * baseUrl: 'https://totaltypescript.com',\n * webhookSecret: 'whsec_abc123',\n * })\n *\n * const user = await client.lookupUser('test@example.com')\n * ```\n */\nexport class IntegrationClient implements SupportIntegration {\n private readonly baseUrl: string\n private readonly webhookSecret: string\n\n constructor(config: { baseUrl: string; webhookSecret: string }) {\n // Strip trailing slash for consistent URL construction\n this.baseUrl = config.baseUrl.replace(/\\/$/, '')\n this.webhookSecret = config.webhookSecret\n }\n\n /**\n * Generate HMAC-SHA256 signature for request body.\n * Format: `t=<timestamp>,v1=<signature>`\n *\n * Signature is computed as: HMAC-SHA256(timestamp + \".\" + body, secret)\n */\n private generateSignature(body: string): string {\n const timestamp = Math.floor(Date.now() / 1000)\n const signedPayload = `${timestamp}.${body}`\n const signature = createHmac('sha256', this.webhookSecret)\n .update(signedPayload)\n .digest('hex')\n\n return `t=${timestamp},v1=${signature}`\n }\n\n /**\n * Make signed POST request to app integration endpoint.\n */\n private async request<T>(endpoint: string, payload: unknown): Promise<T> {\n const body = JSON.stringify(payload)\n const signature = this.generateSignature(body)\n\n const response = await fetch(`${this.baseUrl}${endpoint}`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-Support-Signature': signature,\n },\n body,\n })\n\n if (!response.ok) {\n // Try to extract error message from response body\n let errorMessage: string | undefined\n try {\n const errorBody = (await response.json()) as { error?: string }\n if (errorBody?.error) {\n errorMessage = errorBody.error\n }\n } catch {\n // If JSON parsing fails, ignore and use status text\n }\n\n if (errorMessage) {\n throw new Error(errorMessage)\n }\n throw new Error(\n `Integration request failed: ${response.status} ${response.statusText}`\n )\n }\n\n return (await response.json()) as T\n }\n\n async lookupUser(email: string): Promise<User | null> {\n return this.request('/api/support/lookup-user', { email })\n }\n\n async getPurchases(userId: string): Promise<Purchase[]> {\n return this.request('/api/support/get-purchases', { userId })\n }\n\n async getSubscriptions(userId: string): Promise<Subscription[]> {\n return this.request('/api/support/get-subscriptions', { userId })\n }\n\n async revokeAccess(params: {\n purchaseId: string\n reason: string\n refundId: string\n }): Promise<ActionResult> {\n return this.request('/api/support/revoke-access', params)\n }\n\n async transferPurchase(params: {\n purchaseId: string\n fromUserId: string\n toEmail: string\n }): Promise<ActionResult> {\n return this.request('/api/support/transfer-purchase', params)\n }\n\n async generateMagicLink(params: {\n email: string\n expiresIn: number\n }): Promise<{ url: string }> {\n return this.request('/api/support/generate-magic-link', params)\n }\n\n async updateEmail(params: {\n userId: string\n newEmail: string\n }): Promise<ActionResult> {\n return this.request('/api/support/update-email', params)\n }\n\n async updateName(params: {\n userId: string\n newName: string\n }): Promise<ActionResult> {\n return this.request('/api/support/update-name', params)\n }\n\n async getClaimedSeats(bulkCouponId: string): Promise<ClaimedSeat[]> {\n return this.request('/api/support/get-claimed-seats', { bulkCouponId })\n }\n\n async searchContent(\n request: ContentSearchRequest\n ): Promise<ContentSearchResponse> {\n return this.request('/api/support/search-content', request)\n }\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AA8BpB,IAAM,oBAAN,MAAsD;AAAA,EAC1C;AAAA,EACA;AAAA,EAEjB,YAAY,QAAoD;AAE9D,SAAK,UAAU,OAAO,QAAQ,QAAQ,OAAO,EAAE;AAC/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,QAAyC;AAC9D,WAAO,KAAK,QAAQ,kCAAkC,EAAE,OAAO,CAAC;AAAA,EAClE;AAAA,EAEA,MAAM,aAAa,QAIO;AACxB,WAAO,KAAK,QAAQ,8BAA8B,MAAM;AAAA,EAC1D;AAAA,EAEA,MAAM,iBAAiB,QAIG;AACxB,WAAO,KAAK,QAAQ,kCAAkC,MAAM;AAAA,EAC9D;AAAA,EAEA,MAAM,kBAAkB,QAGK;AAC3B,WAAO,KAAK,QAAQ,oCAAoC,MAAM;AAAA,EAChE;AAAA,EAEA,MAAM,YAAY,QAGQ;AACxB,WAAO,KAAK,QAAQ,6BAA6B,MAAM;AAAA,EACzD;AAAA,EAEA,MAAM,WAAW,QAGS;AACxB,WAAO,KAAK,QAAQ,4BAA4B,MAAM;AAAA,EACxD;AAAA,EAEA,MAAM,gBAAgB,cAA8C;AAClE,WAAO,KAAK,QAAQ,kCAAkC,EAAE,aAAa,CAAC;AAAA,EACxE;AAAA,EAEA,MAAM,cACJ,SACgC;AAChC,WAAO,KAAK,QAAQ,+BAA+B,OAAO;AAAA,EAC5D;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/client.ts"],"sourcesContent":["import { createHmac } from 'node:crypto'\nimport type {\n ActionResult,\n AppInfo,\n ClaimedSeat,\n ContentAccess,\n ContentSearchRequest,\n ContentSearchResponse,\n CouponInfo,\n LicenseInfo,\n ProductStatus,\n Promotion,\n Purchase,\n RefundPolicy,\n Subscription,\n SupportIntegration,\n User,\n UserActivity,\n} from './integration'\n\n/**\n * Client for calling app integration endpoints with HMAC-signed requests.\n *\n * Used by core to call app-specific support actions (lookupUser, getPurchases, etc.)\n * with Stripe-style HMAC-SHA256 signature verification.\n *\n * @example\n * ```typescript\n * import { IntegrationClient } from '@skillrecordings/sdk/client'\n *\n * const client = new IntegrationClient({\n * baseUrl: 'https://totaltypescript.com',\n * webhookSecret: 'whsec_abc123',\n * })\n *\n * const user = await client.lookupUser('test@example.com')\n * ```\n */\nexport class IntegrationClient implements SupportIntegration {\n private readonly baseUrl: string\n private readonly webhookSecret: string\n\n constructor(config: { baseUrl: string; webhookSecret: string }) {\n // Strip trailing slash for consistent URL construction\n this.baseUrl = config.baseUrl.replace(/\\/$/, '')\n this.webhookSecret = config.webhookSecret\n }\n\n /**\n * Generate HMAC-SHA256 signature for request body.\n * Format: `timestamp=<timestamp>,v1=<signature>`\n *\n * Signature is computed as: HMAC-SHA256(timestamp + \".\" + body, secret)\n */\n private generateSignature(body: string): string {\n const timestamp = Math.floor(Date.now() / 1000)\n const signedPayload = `${timestamp}.${body}`\n const signature = createHmac('sha256', this.webhookSecret)\n .update(signedPayload)\n .digest('hex')\n\n return `timestamp=${timestamp},v1=${signature}`\n }\n\n /**\n * Make signed POST request to app integration endpoint.\n * Uses action-based routing: all requests go to /api/support with action in body.\n */\n private async request<T>(\n action: string,\n payload: Record<string, unknown>\n ): Promise<T> {\n const body = JSON.stringify({ action, ...payload })\n const signature = this.generateSignature(body)\n\n // baseUrl should be the complete endpoint URL (e.g., https://example.com/api/support)\n const response = await fetch(this.baseUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-Support-Signature': signature,\n },\n body,\n })\n\n if (!response.ok) {\n // Try to extract error message from response body\n let errorMessage: string | undefined\n try {\n const errorBody = (await response.json()) as { error?: string }\n if (errorBody?.error) {\n errorMessage = errorBody.error\n }\n } catch {\n // If JSON parsing fails, ignore and use status text\n }\n\n if (errorMessage) {\n throw new Error(errorMessage)\n }\n throw new Error(\n `Integration request failed: ${response.status} ${response.statusText}`\n )\n }\n\n return (await response.json()) as T\n }\n\n /**\n * Make a signed request for an optional method.\n * Returns the fallback value if the app responds with 501 (Not Implemented).\n */\n private async requestOptional<T>(\n action: string,\n payload: Record<string, unknown>,\n fallback: T\n ): Promise<T> {\n const body = JSON.stringify({ action, ...payload })\n const signature = this.generateSignature(body)\n\n const response = await fetch(this.baseUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-Support-Signature': signature,\n },\n body,\n })\n\n // 501 = method not implemented by this app — return fallback gracefully\n if (response.status === 501) {\n return fallback\n }\n\n if (!response.ok) {\n let errorMessage: string | undefined\n try {\n const errorBody = (await response.json()) as { error?: string }\n if (errorBody?.error) {\n errorMessage = errorBody.error\n }\n } catch {\n // If JSON parsing fails, ignore and use status text\n }\n\n if (errorMessage) {\n throw new Error(errorMessage)\n }\n throw new Error(\n `Integration request failed: ${response.status} ${response.statusText}`\n )\n }\n\n return (await response.json()) as T\n }\n\n async lookupUser(email: string): Promise<User | null> {\n return this.request('lookupUser', { email })\n }\n\n async getPurchases(userId: string): Promise<Purchase[]> {\n return this.request('getPurchases', { userId })\n }\n\n async getSubscriptions(userId: string): Promise<Subscription[]> {\n return this.request('getSubscriptions', { userId })\n }\n\n async revokeAccess(params: {\n purchaseId: string\n reason: string\n refundId: string\n }): Promise<ActionResult> {\n return this.request('revokeAccess', params)\n }\n\n async transferPurchase(params: {\n purchaseId: string\n fromUserId: string\n toEmail: string\n }): Promise<ActionResult> {\n return this.request('transferPurchase', params)\n }\n\n async generateMagicLink(params: {\n email: string\n expiresIn: number\n }): Promise<{ url: string }> {\n return this.request('generateMagicLink', params)\n }\n\n async updateEmail(params: {\n userId: string\n newEmail: string\n }): Promise<ActionResult> {\n return this.request('updateEmail', params)\n }\n\n async updateName(params: {\n userId: string\n newName: string\n }): Promise<ActionResult> {\n return this.request('updateName', params)\n }\n\n async getClaimedSeats(bulkCouponId: string): Promise<ClaimedSeat[]> {\n return this.request('getClaimedSeats', { bulkCouponId })\n }\n\n async searchContent(\n request: ContentSearchRequest\n ): Promise<ContentSearchResponse> {\n return this.request(\n 'searchContent',\n request as unknown as Record<string, unknown>\n )\n }\n\n async getProductStatus(productId: string): Promise<ProductStatus | null> {\n return this.request('getProductStatus', { productId })\n }\n\n // ── Agent Intelligence Methods ─────────────────────────────────────\n // These methods handle 501 (Not Implemented) gracefully by returning\n // null or empty arrays, allowing the agent to function even when\n // the app hasn't implemented optional methods.\n\n async getActivePromotions(): Promise<Promotion[]> {\n return this.requestOptional<Promotion[]>('getActivePromotions', {}, [])\n }\n\n async getCouponInfo(code: string): Promise<CouponInfo | null> {\n return this.requestOptional<CouponInfo | null>(\n 'getCouponInfo',\n { code },\n null\n )\n }\n\n async getRefundPolicy(): Promise<RefundPolicy> {\n return this.request('getRefundPolicy', {})\n }\n\n async getContentAccess(userId: string): Promise<ContentAccess> {\n return this.request('getContentAccess', { userId })\n }\n\n async getRecentActivity(userId: string): Promise<UserActivity> {\n return this.request('getRecentActivity', { userId })\n }\n\n async getLicenseInfo(purchaseId: string): Promise<LicenseInfo | null> {\n return this.requestOptional<LicenseInfo | null>(\n 'getLicenseInfo',\n { purchaseId },\n null\n )\n }\n\n async getAppInfo(): Promise<AppInfo> {\n return this.request('getAppInfo', {})\n }\n}\n"],"mappings":";;;AAAA,SAAS,kBAAkB;AAsCpB,IAAM,oBAAN,MAAsD;AAAA,EAC1C;AAAA,EACA;AAAA,EAEjB,YAAY,QAAoD;AAE9D,SAAK,UAAU,OAAO,QAAQ,QAAQ,OAAO,EAAE;AAC/C,SAAK,gBAAgB,OAAO;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQQ,kBAAkB,MAAsB;AAC9C,UAAM,YAAY,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI;AAC9C,UAAM,gBAAgB,GAAG,SAAS,IAAI,IAAI;AAC1C,UAAM,YAAY,WAAW,UAAU,KAAK,aAAa,EACtD,OAAO,aAAa,EACpB,OAAO,KAAK;AAEf,WAAO,aAAa,SAAS,OAAO,SAAS;AAAA,EAC/C;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAc,QACZ,QACA,SACY;AACZ,UAAM,OAAO,KAAK,UAAU,EAAE,QAAQ,GAAG,QAAQ,CAAC;AAClD,UAAM,YAAY,KAAK,kBAAkB,IAAI;AAG7C,UAAM,WAAW,MAAM,MAAM,KAAK,SAAS;AAAA,MACzC,QAAQ;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C;AAC7C,WAAO,KAAK,QAAQ,mBAAmB,CAAC,CAAC;AAAA,EAC3C;AAAA,EAEA,MAAM,iBAAiB,QAAwC;AAC7D,WAAO,KAAK,QAAQ,oBAAoB,EAAE,OAAO,CAAC;AAAA,EACpD;AAAA,EAEA,MAAM,kBAAkB,QAAuC;AAC7D,WAAO,KAAK,QAAQ,qBAAqB,EAAE,OAAO,CAAC;AAAA,EACrD;AAAA,EAEA,MAAM,eAAe,YAAiD;AACpE,WAAO,KAAK;AAAA,MACV;AAAA,MACA,EAAE,WAAW;AAAA,MACb;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,aAA+B;AACnC,WAAO,KAAK,QAAQ,cAAc,CAAC,CAAC;AAAA,EACtC;AACF;","names":[]}
package/dist/handler.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { SupportIntegration } from './integration.js';
2
2
  import './types.js';
3
+ import 'zod';
3
4
 
4
5
  /**
5
6
  * Configuration for createSupportHandler
package/dist/handler.js CHANGED
@@ -1,3 +1,5 @@
1
+ import "./chunk-PZ5AY32C.js";
2
+
1
3
  // src/handler.ts
2
4
  import { timingSafeEqual } from "crypto";
3
5
  function createSupportHandler(config) {
@@ -155,6 +157,92 @@ async function routeAction(integration, action, body) {
155
157
  const result = await integration.searchContent(params);
156
158
  return { data: result, status: 200 };
157
159
  }
160
+ case "getProductStatus": {
161
+ if (!integration.getProductStatus) {
162
+ return {
163
+ data: { error: "Method not implemented: getProductStatus" },
164
+ status: 501
165
+ };
166
+ }
167
+ const productId = body.productId;
168
+ const result = await integration.getProductStatus(productId);
169
+ return { data: result, status: 200 };
170
+ }
171
+ // ── Agent Intelligence Methods ─────────────────────────────────
172
+ case "getActivePromotions": {
173
+ if (!integration.getActivePromotions) {
174
+ return {
175
+ data: { error: "Method not implemented: getActivePromotions" },
176
+ status: 501
177
+ };
178
+ }
179
+ const result = await integration.getActivePromotions();
180
+ return { data: result, status: 200 };
181
+ }
182
+ case "getCouponInfo": {
183
+ if (!integration.getCouponInfo) {
184
+ return {
185
+ data: { error: "Method not implemented: getCouponInfo" },
186
+ status: 501
187
+ };
188
+ }
189
+ const code = body.code;
190
+ const result = await integration.getCouponInfo(code);
191
+ return { data: result, status: 200 };
192
+ }
193
+ case "getRefundPolicy": {
194
+ if (!integration.getRefundPolicy) {
195
+ return {
196
+ data: { error: "Method not implemented: getRefundPolicy" },
197
+ status: 501
198
+ };
199
+ }
200
+ const result = await integration.getRefundPolicy();
201
+ return { data: result, status: 200 };
202
+ }
203
+ case "getContentAccess": {
204
+ if (!integration.getContentAccess) {
205
+ return {
206
+ data: { error: "Method not implemented: getContentAccess" },
207
+ status: 501
208
+ };
209
+ }
210
+ const userId = body.userId;
211
+ const result = await integration.getContentAccess(userId);
212
+ return { data: result, status: 200 };
213
+ }
214
+ case "getRecentActivity": {
215
+ if (!integration.getRecentActivity) {
216
+ return {
217
+ data: { error: "Method not implemented: getRecentActivity" },
218
+ status: 501
219
+ };
220
+ }
221
+ const userId = body.userId;
222
+ const result = await integration.getRecentActivity(userId);
223
+ return { data: result, status: 200 };
224
+ }
225
+ case "getLicenseInfo": {
226
+ if (!integration.getLicenseInfo) {
227
+ return {
228
+ data: { error: "Method not implemented: getLicenseInfo" },
229
+ status: 501
230
+ };
231
+ }
232
+ const purchaseId = body.purchaseId;
233
+ const result = await integration.getLicenseInfo(purchaseId);
234
+ return { data: result, status: 200 };
235
+ }
236
+ case "getAppInfo": {
237
+ if (!integration.getAppInfo) {
238
+ return {
239
+ data: { error: "Method not implemented: getAppInfo" },
240
+ status: 501
241
+ };
242
+ }
243
+ const result = await integration.getAppInfo();
244
+ return { data: result, status: 200 };
245
+ }
158
246
  default:
159
247
  return {
160
248
  data: { error: `Unknown action: ${action}` },
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/handler.ts"],"sourcesContent":["import { timingSafeEqual } from 'crypto'\nimport type { SupportIntegration } from './integration'\nimport type { ContentSearchRequest, ContentSearchResponse } from './types'\n\n/**\n * Configuration for createSupportHandler\n */\nexport interface SupportHandlerConfig {\n integration: SupportIntegration\n webhookSecret: string\n}\n\n/**\n * Request body for webhook actions\n */\ninterface WebhookRequest {\n action: string\n [key: string]: unknown\n}\n\n/**\n * Creates a Next.js API route handler for SupportIntegration.\n * Verifies HMAC-SHA256 signature and routes actions to integration methods.\n *\n * Signature format: timestamp=1234567890,v1=hex_signature\n * Payload to sign: timestamp.JSON.stringify(body)\n * Replay protection: 5 minute window\n *\n * @example\n * ```typescript\n * import { createSupportHandler } from '@skillrecordings/sdk/handler'\n * import { integration } from './integration'\n *\n * export const POST = createSupportHandler({\n * integration,\n * webhookSecret: process.env.SUPPORT_WEBHOOK_SECRET!,\n * })\n * ```\n */\nexport function createSupportHandler(\n config: SupportHandlerConfig\n): (request: Request) => Promise<Response> {\n const { integration, webhookSecret } = config\n\n return async function handler(request: Request): Promise<Response> {\n try {\n // 1. Extract signature header\n const signatureHeader = request.headers.get('x-support-signature')\n if (!signatureHeader) {\n return jsonResponse({ error: 'Missing signature header' }, 401)\n }\n\n // 2. Parse signature header (format: timestamp=1234567890,v1=hex_signature)\n const parts = signatureHeader.split(',')\n const timestampPart = parts.find((p) => p.startsWith('timestamp='))\n const signaturePart = parts.find((p) => p.startsWith('v1='))\n\n if (!timestampPart || !signaturePart) {\n return jsonResponse({ error: 'Invalid signature format' }, 401)\n }\n\n const timestampValue = timestampPart.split('=')[1]\n const signatureValue = signaturePart.split('=')[1]\n\n if (!timestampValue || !signatureValue) {\n return jsonResponse({ error: 'Invalid signature format' }, 401)\n }\n\n const timestamp = parseInt(timestampValue, 10)\n const receivedSignature = signatureValue\n\n // 3. Verify timestamp (replay protection - 5 minute window)\n const now = Math.floor(Date.now() / 1000)\n const maxAge = 300 // 5 minutes in seconds\n if (now - timestamp > maxAge) {\n return jsonResponse({ error: 'Signature expired' }, 401)\n }\n\n // 4. Read and parse body\n const bodyText = await request.text()\n let body: WebhookRequest\n\n try {\n body = JSON.parse(bodyText)\n } catch (err) {\n return jsonResponse({ error: 'Invalid JSON body' }, 400)\n }\n\n // 5. Compute expected signature\n const crypto = await import('crypto')\n const payload = `${timestamp}.${bodyText}`\n const expectedSignature = crypto\n .createHmac('sha256', webhookSecret)\n .update(payload)\n .digest('hex')\n\n // 6. Timing-safe comparison to prevent timing attacks\n if (\n !timingSafeEqual(\n Buffer.from(receivedSignature),\n Buffer.from(expectedSignature)\n )\n ) {\n return jsonResponse({ error: 'Invalid signature' }, 401)\n }\n\n // 7. Extract action field\n const { action } = body\n if (!action || typeof action !== 'string') {\n return jsonResponse({ error: 'Missing action field' }, 400)\n }\n\n // 8. Route to integration method\n const result = await routeAction(integration, action, body)\n return jsonResponse(result.data, result.status)\n } catch (err) {\n const message = err instanceof Error ? err.message : 'Unknown error'\n return jsonResponse({ error: `Internal error: ${message}` }, 500)\n }\n }\n}\n\n/**\n * Routes action to appropriate integration method\n */\nasync function routeAction(\n integration: SupportIntegration,\n action: string,\n body: WebhookRequest\n): Promise<{ data: unknown; status: number }> {\n try {\n switch (action) {\n case 'lookupUser': {\n const email = (body as unknown as { email: string }).email\n const result = await integration.lookupUser(email)\n return { data: result, status: 200 }\n }\n\n case 'getPurchases': {\n const userId = (body as unknown as { userId: string }).userId\n const result = await integration.getPurchases(userId)\n return { data: result, status: 200 }\n }\n\n case 'revokeAccess': {\n const params = body as unknown as {\n purchaseId: string\n reason: string\n refundId: string\n }\n const result = await integration.revokeAccess({\n purchaseId: params.purchaseId,\n reason: params.reason,\n refundId: params.refundId,\n })\n return { data: result, status: 200 }\n }\n\n case 'transferPurchase': {\n const params = body as unknown as {\n purchaseId: string\n fromUserId: string\n toEmail: string\n }\n const result = await integration.transferPurchase({\n purchaseId: params.purchaseId,\n fromUserId: params.fromUserId,\n toEmail: params.toEmail,\n })\n return { data: result, status: 200 }\n }\n\n case 'generateMagicLink': {\n const params = body as unknown as {\n email: string\n expiresIn: number\n }\n const result = await integration.generateMagicLink({\n email: params.email,\n expiresIn: params.expiresIn,\n })\n return { data: result, status: 200 }\n }\n\n // Optional methods\n case 'getSubscriptions': {\n if (!integration.getSubscriptions) {\n return {\n data: { error: 'Method not implemented: getSubscriptions' },\n status: 501,\n }\n }\n const userId = (body as unknown as { userId: string }).userId\n const result = await integration.getSubscriptions(userId)\n return { data: result, status: 200 }\n }\n\n case 'updateEmail': {\n if (!integration.updateEmail) {\n return {\n data: { error: 'Method not implemented: updateEmail' },\n status: 501,\n }\n }\n const params = body as unknown as {\n userId: string\n newEmail: string\n }\n const result = await integration.updateEmail({\n userId: params.userId,\n newEmail: params.newEmail,\n })\n return { data: result, status: 200 }\n }\n\n case 'updateName': {\n if (!integration.updateName) {\n return {\n data: { error: 'Method not implemented: updateName' },\n status: 501,\n }\n }\n const params = body as unknown as {\n userId: string\n newName: string\n }\n const result = await integration.updateName({\n userId: params.userId,\n newName: params.newName,\n })\n return { data: result, status: 200 }\n }\n\n case 'getClaimedSeats': {\n if (!integration.getClaimedSeats) {\n return {\n data: { error: 'Method not implemented: getClaimedSeats' },\n status: 501,\n }\n }\n const bulkCouponId = (body as unknown as { bulkCouponId: string })\n .bulkCouponId\n const result = await integration.getClaimedSeats(bulkCouponId)\n return { data: result, status: 200 }\n }\n\n case 'searchContent': {\n if (!integration.searchContent) {\n return {\n data: { error: 'Method not implemented: searchContent' },\n status: 501,\n }\n }\n const params = body as unknown as ContentSearchRequest\n const result: ContentSearchResponse =\n await integration.searchContent(params)\n return { data: result, status: 200 }\n }\n\n default:\n return {\n data: { error: `Unknown action: ${action}` },\n status: 400,\n }\n }\n } catch (err) {\n const message = err instanceof Error ? err.message : 'Unknown error'\n return {\n data: { error: message },\n status: 500,\n }\n }\n}\n\n/**\n * Helper to create JSON responses\n */\nfunction jsonResponse(data: unknown, status: number): Response {\n return new Response(JSON.stringify(data), {\n status,\n headers: {\n 'content-type': 'application/json',\n },\n })\n}\n"],"mappings":";AAAA,SAAS,uBAAuB;AAuCzB,SAAS,qBACd,QACyC;AACzC,QAAM,EAAE,aAAa,cAAc,IAAI;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MAAM,QAAQ,QAAQ,IAAI;AAAA,MACrC;AAAA,MAEA,KAAK,mBAAmB;AACtB,YAAI,CAAC,YAAY,iBAAiB;AAChC,iBAAO;AAAA,YACL,MAAM,EAAE,OAAO,0CAA0C;AAAA,YACzD,QAAQ;AAAA,UACV;AAAA,QACF;AACA,cAAM,eAAgB,KACnB;AACH,cAAM,SAAS,MAAM,YAAY,gBAAgB,YAAY;AAC7D,eAAO,EAAE,MAAM,QAAQ,QAAQ,IAAI;AAAA,MACrC;AAAA,MAEA,KAAK,iBAAiB;AACpB,YAAI,CAAC,YAAY,eAAe;AAC9B,iBAAO;AAAA,YACL,MAAM,EAAE,OAAO,wCAAwC;AAAA,YACvD,QAAQ;AAAA,UACV;AAAA,QACF;AACA,cAAM,SAAS;AACf,cAAM,SACJ,MAAM,YAAY,cAAc,MAAM;AACxC,eAAO,EAAE,MAAM,QAAQ,QAAQ,IAAI;AAAA,MACrC;AAAA,MAEA;AACE,eAAO;AAAA,UACL,MAAM,EAAE,OAAO,mBAAmB,MAAM,GAAG;AAAA,UAC3C,QAAQ;AAAA,QACV;AAAA,IACJ;AAAA,EACF,SAAS,KAAK;AACZ,UAAM,UAAU,eAAe,QAAQ,IAAI,UAAU;AACrD,WAAO;AAAA,MACL,MAAM,EAAE,OAAO,QAAQ;AAAA,MACvB,QAAQ;AAAA,IACV;AAAA,EACF;AACF;AAKA,SAAS,aAAa,MAAe,QAA0B;AAC7D,SAAO,IAAI,SAAS,KAAK,UAAU,IAAI,GAAG;AAAA,IACxC;AAAA,IACA,SAAS;AAAA,MACP,gBAAgB;AAAA,IAClB;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../src/handler.ts"],"sourcesContent":["import { timingSafeEqual } from 'crypto'\nimport type { SupportIntegration } from './integration'\nimport type { ContentSearchRequest, ContentSearchResponse } from './types'\n\n/**\n * Configuration for createSupportHandler\n */\nexport interface SupportHandlerConfig {\n integration: SupportIntegration\n webhookSecret: string\n}\n\n/**\n * Request body for webhook actions\n */\ninterface WebhookRequest {\n action: string\n [key: string]: unknown\n}\n\n/**\n * Creates a Next.js API route handler for SupportIntegration.\n * Verifies HMAC-SHA256 signature and routes actions to integration methods.\n *\n * Signature format: timestamp=1234567890,v1=hex_signature\n * Payload to sign: timestamp.JSON.stringify(body)\n * Replay protection: 5 minute window\n *\n * @example\n * ```typescript\n * import { createSupportHandler } from '@skillrecordings/sdk/handler'\n * import { integration } from './integration'\n *\n * export const POST = createSupportHandler({\n * integration,\n * webhookSecret: process.env.SUPPORT_WEBHOOK_SECRET!,\n * })\n * ```\n */\nexport function createSupportHandler(\n config: SupportHandlerConfig\n): (request: Request) => Promise<Response> {\n const { integration, webhookSecret } = config\n\n return async function handler(request: Request): Promise<Response> {\n try {\n // 1. Extract signature header\n const signatureHeader = request.headers.get('x-support-signature')\n if (!signatureHeader) {\n return jsonResponse({ error: 'Missing signature header' }, 401)\n }\n\n // 2. Parse signature header (format: timestamp=1234567890,v1=hex_signature)\n const parts = signatureHeader.split(',')\n const timestampPart = parts.find((p) => p.startsWith('timestamp='))\n const signaturePart = parts.find((p) => p.startsWith('v1='))\n\n if (!timestampPart || !signaturePart) {\n return jsonResponse({ error: 'Invalid signature format' }, 401)\n }\n\n const timestampValue = timestampPart.split('=')[1]\n const signatureValue = signaturePart.split('=')[1]\n\n if (!timestampValue || !signatureValue) {\n return jsonResponse({ error: 'Invalid signature format' }, 401)\n }\n\n const timestamp = parseInt(timestampValue, 10)\n const receivedSignature = signatureValue\n\n // 3. Verify timestamp (replay protection - 5 minute window)\n const now = Math.floor(Date.now() / 1000)\n const maxAge = 300 // 5 minutes in seconds\n if (now - timestamp > maxAge) {\n return jsonResponse({ error: 'Signature expired' }, 401)\n }\n\n // 4. Read and parse body\n const bodyText = await request.text()\n let body: WebhookRequest\n\n try {\n body = JSON.parse(bodyText)\n } catch (err) {\n return jsonResponse({ error: 'Invalid JSON body' }, 400)\n }\n\n // 5. Compute expected signature\n const crypto = await import('crypto')\n const payload = `${timestamp}.${bodyText}`\n const expectedSignature = crypto\n .createHmac('sha256', webhookSecret)\n .update(payload)\n .digest('hex')\n\n // 6. Timing-safe comparison to prevent timing attacks\n if (\n !timingSafeEqual(\n Buffer.from(receivedSignature),\n Buffer.from(expectedSignature)\n )\n ) {\n return jsonResponse({ error: 'Invalid signature' }, 401)\n }\n\n // 7. Extract action field\n const { action } = body\n if (!action || typeof action !== 'string') {\n return jsonResponse({ error: 'Missing action field' }, 400)\n }\n\n // 8. Route to integration method\n const result = await routeAction(integration, action, body)\n return jsonResponse(result.data, result.status)\n } catch (err) {\n const message = err instanceof Error ? err.message : 'Unknown error'\n return jsonResponse({ error: `Internal error: ${message}` }, 500)\n }\n }\n}\n\n/**\n * Routes action to appropriate integration method\n */\nasync function routeAction(\n integration: SupportIntegration,\n action: string,\n body: WebhookRequest\n): Promise<{ data: unknown; status: number }> {\n try {\n switch (action) {\n case 'lookupUser': {\n const email = (body as unknown as { email: string }).email\n const result = await integration.lookupUser(email)\n return { data: result, status: 200 }\n }\n\n case 'getPurchases': {\n const userId = (body as unknown as { userId: string }).userId\n const result = await integration.getPurchases(userId)\n return { data: result, status: 200 }\n }\n\n case 'revokeAccess': {\n const params = body as unknown as {\n purchaseId: string\n reason: string\n refundId: string\n }\n const result = await integration.revokeAccess({\n purchaseId: params.purchaseId,\n reason: params.reason,\n refundId: params.refundId,\n })\n return { data: result, status: 200 }\n }\n\n case 'transferPurchase': {\n const params = body as unknown as {\n purchaseId: string\n fromUserId: string\n toEmail: string\n }\n const result = await integration.transferPurchase({\n purchaseId: params.purchaseId,\n fromUserId: params.fromUserId,\n toEmail: params.toEmail,\n })\n return { data: result, status: 200 }\n }\n\n case 'generateMagicLink': {\n const params = body as unknown as {\n email: string\n expiresIn: number\n }\n const result = await integration.generateMagicLink({\n email: params.email,\n expiresIn: params.expiresIn,\n })\n return { data: result, status: 200 }\n }\n\n // Optional methods\n case 'getSubscriptions': {\n if (!integration.getSubscriptions) {\n return {\n data: { error: 'Method not implemented: getSubscriptions' },\n status: 501,\n }\n }\n const userId = (body as unknown as { userId: string }).userId\n const result = await integration.getSubscriptions(userId)\n return { data: result, status: 200 }\n }\n\n case 'updateEmail': {\n if (!integration.updateEmail) {\n return {\n data: { error: 'Method not implemented: updateEmail' },\n status: 501,\n }\n }\n const params = body as unknown as {\n userId: string\n newEmail: string\n }\n const result = await integration.updateEmail({\n userId: params.userId,\n newEmail: params.newEmail,\n })\n return { data: result, status: 200 }\n }\n\n case 'updateName': {\n if (!integration.updateName) {\n return {\n data: { error: 'Method not implemented: updateName' },\n status: 501,\n }\n }\n const params = body as unknown as {\n userId: string\n newName: string\n }\n const result = await integration.updateName({\n userId: params.userId,\n newName: params.newName,\n })\n return { data: result, status: 200 }\n }\n\n case 'getClaimedSeats': {\n if (!integration.getClaimedSeats) {\n return {\n data: { error: 'Method not implemented: getClaimedSeats' },\n status: 501,\n }\n }\n const bulkCouponId = (body as unknown as { bulkCouponId: string })\n .bulkCouponId\n const result = await integration.getClaimedSeats(bulkCouponId)\n return { data: result, status: 200 }\n }\n\n case 'searchContent': {\n if (!integration.searchContent) {\n return {\n data: { error: 'Method not implemented: searchContent' },\n status: 501,\n }\n }\n const params = body as unknown as ContentSearchRequest\n const result: ContentSearchResponse =\n await integration.searchContent(params)\n return { data: result, status: 200 }\n }\n\n case 'getProductStatus': {\n if (!integration.getProductStatus) {\n return {\n data: { error: 'Method not implemented: getProductStatus' },\n status: 501,\n }\n }\n const productId = (body as unknown as { productId: string }).productId\n const result = await integration.getProductStatus(productId)\n return { data: result, status: 200 }\n }\n\n // ── Agent Intelligence Methods ─────────────────────────────────\n\n case 'getActivePromotions': {\n if (!integration.getActivePromotions) {\n return {\n data: { error: 'Method not implemented: getActivePromotions' },\n status: 501,\n }\n }\n const result = await integration.getActivePromotions()\n return { data: result, status: 200 }\n }\n\n case 'getCouponInfo': {\n if (!integration.getCouponInfo) {\n return {\n data: { error: 'Method not implemented: getCouponInfo' },\n status: 501,\n }\n }\n const code = (body as unknown as { code: string }).code\n const result = await integration.getCouponInfo(code)\n return { data: result, status: 200 }\n }\n\n case 'getRefundPolicy': {\n if (!integration.getRefundPolicy) {\n return {\n data: { error: 'Method not implemented: getRefundPolicy' },\n status: 501,\n }\n }\n const result = await integration.getRefundPolicy()\n return { data: result, status: 200 }\n }\n\n case 'getContentAccess': {\n if (!integration.getContentAccess) {\n return {\n data: { error: 'Method not implemented: getContentAccess' },\n status: 501,\n }\n }\n const userId = (body as unknown as { userId: string }).userId\n const result = await integration.getContentAccess(userId)\n return { data: result, status: 200 }\n }\n\n case 'getRecentActivity': {\n if (!integration.getRecentActivity) {\n return {\n data: { error: 'Method not implemented: getRecentActivity' },\n status: 501,\n }\n }\n const userId = (body as unknown as { userId: string }).userId\n const result = await integration.getRecentActivity(userId)\n return { data: result, status: 200 }\n }\n\n case 'getLicenseInfo': {\n if (!integration.getLicenseInfo) {\n return {\n data: { error: 'Method not implemented: getLicenseInfo' },\n status: 501,\n }\n }\n const purchaseId = (body as unknown as { purchaseId: string })\n .purchaseId\n const result = await integration.getLicenseInfo(purchaseId)\n return { data: result, status: 200 }\n }\n\n case 'getAppInfo': {\n if (!integration.getAppInfo) {\n return {\n data: { error: 'Method not implemented: getAppInfo' },\n status: 501,\n }\n }\n const result = await integration.getAppInfo()\n return { data: result, status: 200 }\n }\n\n default:\n return {\n data: { error: `Unknown action: ${action}` },\n status: 400,\n }\n }\n } catch (err) {\n const message = err instanceof Error ? err.message : 'Unknown error'\n return {\n data: { error: message },\n status: 500,\n }\n }\n}\n\n/**\n * Helper to create JSON responses\n */\nfunction jsonResponse(data: unknown, status: number): Response {\n return new Response(JSON.stringify(data), {\n status,\n headers: {\n 'content-type': 'application/json',\n },\n })\n}\n"],"mappings":";;;AAAA,SAAS,uBAAuB;AAuCzB,SAAS,qBACd,QACyC;AACzC,QAAM,EAAE,aAAa,cAAc,IAAI;AAEvC,SAAO,eAAe,QAAQ,SAAqC;AACjE,QAAI;AAEF,YAAM,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AAAA,YACL,MAAM,EAAE,OAAO,qCAAqC;AAAA,YACpD,QAAQ;AAAA,UACV;AAAA,QACF;AACA,cAAM,SAAS,MAAM,YAAY,WAAW;AAC5C,eAAO,EAAE,MAAM,QAAQ,QAAQ,IAAI;AAAA,MACrC;AAAA,MAEA;AACE,eAAO;AAAA,UACL,MAAM,EAAE,OAAO,mBAAmB,MAAM,GAAG;AAAA,UAC3C,QAAQ;AAAA,QACV;AAAA,IACJ;AAAA,EACF,SAAS,KAAK;AACZ,UAAM,UAAU,eAAe,QAAQ,IAAI,UAAU;AACrD,WAAO;AAAA,MACL,MAAM,EAAE,OAAO,QAAQ;AAAA,MACvB,QAAQ;AAAA,IACV;AAAA,EACF;AACF;AAKA,SAAS,aAAa,MAAe,QAA0B;AAC7D,SAAO,IAAI,SAAS,KAAK,UAAU,IAAI,GAAG;AAAA,IACxC;AAAA,IACA,SAAS;AAAA,MACP,gBAAgB;AAAA,IAClB;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -1,5 +1,6 @@
1
- import { User, Purchase, Subscription, ActionResult, ClaimedSeat, ContentSearchRequest, ContentSearchResponse } from './types.js';
1
+ import { User, Purchase, Subscription, ActionResult, ClaimedSeat, ContentSearchRequest, ContentSearchResponse, ProductStatus, Promotion, CouponInfo, RefundPolicy, ContentAccess, UserActivity, LicenseInfo, AppInfo } from './types.js';
2
2
  export { ContentSearchResult } from './types.js';
3
+ import 'zod';
3
4
 
4
5
  /**
5
6
  * SupportIntegration interface that apps must implement.
@@ -167,6 +168,106 @@ interface SupportIntegration {
167
168
  * ```
168
169
  */
169
170
  searchContent?(request: ContentSearchRequest): Promise<ContentSearchResponse>;
171
+ /**
172
+ * Get product availability/inventory status.
173
+ * Optional method - implement to let the agent accurately report availability.
174
+ *
175
+ * IMPORTANT: The agent should call this BEFORE claiming a product is sold out
176
+ * or unavailable. Without this, the agent may give incorrect availability info.
177
+ *
178
+ * @param productId - Product identifier (slug or ID)
179
+ * @returns ProductStatus with availability, inventory, and enrollment info
180
+ *
181
+ * @example
182
+ * ```typescript
183
+ * // Customer asks: "Can I still sign up for the TypeScript workshop?"
184
+ * const status = await integration.getProductStatus('ts-workshop-feb-2026')
185
+ *
186
+ * if (status?.soldOut) {
187
+ * // Agent: "Sorry, this workshop is sold out (0 of 50 seats remaining)"
188
+ * } else if (status?.available && status.quantityRemaining > 0) {
189
+ * // Agent: "Yes! There are still 12 seats available."
190
+ * }
191
+ * ```
192
+ */
193
+ getProductStatus?(productId: string): Promise<ProductStatus | null>;
194
+ /**
195
+ * Get currently active promotions and sales.
196
+ * Optional method - implement to let the agent answer presales pricing questions.
197
+ *
198
+ * @returns Array of active promotions, empty if none
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * // Customer asks: "Do you have any discounts?"
203
+ * const promos = await integration.getActivePromotions()
204
+ * // Agent: "Yes! We have a 30% off summer sale running until August 1st."
205
+ * ```
206
+ */
207
+ getActivePromotions?(): Promise<Promotion[]>;
208
+ /**
209
+ * Look up a coupon or discount code.
210
+ * Optional method - implement to let the agent validate coupon codes.
211
+ *
212
+ * @param code - Coupon code to look up
213
+ * @returns CouponInfo if found, null if code doesn't exist
214
+ *
215
+ * @example
216
+ * ```typescript
217
+ * // Customer asks: "Is the code SUMMER2025 still valid?"
218
+ * const coupon = await integration.getCouponInfo('SUMMER2025')
219
+ * if (coupon?.valid) {
220
+ * // Agent: "Yes, SUMMER2025 gives you 30% off!"
221
+ * }
222
+ * ```
223
+ */
224
+ getCouponInfo?(code: string): Promise<CouponInfo | null>;
225
+ /**
226
+ * Get the app's refund policy configuration.
227
+ * Optional method - implement to give the agent accurate refund window info.
228
+ *
229
+ * Without this, the agent falls back to hardcoded defaults which may be wrong.
230
+ *
231
+ * @returns RefundPolicy with window sizes and conditions
232
+ */
233
+ getRefundPolicy?(): Promise<RefundPolicy>;
234
+ /**
235
+ * Get granular content access for a user.
236
+ * Optional method - implement to let the agent debug access issues precisely.
237
+ *
238
+ * Goes beyond purchase data to show what content a user can actually access,
239
+ * including module-level access and team membership.
240
+ *
241
+ * @param userId - User's unique identifier
242
+ * @returns ContentAccess with per-product and per-module access levels
243
+ */
244
+ getContentAccess?(userId: string): Promise<ContentAccess>;
245
+ /**
246
+ * Get recent user activity and progress.
247
+ * Optional method - implement to let the agent assess product usage.
248
+ *
249
+ * Useful for debugging access issues ("when did they last log in?")
250
+ * and refund triage ("have they used the product?").
251
+ *
252
+ * @param userId - User's unique identifier
253
+ * @returns UserActivity with login, completion, and recent action data
254
+ */
255
+ getRecentActivity?(userId: string): Promise<UserActivity>;
256
+ /**
257
+ * Get team license and seat information for a purchase.
258
+ * Optional method - implement to let the agent answer team/enterprise questions.
259
+ *
260
+ * @param purchaseId - Purchase identifier for the team license
261
+ * @returns LicenseInfo with seat allocation, or null if not a team purchase
262
+ */
263
+ getLicenseInfo?(purchaseId: string): Promise<LicenseInfo | null>;
264
+ /**
265
+ * Get app metadata (name, URLs, instructor info).
266
+ * Optional method - eliminates hardcoded product names and URLs in agent prompts.
267
+ *
268
+ * @returns AppInfo with app name, instructor, and relevant URLs
269
+ */
270
+ getAppInfo?(): Promise<AppInfo>;
170
271
  }
171
272
 
172
- export { ActionResult, ClaimedSeat, ContentSearchRequest, ContentSearchResponse, Purchase, Subscription, type SupportIntegration, User };
273
+ export { ActionResult, AppInfo, ClaimedSeat, ContentAccess, ContentSearchRequest, ContentSearchResponse, CouponInfo, LicenseInfo, ProductStatus, Promotion, Purchase, RefundPolicy, Subscription, type SupportIntegration, User, UserActivity };