workos 0.7.3 → 0.8.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.
Files changed (146) hide show
  1. package/README.md +353 -8
  2. package/dist/bin.js +938 -128
  3. package/dist/bin.js.map +1 -1
  4. package/dist/commands/api-key-mgmt.d.ts +16 -0
  5. package/dist/commands/api-key-mgmt.js +96 -0
  6. package/dist/commands/api-key-mgmt.js.map +1 -0
  7. package/dist/commands/audit-log.d.ts +26 -0
  8. package/dist/commands/audit-log.js +155 -0
  9. package/dist/commands/audit-log.js.map +1 -0
  10. package/dist/commands/config.d.ts +3 -0
  11. package/dist/commands/config.js +54 -0
  12. package/dist/commands/config.js.map +1 -0
  13. package/dist/commands/connection.d.ts +13 -0
  14. package/dist/commands/connection.js +94 -0
  15. package/dist/commands/connection.js.map +1 -0
  16. package/dist/commands/debug-sso.d.ts +1 -0
  17. package/dist/commands/debug-sso.js +78 -0
  18. package/dist/commands/debug-sso.js.map +1 -0
  19. package/dist/commands/debug-sync.d.ts +1 -0
  20. package/dist/commands/debug-sync.js +102 -0
  21. package/dist/commands/debug-sync.js.map +1 -0
  22. package/dist/commands/directory.d.ts +27 -0
  23. package/dist/commands/directory.js +174 -0
  24. package/dist/commands/directory.js.map +1 -0
  25. package/dist/commands/env.js +41 -28
  26. package/dist/commands/env.js.map +1 -1
  27. package/dist/commands/event.d.ts +9 -0
  28. package/dist/commands/event.js +43 -0
  29. package/dist/commands/event.js.map +1 -0
  30. package/dist/commands/feature-flag.d.ts +12 -0
  31. package/dist/commands/feature-flag.js +96 -0
  32. package/dist/commands/feature-flag.js.map +1 -0
  33. package/dist/commands/install.js +13 -20
  34. package/dist/commands/install.js.map +1 -1
  35. package/dist/commands/invitation.d.ts +19 -0
  36. package/dist/commands/invitation.js +94 -0
  37. package/dist/commands/invitation.js.map +1 -0
  38. package/dist/commands/membership.d.ts +20 -0
  39. package/dist/commands/membership.js +129 -0
  40. package/dist/commands/membership.js.map +1 -0
  41. package/dist/commands/onboard-user.d.ts +7 -0
  42. package/dist/commands/onboard-user.js +61 -0
  43. package/dist/commands/onboard-user.js.map +1 -0
  44. package/dist/commands/org-domain.d.ts +4 -0
  45. package/dist/commands/org-domain.js +45 -0
  46. package/dist/commands/org-domain.js.map +1 -0
  47. package/dist/commands/organization.d.ts +1 -5
  48. package/dist/commands/organization.js +34 -73
  49. package/dist/commands/organization.js.map +1 -1
  50. package/dist/commands/permission.d.ts +20 -0
  51. package/dist/commands/permission.js +93 -0
  52. package/dist/commands/permission.js.map +1 -0
  53. package/dist/commands/portal.d.ts +7 -0
  54. package/dist/commands/portal.js +26 -0
  55. package/dist/commands/portal.js.map +1 -0
  56. package/dist/commands/role.d.ts +17 -0
  57. package/dist/commands/role.js +122 -0
  58. package/dist/commands/role.js.map +1 -0
  59. package/dist/commands/seed.d.ts +4 -0
  60. package/dist/commands/seed.js +238 -0
  61. package/dist/commands/seed.js.map +1 -0
  62. package/dist/commands/session.d.ts +8 -0
  63. package/dist/commands/session.js +63 -0
  64. package/dist/commands/session.js.map +1 -0
  65. package/dist/commands/setup-org.d.ts +6 -0
  66. package/dist/commands/setup-org.js +99 -0
  67. package/dist/commands/setup-org.js.map +1 -0
  68. package/dist/commands/user.js +35 -71
  69. package/dist/commands/user.js.map +1 -1
  70. package/dist/commands/vault.d.ts +24 -0
  71. package/dist/commands/vault.js +120 -0
  72. package/dist/commands/vault.js.map +1 -0
  73. package/dist/commands/webhook.d.ts +3 -0
  74. package/dist/commands/webhook.js +73 -0
  75. package/dist/commands/webhook.js.map +1 -0
  76. package/dist/dashboard/components/DiffPanel.js.map +1 -1
  77. package/dist/dashboard/lib/logo-frames.js +1 -1
  78. package/dist/dashboard/lib/logo-frames.js.map +1 -1
  79. package/dist/doctor/checks/dashboard.js.map +1 -1
  80. package/dist/doctor/checks/environment.js.map +1 -1
  81. package/dist/integrations/go/index.js +1 -3
  82. package/dist/integrations/go/index.js.map +1 -1
  83. package/dist/lib/adapters/headless-adapter.d.ts +67 -0
  84. package/dist/lib/adapters/headless-adapter.js +263 -0
  85. package/dist/lib/adapters/headless-adapter.js.map +1 -0
  86. package/dist/lib/adapters/index.d.ts +1 -0
  87. package/dist/lib/adapters/index.js +1 -0
  88. package/dist/lib/adapters/index.js.map +1 -1
  89. package/dist/lib/agent-interface.d.ts +3 -11
  90. package/dist/lib/agent-interface.js +1 -13
  91. package/dist/lib/agent-interface.js.map +1 -1
  92. package/dist/lib/api-error-handler.d.ts +6 -0
  93. package/dist/lib/api-error-handler.js +58 -0
  94. package/dist/lib/api-error-handler.js.map +1 -0
  95. package/dist/lib/api-key.js +5 -1
  96. package/dist/lib/api-key.js.map +1 -1
  97. package/dist/lib/config.js.map +1 -1
  98. package/dist/lib/credential-proxy.js +0 -6
  99. package/dist/lib/credential-proxy.js.map +1 -1
  100. package/dist/lib/device-auth.js +1 -1
  101. package/dist/lib/device-auth.js.map +1 -1
  102. package/dist/lib/ensure-auth.js +25 -4
  103. package/dist/lib/ensure-auth.js.map +1 -1
  104. package/dist/lib/installer-core.d.ts +12 -12
  105. package/dist/lib/run-with-core.js +25 -4
  106. package/dist/lib/run-with-core.js.map +1 -1
  107. package/dist/lib/validation/validator.js +0 -1
  108. package/dist/lib/validation/validator.js.map +1 -1
  109. package/dist/lib/workos-client.d.ts +58 -0
  110. package/dist/lib/workos-client.js +137 -0
  111. package/dist/lib/workos-client.js.map +1 -0
  112. package/dist/run.d.ts +7 -0
  113. package/dist/run.js +5 -2
  114. package/dist/run.js.map +1 -1
  115. package/dist/smoke-test.ts +881 -0
  116. package/dist/steps/run-prettier.js +1 -1
  117. package/dist/steps/run-prettier.js.map +1 -1
  118. package/dist/utils/analytics.d.ts +1 -1
  119. package/dist/utils/analytics.js.map +1 -1
  120. package/dist/utils/clack-utils.js +1 -1
  121. package/dist/utils/clack-utils.js.map +1 -1
  122. package/dist/utils/environment.js +8 -0
  123. package/dist/utils/environment.js.map +1 -1
  124. package/dist/utils/exit-codes.d.ts +22 -0
  125. package/dist/utils/exit-codes.js +30 -0
  126. package/dist/utils/exit-codes.js.map +1 -0
  127. package/dist/utils/help-json.d.ts +45 -0
  128. package/dist/utils/help-json.js +1161 -0
  129. package/dist/utils/help-json.js.map +1 -0
  130. package/dist/utils/ndjson.d.ts +16 -0
  131. package/dist/utils/ndjson.js +18 -0
  132. package/dist/utils/ndjson.js.map +1 -0
  133. package/dist/utils/output.d.ts +40 -0
  134. package/dist/utils/output.js +95 -0
  135. package/dist/utils/output.js.map +1 -0
  136. package/dist/utils/package-manager.js +2 -3
  137. package/dist/utils/package-manager.js.map +1 -1
  138. package/dist/utils/register-subcommand.d.ts +7 -0
  139. package/dist/utils/register-subcommand.js +36 -0
  140. package/dist/utils/register-subcommand.js.map +1 -0
  141. package/dist/utils/telemetry-types.d.ts +1 -1
  142. package/dist/utils/telemetry-types.js.map +1 -1
  143. package/dist/utils/types.d.ts +12 -0
  144. package/dist/utils/types.js.map +1 -1
  145. package/package.json +20 -16
  146. package/skills/workos-management/SKILL.md +250 -0
