@symbo.ls/sdk 2.34.32 → 2.34.34

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.
@@ -14,6 +14,7 @@ import { TrackingService } from './TrackingService.js'
14
14
  import { WaitlistService } from './WaitlistService.js'
15
15
  import { MetricsService } from './MetricsService.js'
16
16
  import { IntegrationService } from './IntegrationService.js'
17
+ import { FeatureFlagService } from './FeatureFlagService.js'
17
18
 
18
19
  const createService = (ServiceClass, config) => new ServiceClass(config)
19
20
 
@@ -65,6 +66,9 @@ export const createMetricsService = config =>
65
66
  export const createIntegrationService = config =>
66
67
  createService(IntegrationService, config)
67
68
 
69
+ export const createFeatureFlagService = config =>
70
+ createService(FeatureFlagService, config)
71
+
68
72
  export {
69
73
  AuthService,
70
74
  CollabService,
@@ -81,5 +85,6 @@ export {
81
85
  TrackingService,
82
86
  WaitlistService,
83
87
  MetricsService,
84
- IntegrationService
88
+ IntegrationService,
89
+ FeatureFlagService
85
90
  }
@@ -0,0 +1,67 @@
1
+ import test from 'tape'
2
+ import sinon from 'sinon'
3
+ import { FeatureFlagService } from '../../FeatureFlagService.js'
4
+
5
+ // #region Setup
6
+ const sandbox = sinon.createSandbox()
7
+ // #endregion
8
+
9
+ // #region Tests
10
+ test('getAdminFeatureFlags should pass includeArchived=false', async t => {
11
+ t.plan(1)
12
+ const responseStub = { success: true, data: [] }
13
+ const service = new FeatureFlagService()
14
+ sandbox.stub(service, '_requireReady').resolves()
15
+ const requestStub = sandbox.stub(service, '_request').resolves(responseStub)
16
+
17
+ await service.getAdminFeatureFlags({ includeArchived: false })
18
+ t.equal(
19
+ requestStub.firstCall.args[0],
20
+ '/admin/feature-flags?includeArchived=false',
21
+ 'includeArchived=false included'
22
+ )
23
+
24
+ sandbox.restore()
25
+ t.end()
26
+ })
27
+
28
+ test('createFeatureFlag should require key', async t => {
29
+ t.plan(1)
30
+ const service = new FeatureFlagService()
31
+ sandbox.stub(service, '_requireReady').resolves()
32
+
33
+ try {
34
+ await service.createFeatureFlag({ enabled: true })
35
+ t.fail('Expected createFeatureFlag to throw without key')
36
+ } catch (err) {
37
+ t.equal(err.toString(), 'Error: Feature flag key is required', 'Key validation works')
38
+ }
39
+
40
+ sandbox.restore()
41
+ t.end()
42
+ })
43
+
44
+ test('updateFeatureFlag should require id', async t => {
45
+ t.plan(1)
46
+ const service = new FeatureFlagService()
47
+ sandbox.stub(service, '_requireReady').resolves()
48
+
49
+ try {
50
+ await service.updateFeatureFlag(null, { enabled: false })
51
+ t.fail('Expected updateFeatureFlag to throw without id')
52
+ } catch (err) {
53
+ t.equal(err.toString(), 'Error: Feature flag id is required', 'Id validation works')
54
+ }
55
+
56
+ sandbox.restore()
57
+ t.end()
58
+ })
59
+ // #endregion
60
+
61
+ // #region Cleanup
62
+ test('teardown', t => {
63
+ sandbox.restore()
64
+ t.end()
65
+ })
66
+ // #endregion
67
+
@@ -0,0 +1,75 @@
1
+ import test from 'tape'
2
+ import sinon from 'sinon'
3
+ import { FeatureFlagService } from '../../FeatureFlagService.js'
4
+
5
+ // #region Setup
6
+ const sandbox = sinon.createSandbox()
7
+ // #endregion
8
+
9
+ // #region Tests
10
+ test('getFeatureFlags should return response data', async t => {
11
+ t.plan(1)
12
+ const responseStub = {
13
+ success: true,
14
+ data: { flags: { new_ui: { enabled: true, variant: null, payload: null } } }
15
+ }
16
+ const service = new FeatureFlagService()
17
+ sandbox.stub(service, '_requireReady').resolves()
18
+ sandbox.stub(service, '_request').resolves(responseStub)
19
+
20
+ const response = await service.getFeatureFlags()
21
+ t.equal(response, responseStub.data, 'Response data returned')
22
+
23
+ sandbox.restore()
24
+ t.end()
25
+ })
26
+
27
+ test('getFeatureFlags should pass keys query param', async t => {
28
+ t.plan(1)
29
+ const responseStub = { success: true, data: { flags: {} } }
30
+ const service = new FeatureFlagService()
31
+ sandbox.stub(service, '_requireReady').resolves()
32
+ const requestStub = sandbox.stub(service, '_request').resolves(responseStub)
33
+
34
+ await service.getFeatureFlags({ keys: ['new_ui', 'checkout_experiment'] })
35
+ t.ok(
36
+ requestStub.firstCall.args[0].includes('/feature-flags?keys=new_ui%2Ccheckout_experiment'),
37
+ 'Keys query param included'
38
+ )
39
+
40
+ sandbox.restore()
41
+ t.end()
42
+ })
43
+
44
+ test('getFeatureFlags should return an error', async t => {
45
+ t.plan(1)
46
+ const responseStub = {
47
+ success: false,
48
+ data: {},
49
+ message: 'Negative getFeatureFlags Test'
50
+ }
51
+ const service = new FeatureFlagService()
52
+ sandbox.stub(service, '_requireReady').resolves()
53
+ sandbox.stub(service, '_request').resolves(responseStub)
54
+
55
+ try {
56
+ await service.getFeatureFlags()
57
+ } catch (err) {
58
+ t.ok(
59
+ err.toString().includes(`Failed to get feature flags: ${responseStub.message}`),
60
+ 'Error correctly returned'
61
+ )
62
+ }
63
+
64
+ sandbox.restore()
65
+ t.end()
66
+ })
67
+ // #endregion
68
+
69
+ // #region Cleanup
70
+ test('teardown', t => {
71
+ sandbox.restore()
72
+ t.end()
73
+ })
74
+ // #endregion
75
+
@@ -321,5 +321,13 @@ export const SERVICE_METHODS = {
321
321
  listGitHubConnectors: 'integration',
322
322
  createGitHubConnector: 'integration',
323
323
  updateGitHubConnector: 'integration',
324
- deleteGitHubConnector: 'integration'
324
+ deleteGitHubConnector: 'integration',
325
+
326
+ // Feature flag methods (system-level + experiments)
327
+ getFeatureFlags: 'featureFlag',
328
+ getFeatureFlag: 'featureFlag',
329
+ getAdminFeatureFlags: 'featureFlag',
330
+ createFeatureFlag: 'featureFlag',
331
+ updateFeatureFlag: 'featureFlag',
332
+ archiveFeatureFlag: 'featureFlag'
325
333
  }