skedyul 0.2.146 → 0.2.148

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/.build-stamp CHANGED
@@ -1 +1 @@
1
- 1770617344407
1
+ 1770684891920
package/dist/server.js CHANGED
@@ -878,49 +878,37 @@ function createDedicatedServerInstance(config, tools, callTool, state, mcpServer
878
878
  }
879
879
  return;
880
880
  }
881
- // Handle /oauth_callback endpoint for OAuth callbacks (called by platform route)
882
- if (pathname === '/oauth_callback' && req.method === 'GET') {
881
+ // Handle /oauth_callback endpoint for OAuth callbacks (called by Temporal workflow)
882
+ if (pathname === '/oauth_callback' && req.method === 'POST') {
883
883
  if (!config.hooks?.oauth_callback) {
884
- sendHTML(res, 404, '<html><body><h1>OAuth callback handler not configured</h1></body></html>');
884
+ sendJSON(res, 404, { error: 'OAuth callback handler not configured' });
885
885
  return;
886
886
  }
887
- // Parse query parameters
888
- const url = new URL(req.url || '', `http://${req.headers.host}`);
889
- const query = {};
890
- url.searchParams.forEach((value, key) => {
891
- query[key] = value;
892
- });
893
- // Decode state parameter (contains appInstallationId, workplace, app info)
894
- let stateData = {};
895
- if (query.state) {
896
- try {
897
- stateData = JSON.parse(Buffer.from(query.state, 'base64').toString('utf-8'));
898
- }
899
- catch {
900
- sendHTML(res, 400, '<html><body><h1>Invalid state parameter</h1></body></html>');
901
- return;
902
- }
887
+ let oauthCallbackBody = {};
888
+ try {
889
+ oauthCallbackBody = (await parseJSONBody(req));
903
890
  }
904
- if (!stateData.appInstallationId || !stateData.workplace || !stateData.app) {
905
- sendHTML(res, 400, '<html><body><h1>Missing required state data</h1></body></html>');
891
+ catch {
892
+ sendJSON(res, 400, {
893
+ error: { code: -32700, message: 'Parse error' },
894
+ });
895
+ return;
896
+ }
897
+ if (!oauthCallbackBody.query) {
898
+ sendJSON(res, 400, {
899
+ error: { code: -32602, message: 'Missing query parameter' },
900
+ });
906
901
  return;
907
902
  }
908
- // Get current env vars from request (if any)
909
- // For OAuth callbacks, we might not have env vars yet, so use empty object
910
- const env = {};
911
- const oauthCallbackContext = {
912
- query,
913
- env,
914
- workplace: stateData.workplace,
915
- appInstallationId: stateData.appInstallationId,
916
- app: stateData.app,
917
- };
918
903
  // Build request-scoped config for SDK access
919
- // Use env from process or request if available
904
+ // Use provision-level token from process.env (baked at provisioning time)
920
905
  const oauthCallbackRequestConfig = {
921
906
  baseUrl: process.env.SKEDYUL_API_URL ?? '',
922
907
  apiToken: process.env.SKEDYUL_API_TOKEN ?? '',
923
908
  };
909
+ const oauthCallbackContext = {
910
+ query: oauthCallbackBody.query,
911
+ };
924
912
  try {
925
913
  const oauthCallbackHook = config.hooks.oauth_callback;
926
914
  const oauthCallbackHandler = typeof oauthCallbackHook === 'function'
@@ -929,29 +917,19 @@ function createDedicatedServerInstance(config, tools, callTool, state, mcpServer
929
917
  const result = await (0, client_1.runWithConfig)(oauthCallbackRequestConfig, async () => {
930
918
  return await oauthCallbackHandler(oauthCallbackContext);
931
919
  });
932
- // Return custom HTML if provided, otherwise default success page
933
- const html = result.html ?? `
934
- <html>
935
- <body style="font-family: system-ui; padding: 40px; text-align: center;">
936
- <h1 style="color: #38a169;">✓ Authorization Successful</h1>
937
- <p>You can close this window and return to the app.</p>
938
- </body>
939
- </html>
940
- `;
941
- sendHTML(res, 200, html);
920
+ sendJSON(res, 200, {
921
+ appInstallationId: result.appInstallationId,
922
+ env: result.env ?? {},
923
+ });
942
924
  }
943
925
  catch (err) {
944
926
  const errorMessage = err instanceof Error ? err.message : String(err ?? 'Unknown error');
945
- const errorHtml = `
946
- <html>
947
- <body style="font-family: system-ui; padding: 40px; text-align: center;">
948
- <h1 style="color: #e53e3e;">Authorization Failed</h1>
949
- <p>${errorMessage}</p>
950
- <p>You can close this window.</p>
951
- </body>
952
- </html>
953
- `;
954
- sendHTML(res, 500, errorHtml);
927
+ sendJSON(res, 500, {
928
+ error: {
929
+ code: -32603,
930
+ message: errorMessage,
931
+ },
932
+ });
955
933
  }
956
934
  return;
957
935
  }
@@ -1573,47 +1551,29 @@ function createServerlessInstance(config, tools, callTool, state, mcpServer, reg
1573
1551
  }
1574
1552
  }
1575
1553
  // Handle /oauth_callback endpoint for OAuth callbacks (called by platform route)
1576
- if (path === '/oauth_callback' && method === 'GET') {
1554
+ if (path === '/oauth_callback' && method === 'POST') {
1577
1555
  if (!config.hooks?.oauth_callback) {
1578
- return createResponse(404, { error: 'OAuth callback handler not configured' }, { ...headers, 'Content-Type': 'text/html; charset=utf-8' });
1556
+ return createResponse(404, { error: 'OAuth callback handler not configured' }, headers);
1579
1557
  }
1580
- // Parse query parameters from event
1581
- const query = {};
1582
- if (event.queryStringParameters) {
1583
- Object.entries(event.queryStringParameters).forEach(([key, value]) => {
1584
- if (value)
1585
- query[key] = value;
1586
- });
1558
+ let oauthCallbackBody = {};
1559
+ try {
1560
+ oauthCallbackBody = event.body ? JSON.parse(event.body) : {};
1587
1561
  }
1588
- // Decode state parameter (contains appInstallationId, workplace, app info)
1589
- let stateData = {};
1590
- if (query.state) {
1591
- try {
1592
- stateData = JSON.parse(Buffer.from(query.state, 'base64').toString('utf-8'));
1593
- }
1594
- catch {
1595
- return createResponse(400, { error: 'Invalid state parameter' }, { ...headers, 'Content-Type': 'text/html; charset=utf-8' });
1596
- }
1562
+ catch {
1563
+ return createResponse(400, { error: { code: -32700, message: 'Parse error' } }, headers);
1597
1564
  }
1598
- if (!stateData.appInstallationId || !stateData.workplace || !stateData.app) {
1599
- return createResponse(400, { error: 'Missing required state data' }, { ...headers, 'Content-Type': 'text/html; charset=utf-8' });
1565
+ if (!oauthCallbackBody.query) {
1566
+ return createResponse(400, { error: { code: -32602, message: 'Missing query parameter' } }, headers);
1600
1567
  }
1601
- // Get current env vars from request (if any)
1602
- // For OAuth callbacks, we might not have env vars yet, so use empty object
1603
- const env = {};
1604
- const oauthCallbackContext = {
1605
- query,
1606
- env,
1607
- workplace: stateData.workplace,
1608
- appInstallationId: stateData.appInstallationId,
1609
- app: stateData.app,
1610
- };
1611
1568
  // Build request-scoped config for SDK access
1612
- // Use env from process or request if available
1569
+ // Use provision-level token from process.env (baked at provisioning time)
1613
1570
  const oauthCallbackRequestConfig = {
1614
1571
  baseUrl: process.env.SKEDYUL_API_URL ?? '',
1615
1572
  apiToken: process.env.SKEDYUL_API_TOKEN ?? '',
1616
1573
  };
1574
+ const oauthCallbackContext = {
1575
+ query: oauthCallbackBody.query,
1576
+ };
1617
1577
  try {
1618
1578
  const oauthCallbackHook = config.hooks.oauth_callback;
1619
1579
  const oauthCallbackHandler = typeof oauthCallbackHook === 'function'
@@ -1622,29 +1582,19 @@ function createServerlessInstance(config, tools, callTool, state, mcpServer, reg
1622
1582
  const result = await (0, client_1.runWithConfig)(oauthCallbackRequestConfig, async () => {
1623
1583
  return await oauthCallbackHandler(oauthCallbackContext);
1624
1584
  });
1625
- // Return custom HTML if provided, otherwise default success page
1626
- const html = result.html ?? `
1627
- <html>
1628
- <body style="font-family: system-ui; padding: 40px; text-align: center;">
1629
- <h1 style="color: #38a169;">✓ Authorization Successful</h1>
1630
- <p>You can close this window and return to the app.</p>
1631
- </body>
1632
- </html>
1633
- `;
1634
- return createResponse(200, html, { ...headers, 'Content-Type': 'text/html; charset=utf-8' });
1585
+ return createResponse(200, {
1586
+ appInstallationId: result.appInstallationId,
1587
+ env: result.env ?? {},
1588
+ }, headers);
1635
1589
  }
1636
1590
  catch (err) {
1637
1591
  const errorMessage = err instanceof Error ? err.message : String(err ?? 'Unknown error');
1638
- const errorHtml = `
1639
- <html>
1640
- <body style="font-family: system-ui; padding: 40px; text-align: center;">
1641
- <h1 style="color: #e53e3e;">Authorization Failed</h1>
1642
- <p>${errorMessage}</p>
1643
- <p>You can close this window.</p>
1644
- </body>
1645
- </html>
1646
- `;
1647
- return createResponse(500, errorHtml, { ...headers, 'Content-Type': 'text/html; charset=utf-8' });
1592
+ return createResponse(500, {
1593
+ error: {
1594
+ code: -32603,
1595
+ message: errorMessage,
1596
+ },
1597
+ }, headers);
1648
1598
  }
1649
1599
  }
1650
1600
  if (path === '/health' && method === 'GET') {
package/dist/types.d.ts CHANGED
@@ -246,6 +246,8 @@ export interface InstallHandlerContext {
246
246
  app: {
247
247
  id: string;
248
248
  versionId: string;
249
+ handle: string;
250
+ versionHandle: string;
249
251
  };
250
252
  }
251
253
  export interface InstallHandlerResponseOAuth {
@@ -263,20 +265,10 @@ export type InstallHandlerResult<Hooks extends ServerHooks = ServerHooks> = HasO
263
265
  export type InstallHandler<Hooks extends ServerHooks = ServerHooks> = (ctx: InstallHandlerContext) => Promise<InstallHandlerResult<Hooks>>;
264
266
  export interface OAuthCallbackContext {
265
267
  query: Record<string, string>;
266
- env: Record<string, string>;
267
- workplace: {
268
- id: string;
269
- subdomain: string;
270
- };
271
- appInstallationId: string;
272
- app: {
273
- id: string;
274
- versionId: string;
275
- };
276
268
  }
277
269
  export interface OAuthCallbackResult {
278
270
  env?: Record<string, string>;
279
- html?: string;
271
+ appInstallationId?: string;
280
272
  }
281
273
  export type OAuthCallbackHandler = (ctx: OAuthCallbackContext) => Promise<OAuthCallbackResult>;
282
274
  export interface ProvisionHandlerContext {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skedyul",
3
- "version": "0.2.146",
3
+ "version": "0.2.148",
4
4
  "description": "The Skedyul SDK for Node.js",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",