@@ -0,0 +1,26 @@
1
+ export interface AuditLogCreateEventFlags {
2
+ action?: string;
3
+ actorType?: string;
4
+ actorId?: string;
5
+ actorName?: string;
6
+ targets?: string;
7
+ context?: string;
8
+ metadata?: string;
9
+ occurredAt?: string;
10
+ file?: string;
11
+ }
12
+ export declare function runAuditLogCreateEvent(orgId: string, flags: AuditLogCreateEventFlags, apiKey: string, baseUrl?: string): Promise<void>;
13
+ export interface AuditLogExportOptions {
14
+ organizationId: string;
15
+ rangeStart: string;
16
+ rangeEnd: string;
17
+ actions?: string[];
18
+ actorNames?: string[];
19
+ actorIds?: string[];
20
+ targets?: string[];
21
+ }
22
+ export declare function runAuditLogExport(options: AuditLogExportOptions, apiKey: string, baseUrl?: string): Promise<void>;
23
+ export declare function runAuditLogListActions(apiKey: string, baseUrl?: string): Promise<void>;
24
+ export declare function runAuditLogGetSchema(action: string, apiKey: string, baseUrl?: string): Promise<void>;
25
+ export declare function runAuditLogCreateSchema(action: string, filePath: string, apiKey: string, baseUrl?: string): Promise<void>;
26
+ export declare function runAuditLogGetRetention(orgId: string, apiKey: string, baseUrl?: string): Promise<void>;
@@ -0,0 +1,155 @@
1
+ import chalk from 'chalk';
2
+ import { readFile } from 'node:fs/promises';
3
+ import { createWorkOSClient } from '../lib/workos-client.js';
4
+ import { formatTable } from '../utils/table.js';
5
+ import { outputJson, outputSuccess, isJsonMode } from '../utils/output.js';
6
+ import { createApiErrorHandler } from '../lib/api-error-handler.js';
7
+ const handleApiError = createApiErrorHandler('AuditLog');
8
+ export async function runAuditLogCreateEvent(orgId, flags, apiKey, baseUrl) {
9
+ const client = createWorkOSClient(apiKey, baseUrl);
10
+ try {
11
+ let event;
12
+ if (flags.file) {
13
+ const raw = await readFile(flags.file, 'utf-8');
14
+ event = JSON.parse(raw);
15
+ }
16
+ else {
17
+ if (!flags.action || !flags.actorType || !flags.actorId) {
18
+ throw new Error('--action, --actor-type, and --actor-id are required (or use --file)');
19
+ }
20
+ event = {
21
+ action: flags.action,
22
+ occurredAt: flags.occurredAt ? new Date(flags.occurredAt) : new Date(),
23
+ actor: {
24
+ id: flags.actorId,
25
+ type: flags.actorType,
26
+ ...(flags.actorName && { name: flags.actorName }),
27
+ },
28
+ targets: flags.targets ? JSON.parse(flags.targets) : [],
29
+ context: flags.context ? JSON.parse(flags.context) : { location: '0.0.0.0' },
30
+ ...(flags.metadata && { metadata: JSON.parse(flags.metadata) }),
31
+ };
32
+ }
33
+ await client.sdk.auditLogs.createEvent(orgId, event);
34
+ outputSuccess('Created audit log event', { organization_id: orgId, action: event.action });
35
+ }
36
+ catch (error) {
37
+ handleApiError(error);
38
+ }
39
+ }
40
+ const POLL_MAX_ATTEMPTS = 60;
41
+ const POLL_INITIAL_DELAY_MS = 1000;
42
+ const POLL_MAX_DELAY_MS = 30000;
43
+ export async function runAuditLogExport(options, apiKey, baseUrl) {
44
+ const client = createWorkOSClient(apiKey, baseUrl);
45
+ try {
46
+ const exportResult = await client.sdk.auditLogs.createExport({
47
+ organizationId: options.organizationId,
48
+ rangeStart: new Date(options.rangeStart),
49
+ rangeEnd: new Date(options.rangeEnd),
50
+ ...(options.actions && { actions: options.actions }),
51
+ ...(options.actorNames && { actorNames: options.actorNames }),
52
+ ...(options.actorIds && { actorIds: options.actorIds }),
53
+ ...(options.targets && { targets: options.targets }),
54
+ });
55
+ let current = exportResult;
56
+ let delay = POLL_INITIAL_DELAY_MS;
57
+ for (let attempt = 0; attempt < POLL_MAX_ATTEMPTS && current.state === 'pending'; attempt++) {
58
+ if (!isJsonMode()) {
59
+ process.stderr.write('.');
60
+ }
61
+ await new Promise((resolve) => setTimeout(resolve, delay));
62
+ delay = Math.min(delay * 2, POLL_MAX_DELAY_MS);
63
+ current = await client.sdk.auditLogs.getExport(current.id);
64
+ }
65
+ if (!isJsonMode() && current.state !== 'pending') {
66
+ process.stderr.write('\n');
67
+ }
68
+ if (current.state === 'error') {
69
+ throw new Error(`Export failed (id: ${current.id})`);
70
+ }
71
+ if (current.state === 'pending') {
72
+ throw new Error(`Export timed out (id: ${current.id}). Check status later.`);
73
+ }
74
+ if (isJsonMode()) {
75
+ outputJson(current);
76
+ return;
77
+ }
78
+ console.log(chalk.green('Export ready'));
79
+ console.log(` ID: ${current.id}`);
80
+ if (current.url) {
81
+ console.log(` URL: ${current.url}`);
82
+ }
83
+ }
84
+ catch (error) {
85
+ handleApiError(error);
86
+ }
87
+ }
88
+ // ── list-actions ──────────────────────────────────────────────────────
89
+ export async function runAuditLogListActions(apiKey, baseUrl) {
90
+ const client = createWorkOSClient(apiKey, baseUrl);
91
+ try {
92
+ const result = await client.auditLogs.listActions();
93
+ if (isJsonMode()) {
94
+ outputJson(result);
95
+ return;
96
+ }
97
+ if (result.data.length === 0) {
98
+ console.log('No audit log actions found.');
99
+ return;
100
+ }
101
+ const rows = result.data.map((item) => [item.action]);
102
+ console.log(formatTable([{ header: 'Action Name' }], rows));
103
+ }
104
+ catch (error) {
105
+ handleApiError(error);
106
+ }
107
+ }
108
+ // ── get-schema ────────────────────────────────────────────────────────
109
+ export async function runAuditLogGetSchema(action, apiKey, baseUrl) {
110
+ const client = createWorkOSClient(apiKey, baseUrl);
111
+ try {
112
+ const result = await client.auditLogs.getSchema(action);
113
+ if (isJsonMode()) {
114
+ outputJson(result);
115
+ return;
116
+ }
117
+ console.log(chalk.bold(`Schema for ${action}`));
118
+ console.log(JSON.stringify(result, null, 2));
119
+ }
120
+ catch (error) {
121
+ handleApiError(error);
122
+ }
123
+ }
124
+ // ── create-schema ─────────────────────────────────────────────────────
125
+ export async function runAuditLogCreateSchema(action, filePath, apiKey, baseUrl) {
126
+ const client = createWorkOSClient(apiKey, baseUrl);
127
+ try {
128
+ const raw = await readFile(filePath, 'utf-8');
129
+ const schema = JSON.parse(raw);
130
+ const result = await client.sdk.auditLogs.createSchema({
131
+ action,
132
+ ...schema,
133
+ });
134
+ outputSuccess('Created audit log schema', result);
135
+ }
136
+ catch (error) {
137
+ handleApiError(error);
138
+ }
139
+ }
140
+ // ── get-retention ─────────────────────────────────────────────────────
141
+ export async function runAuditLogGetRetention(orgId, apiKey, baseUrl) {
142
+ const client = createWorkOSClient(apiKey, baseUrl);
143
+ try {
144
+ const result = await client.auditLogs.getRetention(orgId);
145
+ if (isJsonMode()) {
146
+ outputJson(result);
147
+ return;
148
+ }
149
+ console.log(`Retention period: ${chalk.bold(String(result.retention_period_in_days))} days`);
150
+ }
151
+ catch (error) {
152
+ handleApiError(error);
153
+ }
154
+ }
155
+ //# sourceMappingURL=audit-log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-log.js","sourceRoot":"","sources":["../../src/commands/audit-log.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAA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,MAAM,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,YAAY,CAAC;YACrD,MAAM;YACN,GAAG,MAAM;SACV,CAAC,CAAC;QAEH,aAAa,CAAC,0BAA0B,EAAE,MAAM,CAAC,CAAC;IACpD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,cAAc,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;AACH,CAAC;AAED,yEAAyE;AAEzE,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,KAAa,EAAE,MAAc,EAAE,OAAgB;IAC3F,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEnD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAE1D,IAAI,UAAU,EAAE,EAAE,CAAC;YACjB,UAAU,CAAC,MAAM,CAAC,CAAC;YACnB,OAAO;QACT,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,qBAAqB,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,wBAAwB,CAAC,CAAC,OAAO,CAAC,CAAC;IAC/F,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,cAAc,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;AACH,CAAC","sourcesContent":["import chalk from 'chalk';\nimport { readFile } from 'node:fs/promises';\nimport type { CreateAuditLogEventOptions } from '@workos-inc/node';\nimport { createWorkOSClient } from '../lib/workos-client.js';\nimport { formatTable } from '../utils/table.js';\nimport { outputJson, outputSuccess, isJsonMode } from '../utils/output.js';\nimport { createApiErrorHandler } from '../lib/api-error-handler.js';\n\nconst handleApiError = createApiErrorHandler('AuditLog');\n\n// ── create-event ──────────────────────────────────────────────────────\n\nexport interface AuditLogCreateEventFlags {\n action?: string;\n actorType?: string;\n actorId?: string;\n actorName?: string;\n targets?: string;\n context?: string;\n metadata?: string;\n occurredAt?: string;\n file?: string;\n}\n\nexport async function runAuditLogCreateEvent(\n orgId: string,\n flags: AuditLogCreateEventFlags,\n apiKey: string,\n baseUrl?: string,\n): Promise<void> {\n const client = createWorkOSClient(apiKey, baseUrl);\n\n try {\n let event: CreateAuditLogEventOptions;\n\n if (flags.file) {\n const raw = await readFile(flags.file, 'utf-8');\n event = JSON.parse(raw);\n } else {\n if (!flags.action || !flags.actorType || !flags.actorId) {\n throw new Error('--action, --actor-type, and --actor-id are required (or use --file)');\n }\n event = {\n action: flags.action,\n occurredAt: flags.occurredAt ? new Date(flags.occurredAt) : new Date(),\n actor: {\n id: flags.actorId,\n type: flags.actorType,\n ...(flags.actorName && { name: flags.actorName }),\n },\n targets: flags.targets ? JSON.parse(flags.targets) : [],\n context: flags.context ? JSON.parse(flags.context) : { location: '0.0.0.0' },\n ...(flags.metadata && { metadata: JSON.parse(flags.metadata) }),\n };\n }\n\n await client.sdk.auditLogs.createEvent(orgId, event);\n outputSuccess('Created audit log event', { organization_id: orgId, action: event.action });\n } catch (error) {\n handleApiError(error);\n }\n}\n\n// ── export ────────────────────────────────────────────────────────────\n\nexport interface AuditLogExportOptions {\n organizationId: string;\n rangeStart: string;\n rangeEnd: string;\n actions?: string[];\n actorNames?: string[];\n actorIds?: string[];\n targets?: string[];\n}\n\nconst POLL_MAX_ATTEMPTS = 60;\nconst POLL_INITIAL_DELAY_MS = 1000;\nconst POLL_MAX_DELAY_MS = 30000;\n\nexport async function runAuditLogExport(\n options: AuditLogExportOptions,\n apiKey: string,\n baseUrl?: string,\n): Promise<void> {\n const client = createWorkOSClient(apiKey, baseUrl);\n\n try {\n const exportResult = await client.sdk.auditLogs.createExport({\n organizationId: options.organizationId,\n rangeStart: new Date(options.rangeStart),\n rangeEnd: new Date(options.rangeEnd),\n ...(options.actions && { actions: options.actions }),\n ...(options.actorNames && { actorNames: options.actorNames }),\n ...(options.actorIds && { actorIds: options.actorIds }),\n ...(options.targets && { targets: options.targets }),\n });\n\n let current = exportResult;\n let delay = POLL_INITIAL_DELAY_MS;\n\n for (let attempt = 0; attempt < POLL_MAX_ATTEMPTS && current.state === 'pending'; attempt++) {\n if (!isJsonMode()) {\n process.stderr.write('.');\n }\n await new Promise((resolve) => setTimeout(resolve, delay));\n delay = Math.min(delay * 2, POLL_MAX_DELAY_MS);\n current = await client.sdk.auditLogs.getExport(current.id);\n }\n\n if (!isJsonMode() && current.state !== 'pending') {\n process.stderr.write('\\n');\n }\n\n if (current.state === 'error') {\n throw new Error(`Export failed (id: ${current.id})`);\n }\n\n if (current.state === 'pending') {\n throw new Error(`Export timed out (id: ${current.id}). Check status later.`);\n }\n\n if (isJsonMode()) {\n outputJson(current);\n return;\n }\n\n console.log(chalk.green('Export ready'));\n console.log(` ID: ${current.id}`);\n if (current.url) {\n console.log(` URL: ${current.url}`);\n }\n } catch (error) {\n handleApiError(error);\n }\n}\n\n// ── list-actions ──────────────────────────────────────────────────────\n\nexport async function runAuditLogListActions(apiKey: string, baseUrl?: string): Promise<void> {\n const client = createWorkOSClient(apiKey, baseUrl);\n\n try {\n const result = await client.auditLogs.listActions();\n\n if (isJsonMode()) {\n outputJson(result);\n return;\n }\n\n if (result.data.length === 0) {\n console.log('No audit log actions found.');\n return;\n }\n\n const rows = result.data.map((item) => [item.action]);\n console.log(formatTable([{ header: 'Action Name' }], rows));\n } catch (error) {\n handleApiError(error);\n }\n}\n\n// ── get-schema ────────────────────────────────────────────────────────\n\nexport async function runAuditLogGetSchema(action: string, apiKey: string, baseUrl?: string): Promise<void> {\n const client = createWorkOSClient(apiKey, baseUrl);\n\n try {\n const result = await client.auditLogs.getSchema(action);\n\n if (isJsonMode()) {\n outputJson(result);\n return;\n }\n\n console.log(chalk.bold(`Schema for ${action}`));\n console.log(JSON.stringify(result, null, 2));\n } catch (error) {\n handleApiError(error);\n }\n}\n\n// ── create-schema ─────────────────────────────────────────────────────\n\nexport async function runAuditLogCreateSchema(\n action: string,\n filePath: string,\n apiKey: string,\n baseUrl?: string,\n): Promise<void> {\n const client = createWorkOSClient(apiKey, baseUrl);\n\n try {\n const raw = await readFile(filePath, 'utf-8');\n const schema = JSON.parse(raw);\n\n const result = await client.sdk.auditLogs.createSchema({\n action,\n ...schema,\n });\n\n outputSuccess('Created audit log schema', result);\n } catch (error) {\n handleApiError(error);\n }\n}\n\n// ── get-retention ─────────────────────────────────────────────────────\n\nexport async function runAuditLogGetRetention(orgId: string, apiKey: string, baseUrl?: string): Promise<void> {\n const client = createWorkOSClient(apiKey, baseUrl);\n\n try {\n const result = await client.auditLogs.getRetention(orgId);\n\n if (isJsonMode()) {\n outputJson(result);\n return;\n }\n\n console.log(`Retention period: ${chalk.bold(String(result.retention_period_in_days))} days`);\n } catch (error) {\n handleApiError(error);\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ export declare function runConfigRedirectAdd(uri: string, apiKey: string, baseUrl?: string): Promise<void>;
2
+ export declare function runConfigCorsAdd(origin: string, apiKey: string, baseUrl?: string): Promise<void>;
3
+ export declare function runConfigHomepageUrlSet(url: string, apiKey: string, baseUrl?: string): Promise<void>;
@@ -0,0 +1,54 @@
1
+ import chalk from 'chalk';
2
+ import { createWorkOSClient } from '../lib/workos-client.js';
3
+ import { outputSuccess, isJsonMode } from '../utils/output.js';
4
+ import { createApiErrorHandler } from '../lib/api-error-handler.js';
5
+ const handleApiError = createApiErrorHandler('Config');
6
+ export async function runConfigRedirectAdd(uri, apiKey, baseUrl) {
7
+ const client = createWorkOSClient(apiKey, baseUrl);
8
+ try {
9
+ const result = await client.redirectUris.add(uri);
10
+ if (result.alreadyExists) {
11
+ if (isJsonMode()) {
12
+ outputSuccess('Redirect URI already exists', { uri, alreadyExists: true });
13
+ }
14
+ else {
15
+ console.log(chalk.yellow('Redirect URI already exists (no change)'));
16
+ }
17
+ return;
18
+ }
19
+ outputSuccess('Added redirect URI', { uri });
20
+ }
21
+ catch (error) {
22
+ handleApiError(error);
23
+ }
24
+ }
25
+ export async function runConfigCorsAdd(origin, apiKey, baseUrl) {
26
+ const client = createWorkOSClient(apiKey, baseUrl);
27
+ try {
28
+ const result = await client.corsOrigins.add(origin);
29
+ if (result.alreadyExists) {
30
+ if (isJsonMode()) {
31
+ outputSuccess('CORS origin already exists', { origin, alreadyExists: true });
32
+ }
33
+ else {
34
+ console.log(chalk.yellow('CORS origin already exists (no change)'));
35
+ }
36
+ return;
37
+ }
38
+ outputSuccess('Added CORS origin', { origin });
39
+ }
40
+ catch (error) {
41
+ handleApiError(error);
42
+ }
43
+ }
44
+ export async function runConfigHomepageUrlSet(url, apiKey, baseUrl) {
45
+ const client = createWorkOSClient(apiKey, baseUrl);
46
+ try {
47
+ await client.homepageUrl.set(url);
48
+ outputSuccess('Set homepage URL', { url });
49
+ }
50
+ catch (error) {
51
+ handleApiError(error);
52
+ }
53
+ }
54
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,MAAM,cAAc,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAC;AAEvD,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,GAAW,EAAE,MAAc,EAAE,OAAgB;IACtF,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEnD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAElD,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;YACzB,IAAI,UAAU,EAAE,EAAE,CAAC;gBACjB,aAAa,CAAC,6BAA6B,EAAE,EAAE,GAAG,EA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AAM,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAClC,aAAa,CAAC,kBAAkB,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;IAC7C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,cAAc,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;AACH,CAAC","sourcesContent":["import chalk from 'chalk';\nimport { createWorkOSClient } from '../lib/workos-client.js';\nimport { outputSuccess, isJsonMode } from '../utils/output.js';\nimport { createApiErrorHandler } from '../lib/api-error-handler.js';\n\nconst handleApiError = createApiErrorHandler('Config');\n\nexport async function runConfigRedirectAdd(uri: string, apiKey: string, baseUrl?: string): Promise<void> {\n const client = createWorkOSClient(apiKey, baseUrl);\n\n try {\n const result = await client.redirectUris.add(uri);\n\n if (result.alreadyExists) {\n if (isJsonMode()) {\n outputSuccess('Redirect URI already exists', { uri, alreadyExists: true });\n } else {\n console.log(chalk.yellow('Redirect URI already exists (no change)'));\n }\n return;\n }\n\n outputSuccess('Added redirect URI', { uri });\n } catch (error) {\n handleApiError(error);\n }\n}\n\nexport async function runConfigCorsAdd(origin: string, apiKey: string, baseUrl?: string): Promise<void> {\n const client = createWorkOSClient(apiKey, baseUrl);\n\n try {\n const result = await client.corsOrigins.add(origin);\n\n if (result.alreadyExists) {\n if (isJsonMode()) {\n outputSuccess('CORS origin already exists', { origin, alreadyExists: true });\n } else {\n console.log(chalk.yellow('CORS origin already exists (no change)'));\n }\n return;\n }\n\n outputSuccess('Added CORS origin', { origin });\n } catch (error) {\n handleApiError(error);\n }\n}\n\nexport async function runConfigHomepageUrlSet(url: string, apiKey: string, baseUrl?: string): Promise<void> {\n const client = createWorkOSClient(apiKey, baseUrl);\n\n try {\n await client.homepageUrl.set(url);\n outputSuccess('Set homepage URL', { url });\n } catch (error) {\n handleApiError(error);\n }\n}\n"]}
@@ -0,0 +1,13 @@
1
+ export interface ConnectionListOptions {
2
+ organizationId?: string;
3
+ connectionType?: string;
4
+ limit?: number;
5
+ before?: string;
6
+ after?: string;
7
+ order?: string;
8
+ }
9
+ export declare function runConnectionList(options: ConnectionListOptions, apiKey: string, baseUrl?: string): Promise<void>;
10
+ export declare function runConnectionGet(id: string, apiKey: string, baseUrl?: string): Promise<void>;
11
+ export declare function runConnectionDelete(id: string, options: {
12
+ force?: boolean;
13
+ }, apiKey: string, baseUrl?: string): Promise<void>;
@@ -0,0 +1,94 @@
1
+ import chalk from 'chalk';
2
+ import { createWorkOSClient } from '../lib/workos-client.js';
3
+ import { formatTable } from '../utils/table.js';
4
+ import { outputSuccess, outputJson, isJsonMode, exitWithError } from '../utils/output.js';
5
+ import { createApiErrorHandler } from '../lib/api-error-handler.js';
6
+ import { isNonInteractiveEnvironment } from '../utils/environment.js';
7
+ import clack from '../utils/clack.js';
8
+ const handleApiError = createApiErrorHandler('Connection');
9
+ export async function runConnectionList(options, apiKey, baseUrl) {
10
+ const client = createWorkOSClient(apiKey, baseUrl);
11
+ try {
12
+ const result = await client.sdk.sso.listConnections({
13
+ ...(options.organizationId && { organizationId: options.organizationId }),
14
+ ...(options.connectionType && { connectionType: options.connectionType }),
15
+ limit: options.limit,
16
+ before: options.before,
17
+ after: options.after,
18
+ order: options.order,
19
+ });
20
+ if (isJsonMode()) {
21
+ outputJson({ data: result.data, listMetadata: result.listMetadata });
22
+ return;
23
+ }
24
+ if (result.data.length === 0) {
25
+ console.log('No connections found.');
26
+ return;
27
+ }
28
+ const rows = result.data.map((conn) => [
29
+ conn.id,
30
+ conn.name,
31
+ conn.type,
32
+ conn.organizationId || chalk.dim('-'),
33
+ conn.state,
34
+ conn.createdAt,
35
+ ]);
36
+ console.log(formatTable([
37
+ { header: 'ID' },
38
+ { header: 'Name' },
39
+ { header: 'Type' },
40
+ { header: 'Org ID' },
41
+ { header: 'State' },
42
+ { header: 'Created' },
43
+ ], rows));
44
+ const { before, after } = result.listMetadata;
45
+ if (before && after) {
46
+ console.log(chalk.dim(`Before: ${before} After: ${after}`));
47
+ }
48
+ else if (before) {
49
+ console.log(chalk.dim(`Before: ${before}`));
50
+ }
51
+ else if (after) {
52
+ console.log(chalk.dim(`After: ${after}`));
53
+ }
54
+ }
55
+ catch (error) {
56
+ handleApiError(error);
57
+ }
58
+ }
59
+ export async function runConnectionGet(id, apiKey, baseUrl) {
60
+ const client = createWorkOSClient(apiKey, baseUrl);
61
+ try {
62
+ const connection = await client.sdk.sso.getConnection(id);
63
+ outputJson(connection);
64
+ }
65
+ catch (error) {
66
+ handleApiError(error);
67
+ }
68
+ }
69
+ export async function runConnectionDelete(id, options, apiKey, baseUrl) {
70
+ if (!options.force) {
71
+ if (isNonInteractiveEnvironment()) {
72
+ exitWithError({
73
+ code: 'confirmation_required',
74
+ message: 'Destructive operation requires --force flag in non-interactive mode.',
75
+ });
76
+ }
77
+ const confirmed = await clack.confirm({
78
+ message: `Delete connection ${id}? This cannot be undone.`,
79
+ });
80
+ if (clack.isCancel(confirmed) || !confirmed) {
81
+ console.log('Delete cancelled.');
82
+ return;
83
+ }
84
+ }
85
+ const client = createWorkOSClient(apiKey, baseUrl);
86
+ try {
87
+ await client.sdk.sso.deleteConnection(id);
88
+ outputSuccess('Deleted connection', { id });
89
+ }
90
+ catch (error) {
91
+ handleApiError(error);
92
+ }
93
+ }
94
+ //# sourceMappingURL=connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/commands/connection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC1F,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAC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,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,cAAc,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,EAAU,EACV,OAA4B,EAC5B,MAAc,EACd,OAAgB;IAEhB,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACnB,IAAI,2BAA2B,EAAE,EAAE,CAAC;YAClC,aAAa,CAAC;gBACZ,IAAI,EAAE,uBAAuB;gBAC7B,OAAO,EAAE,sEAAsE;aAChF,CAAC,CAAC;QACL,CAAC;QAED,MAAM,SAAS,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC;YACpC,OAAO,EAAE,qBAAqB,EAAE,0BAA0B;SAC3D,CAAC,CAAC;QAEH,IAAI,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YAC5C,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;YACjC,OAAO;QACT,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEnD,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC;QAC1C,aAAa,CAAC,oBAAoB,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IAC9C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,cAAc,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;AACH,CAAC","sourcesContent":["import chalk from 'chalk';\nimport type { ConnectionType } from '@workos-inc/node';\nimport { createWorkOSClient } from '../lib/workos-client.js';\nimport { formatTable } from '../utils/table.js';\nimport { outputSuccess, outputJson, isJsonMode, exitWithError } from '../utils/output.js';\nimport { createApiErrorHandler } from '../lib/api-error-handler.js';\nimport { isNonInteractiveEnvironment } from '../utils/environment.js';\nimport clack from '../utils/clack.js';\n\nconst handleApiError = createApiErrorHandler('Connection');\n\nexport interface ConnectionListOptions {\n organizationId?: string;\n connectionType?: string;\n limit?: number;\n before?: string;\n after?: string;\n order?: string;\n}\n\nexport async function runConnectionList(\n options: ConnectionListOptions,\n apiKey: string,\n baseUrl?: string,\n): Promise<void> {\n const client = createWorkOSClient(apiKey, baseUrl);\n\n try {\n const result = await client.sdk.sso.listConnections({\n ...(options.organizationId && { organizationId: options.organizationId }),\n ...(options.connectionType && { connectionType: options.connectionType as ConnectionType }),\n limit: options.limit,\n before: options.before,\n after: options.after,\n order: options.order as 'asc' | 'desc' | undefined,\n });\n\n if (isJsonMode()) {\n outputJson({ data: result.data, listMetadata: result.listMetadata });\n return;\n }\n\n if (result.data.length === 0) {\n console.log('No connections found.');\n return;\n }\n\n const rows = result.data.map((conn) => [\n conn.id,\n conn.name,\n conn.type,\n conn.organizationId || chalk.dim('-'),\n conn.state,\n conn.createdAt,\n ]);\n\n console.log(\n formatTable(\n [\n { header: 'ID' },\n { header: 'Name' },\n { header: 'Type' },\n { header: 'Org ID' },\n { header: 'State' },\n { header: 'Created' },\n ],\n rows,\n ),\n );\n\n const { before, after } = result.listMetadata;\n if (before && after) {\n console.log(chalk.dim(`Before: ${before} After: ${after}`));\n } else if (before) {\n console.log(chalk.dim(`Before: ${before}`));\n } else if (after) {\n console.log(chalk.dim(`After: ${after}`));\n }\n } catch (error) {\n handleApiError(error);\n }\n}\n\nexport async function runConnectionGet(id: string, apiKey: string, baseUrl?: string): Promise<void> {\n const client = createWorkOSClient(apiKey, baseUrl);\n\n try {\n const connection = await client.sdk.sso.getConnection(id);\n outputJson(connection);\n } catch (error) {\n handleApiError(error);\n }\n}\n\nexport async function runConnectionDelete(\n id: string,\n options: { force?: boolean },\n apiKey: string,\n baseUrl?: string,\n): Promise<void> {\n if (!options.force) {\n if (isNonInteractiveEnvironment()) {\n exitWithError({\n code: 'confirmation_required',\n message: 'Destructive operation requires --force flag in non-interactive mode.',\n });\n }\n\n const confirmed = await clack.confirm({\n message: `Delete connection ${id}? This cannot be undone.`,\n });\n\n if (clack.isCancel(confirmed) || !confirmed) {\n console.log('Delete cancelled.');\n return;\n }\n }\n\n const client = createWorkOSClient(apiKey, baseUrl);\n\n try {\n await client.sdk.sso.deleteConnection(id);\n outputSuccess('Deleted connection', { id });\n } catch (error) {\n handleApiError(error);\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare function runDebugSso(connectionId: string, apiKey: string, baseUrl?: string): Promise<void>;
@@ -0,0 +1,78 @@
1
+ import chalk from 'chalk';
2
+ import { createWorkOSClient } from '../lib/workos-client.js';
3
+ import { outputJson, isJsonMode } from '../utils/output.js';
4
+ import { createApiErrorHandler } from '../lib/api-error-handler.js';
5
+ const handleApiError = createApiErrorHandler('Connection');
6
+ export async function runDebugSso(connectionId, apiKey, baseUrl) {
7
+ const client = createWorkOSClient(apiKey, baseUrl);
8
+ try {
9
+ // 1. Get connection details
10
+ const connection = await client.sdk.sso.getConnection(connectionId);
11
+ const issues = [];
12
+ // 2. Check for common issues
13
+ if (connection.state !== 'active') {
14
+ issues.push(`Connection is ${connection.state} (not active)`);
15
+ }
16
+ // 3. List recent authentication events
17
+ let recentEvents = [];
18
+ try {
19
+ const events = await client.sdk.events.listEvents({
20
+ events: [
21
+ 'authentication.email_verification_succeeded',
22
+ 'authentication.magic_auth_succeeded',
23
+ 'authentication.sso_succeeded',
24
+ ],
25
+ ...(connection.organizationId && { organizationId: connection.organizationId }),
26
+ limit: 5,
27
+ });
28
+ recentEvents = events.data.map((e) => ({ id: e.id, event: e.event, createdAt: e.createdAt }));
29
+ }
30
+ catch {
31
+ // Events may not be available
32
+ }
33
+ if (isJsonMode()) {
34
+ outputJson({
35
+ connection: {
36
+ id: connection.id,
37
+ name: connection.name,
38
+ type: connection.type,
39
+ state: connection.state,
40
+ organizationId: connection.organizationId,
41
+ createdAt: connection.createdAt,
42
+ },
43
+ recentEvents,
44
+ issues,
45
+ });
46
+ return;
47
+ }
48
+ // 4. Human-readable diagnosis
49
+ console.log(chalk.bold(`SSO Connection: ${connection.name}`));
50
+ console.log(` ID: ${connection.id}`);
51
+ console.log(` Type: ${connection.type}`);
52
+ console.log(` State: ${connection.state === 'active' ? chalk.green('active') : chalk.yellow(connection.state)}`);
53
+ console.log(` Organization: ${connection.organizationId || chalk.dim('none')}`);
54
+ console.log(` Created: ${connection.createdAt}`);
55
+ if (recentEvents.length > 0) {
56
+ console.log(chalk.bold('\nRecent auth events:'));
57
+ for (const event of recentEvents) {
58
+ console.log(` ${event.event} (${event.createdAt})`);
59
+ }
60
+ }
61
+ else {
62
+ console.log(chalk.dim('\nNo recent authentication events found.'));
63
+ }
64
+ if (issues.length > 0) {
65
+ console.log(chalk.bold('\nIssues found:'));
66
+ for (const issue of issues) {
67
+ console.log(chalk.yellow(` ⚠ ${issue}`));
68
+ }
69
+ }
70
+ else {
71
+ console.log(chalk.green('\nNo issues detected.'));
72
+ }
73
+ }
74
+ catch (error) {
75
+ handleApiError(error);
76
+ }
77
+ }
78
+ //# sourceMappingURL=debug-sso.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug-sso.js","sourceRoot":"","sources":["../../src/commands/debug-sso.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,MAAM,cAAc,GAAG,qBAAqB,CAAC,YAAY,CAAC,CAAC;AAE3D,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,YAAoB,EAAE,MAAc,EAAE,OAAgB;IACtF,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEnD,IAAI,CAAC;QACH,4BAA4B;QAC5B,MAAM,UAAU,GAAG,MAAM,MAAM,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AAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;gBAC3B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC;YAC5C,CAAC;QACH,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,cAAc,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;AACH,CAAC","sourcesContent":["import chalk from 'chalk';\nimport type { EventName } from '@workos-inc/node';\nimport { createWorkOSClient } from '../lib/workos-client.js';\nimport { outputJson, isJsonMode } from '../utils/output.js';\nimport { createApiErrorHandler } from '../lib/api-error-handler.js';\n\nconst handleApiError = createApiErrorHandler('Connection');\n\nexport async function runDebugSso(connectionId: string, apiKey: string, baseUrl?: string): Promise<void> {\n const client = createWorkOSClient(apiKey, baseUrl);\n\n try {\n // 1. Get connection details\n const connection = await client.sdk.sso.getConnection(connectionId);\n\n const issues: string[] = [];\n\n // 2. Check for common issues\n if (connection.state !== 'active') {\n issues.push(`Connection is ${connection.state} (not active)`);\n }\n\n // 3. List recent authentication events\n let recentEvents: Array<{ id: string; event: string; createdAt: string }> = [];\n try {\n const events = await client.sdk.events.listEvents({\n events: [\n 'authentication.email_verification_succeeded',\n 'authentication.magic_auth_succeeded',\n 'authentication.sso_succeeded',\n ] as EventName[],\n ...(connection.organizationId && { organizationId: connection.organizationId }),\n limit: 5,\n });\n recentEvents = events.data.map((e) => ({ id: e.id, event: e.event, createdAt: e.createdAt }));\n } catch {\n // Events may not be available\n }\n\n if (isJsonMode()) {\n outputJson({\n connection: {\n id: connection.id,\n name: connection.name,\n type: connection.type,\n state: connection.state,\n organizationId: connection.organizationId,\n createdAt: connection.createdAt,\n },\n recentEvents,\n issues,\n });\n return;\n }\n\n // 4. Human-readable diagnosis\n console.log(chalk.bold(`SSO Connection: ${connection.name}`));\n console.log(` ID: ${connection.id}`);\n console.log(` Type: ${connection.type}`);\n console.log(` State: ${connection.state === 'active' ? chalk.green('active') : chalk.yellow(connection.state)}`);\n console.log(` Organization: ${connection.organizationId || chalk.dim('none')}`);\n console.log(` Created: ${connection.createdAt}`);\n\n if (recentEvents.length > 0) {\n console.log(chalk.bold('\\nRecent auth events:'));\n for (const event of recentEvents) {\n console.log(` ${event.event} (${event.createdAt})`);\n }\n } else {\n console.log(chalk.dim('\\nNo recent authentication events found.'));\n }\n\n if (issues.length > 0) {\n console.log(chalk.bold('\\nIssues found:'));\n for (const issue of issues) {\n console.log(chalk.yellow(` ⚠ ${issue}`));\n }\n } else {\n console.log(chalk.green('\\nNo issues detected.'));\n }\n } catch (error) {\n handleApiError(error);\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare function runDebugSync(directoryId: string, apiKey: string, baseUrl?: string): Promise<void>;
@@ -0,0 +1,102 @@
1
+ import chalk from 'chalk';
2
+ import { createWorkOSClient } from '../lib/workos-client.js';
3
+ import { outputJson, isJsonMode } from '../utils/output.js';
4
+ import { createApiErrorHandler } from '../lib/api-error-handler.js';
5
+ const handleApiError = createApiErrorHandler('Directory');
6
+ export async function runDebugSync(directoryId, apiKey, baseUrl) {
7
+ const client = createWorkOSClient(apiKey, baseUrl);
8
+ try {
9
+ // 1. Get directory details
10
+ const directory = await client.sdk.directorySync.getDirectory(directoryId);
11
+ const issues = [];
12
+ // 2. Check state
13
+ if (String(directory.state) !== 'linked') {
14
+ issues.push(`Directory is ${directory.state} (not linked)`);
15
+ }
16
+ // 3. Count users and groups
17
+ let userCount = 0;
18
+ let groupCount = 0;
19
+ try {
20
+ const users = await client.sdk.directorySync.listUsers({ directory: directoryId, limit: 1 });
21
+ userCount = users.data.length;
22
+ // If there's pagination, there are more
23
+ if (users.listMetadata.after)
24
+ userCount = -1; // indicates "more than 1"
25
+ }
26
+ catch {
27
+ // May not have access
28
+ }
29
+ try {
30
+ const groups = await client.sdk.directorySync.listGroups({ directory: directoryId, limit: 1 });
31
+ groupCount = groups.data.length;
32
+ if (groups.listMetadata.after)
33
+ groupCount = -1;
34
+ }
35
+ catch {
36
+ // May not have access
37
+ }
38
+ // 4. List recent sync events
39
+ let recentEvents = [];
40
+ try {
41
+ const events = await client.sdk.events.listEvents({
42
+ events: ['dsync.user.created', 'dsync.user.updated', 'dsync.group.created'],
43
+ ...(directory.organizationId && { organizationId: directory.organizationId }),
44
+ limit: 5,
45
+ });
46
+ recentEvents = events.data.map((e) => ({ id: e.id, event: e.event, createdAt: e.createdAt }));
47
+ }
48
+ catch {
49
+ // Events may not be available
50
+ }
51
+ if (recentEvents.length === 0) {
52
+ issues.push('No recent sync events found — sync may be stalled');
53
+ }
54
+ if (isJsonMode()) {
55
+ outputJson({
56
+ directory: {
57
+ id: directory.id,
58
+ name: directory.name,
59
+ type: directory.type,
60
+ state: directory.state,
61
+ organizationId: directory.organizationId,
62
+ createdAt: directory.createdAt,
63
+ },
64
+ userCount: userCount === -1 ? '1+' : userCount,
65
+ groupCount: groupCount === -1 ? '1+' : groupCount,
66
+ recentEvents,
67
+ issues,
68
+ });
69
+ return;
70
+ }
71
+ // 5. Human-readable diagnosis
72
+ console.log(chalk.bold(`Directory Sync: ${directory.name}`));
73
+ console.log(` ID: ${directory.id}`);
74
+ console.log(` Type: ${directory.type}`);
75
+ console.log(` State: ${String(directory.state) === 'linked' ? chalk.green('linked') : chalk.yellow(directory.state)}`);
76
+ console.log(` Organization: ${directory.organizationId || chalk.dim('none')}`);
77
+ console.log(` Users: ${userCount === -1 ? '1+' : userCount}`);
78
+ console.log(` Groups: ${groupCount === -1 ? '1+' : groupCount}`);
79
+ if (recentEvents.length > 0) {
80
+ console.log(chalk.bold('\nRecent sync events:'));
81
+ for (const event of recentEvents) {
82
+ console.log(` ${event.event} (${event.createdAt})`);
83
+ }
84
+ }
85
+ else {
86
+ console.log(chalk.dim('\nNo recent sync events found.'));
87
+ }
88
+ if (issues.length > 0) {
89
+ console.log(chalk.bold('\nIssues found:'));
90
+ for (const issue of issues) {
91
+ console.log(chalk.yellow(` ⚠ ${issue}`));
92
+ }
93
+ }
94
+ else {
95
+ console.log(chalk.green('\nNo issues detected.'));
96
+ }
97
+ }
98
+ catch (error) {
99
+ handleApiError(error);
100
+ }
101
+ }
102
+ //# sourceMappingURL=debug-sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug-sync.js","sourceRoot":"","sources":["../../src/commands/debug-sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,MAAM,cAAc,GAAG,qBAAqB,CAAC,WAAW,CAAC,CAAC;AAE1D,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,WAAmB,EAAE,MAAc,EAAE,OAAgB;IACtF,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEnD,IAAI,CAAC;QACH,2BAA2B;QAC3B,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;QAE3E,MAAM,MAAM,GAAa,EAAE,CAAC;QAE5B,iBAAiB;QACjB,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,QAAQ,EAAE,CAAC;YACzC,MAAM,CAAC,IAAI,CAAC,gBAAgB,SAAS,CAAC,KAAK,eAAe,CAAC,CAAC;QAC9D,CAAC;QAED,4BAA4B;QAC5B,IAAI,SAAS,GAAG,CAAC,CAAC;QAClB,IAAI,UAAU,GAAG,CAAC,CAAC;QACnB,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,GAAG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AAK,CAAC,CAAC;IACxB,CAAC;AACH,CAAC","sourcesContent":["import chalk from 'chalk';\nimport type { EventName } from '@workos-inc/node';\nimport { createWorkOSClient } from '../lib/workos-client.js';\nimport { outputJson, isJsonMode } from '../utils/output.js';\nimport { createApiErrorHandler } from '../lib/api-error-handler.js';\n\nconst handleApiError = createApiErrorHandler('Directory');\n\nexport async function runDebugSync(directoryId: string, apiKey: string, baseUrl?: string): Promise<void> {\n const client = createWorkOSClient(apiKey, baseUrl);\n\n try {\n // 1. Get directory details\n const directory = await client.sdk.directorySync.getDirectory(directoryId);\n\n const issues: string[] = [];\n\n // 2. Check state\n if (String(directory.state) !== 'linked') {\n issues.push(`Directory is ${directory.state} (not linked)`);\n }\n\n // 3. Count users and groups\n let userCount = 0;\n let groupCount = 0;\n try {\n const users = await client.sdk.directorySync.listUsers({ directory: directoryId, limit: 1 });\n userCount = users.data.length;\n // If there's pagination, there are more\n if (users.listMetadata.after) userCount = -1; // indicates \"more than 1\"\n } catch {\n // May not have access\n }\n\n try {\n const groups = await client.sdk.directorySync.listGroups({ directory: directoryId, limit: 1 });\n groupCount = groups.data.length;\n if (groups.listMetadata.after) groupCount = -1;\n } catch {\n // May not have access\n }\n\n // 4. List recent sync events\n let recentEvents: Array<{ id: string; event: string; createdAt: string }> = [];\n try {\n const events = await client.sdk.events.listEvents({\n events: ['dsync.user.created', 'dsync.user.updated', 'dsync.group.created'] as EventName[],\n ...(directory.organizationId && { organizationId: directory.organizationId }),\n limit: 5,\n });\n recentEvents = events.data.map((e) => ({ id: e.id, event: e.event, createdAt: e.createdAt }));\n } catch {\n // Events may not be available\n }\n\n if (recentEvents.length === 0) {\n issues.push('No recent sync events found — sync may be stalled');\n }\n\n if (isJsonMode()) {\n outputJson({\n directory: {\n id: directory.id,\n name: directory.name,\n type: directory.type,\n state: directory.state,\n organizationId: directory.organizationId,\n createdAt: directory.createdAt,\n },\n userCount: userCount === -1 ? '1+' : userCount,\n groupCount: groupCount === -1 ? '1+' : groupCount,\n recentEvents,\n issues,\n });\n return;\n }\n\n // 5. Human-readable diagnosis\n console.log(chalk.bold(`Directory Sync: ${directory.name}`));\n console.log(` ID: ${directory.id}`);\n console.log(` Type: ${directory.type}`);\n console.log(\n ` State: ${String(directory.state) === 'linked' ? chalk.green('linked') : chalk.yellow(directory.state)}`,\n );\n console.log(` Organization: ${directory.organizationId || chalk.dim('none')}`);\n console.log(` Users: ${userCount === -1 ? '1+' : userCount}`);\n console.log(` Groups: ${groupCount === -1 ? '1+' : groupCount}`);\n\n if (recentEvents.length > 0) {\n console.log(chalk.bold('\\nRecent sync events:'));\n for (const event of recentEvents) {\n console.log(` ${event.event} (${event.createdAt})`);\n }\n } else {\n console.log(chalk.dim('\\nNo recent sync events found.'));\n }\n\n if (issues.length > 0) {\n console.log(chalk.bold('\\nIssues found:'));\n for (const issue of issues) {\n console.log(chalk.yellow(` ⚠ ${issue}`));\n }\n } else {\n console.log(chalk.green('\\nNo issues detected.'));\n }\n } catch (error) {\n handleApiError(error);\n }\n}\n"]}