@contrail/cli 3.6.0-alpha-8-alpha.694fd70 → 3.6.0-alpha.aae3e70

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 (163) hide show
  1. package/README.md +45 -151
  2. package/dist/api/feature-flags.d.ts +3 -0
  3. package/dist/api/feature-flags.js +29 -0
  4. package/dist/api/types.d.ts +0 -35
  5. package/dist/api/types.js +1 -49
  6. package/dist/api/users.d.ts +1 -0
  7. package/dist/api/users.js +10 -1
  8. package/dist/auth/login.d.ts +4 -0
  9. package/dist/auth/login.js +167 -93
  10. package/dist/auth/login.spec.js +305 -0
  11. package/dist/auth/sso.d.ts +36 -0
  12. package/dist/auth/sso.js +164 -0
  13. package/dist/auth/sso.spec.js +119 -0
  14. package/dist/basecommand.d.ts +1 -3
  15. package/dist/basecommand.js +2 -2
  16. package/dist/commands/app/getApiKey.js +2 -2
  17. package/dist/commands/config/set.js +1 -1
  18. package/dist/commands/feature-flags/export.d.ts +19 -0
  19. package/dist/commands/feature-flags/export.js +66 -0
  20. package/dist/commands/feature-flags/export.spec.js +109 -0
  21. package/dist/commands/feature-flags/import.d.ts +42 -0
  22. package/dist/commands/feature-flags/import.js +191 -0
  23. package/dist/commands/feature-flags/import.spec.js +194 -0
  24. package/dist/commands/instance/export.d.ts +9 -0
  25. package/dist/commands/instance/export.js +18 -3
  26. package/dist/commands/instance/export.spec.js +32 -0
  27. package/dist/commands/instance/import.d.ts +3 -0
  28. package/dist/commands/instance/import.js +5 -0
  29. package/dist/commands/instance/import.spec.js +4 -0
  30. package/dist/commands/login.d.ts +12 -0
  31. package/dist/commands/login.js +25 -0
  32. package/dist/common.d.ts +1 -3
  33. package/dist/common.js +1 -13
  34. package/dist/helpers/config/config.d.ts +5 -4
  35. package/dist/helpers/config/config.js +10 -12
  36. package/dist/helpers/file-helpers.d.ts +0 -1
  37. package/dist/helpers/file-helpers.js +1 -18
  38. package/dist/logger.js +1 -4
  39. package/node_modules/@contrail/entity-compare/package.json +3 -6
  40. package/node_modules/@contrail/loader/lib/common/conditional-columns.js +1 -1
  41. package/node_modules/@contrail/loader/lib/constants.d.ts +8 -0
  42. package/node_modules/@contrail/loader/lib/constants.js +9 -1
  43. package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.d.ts +4 -0
  44. package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.js +57 -0
  45. package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.spec.js +492 -34
  46. package/node_modules/@contrail/loader/lib/pipeline/validate.js +2 -52
  47. package/node_modules/@contrail/loader/lib/pipeline/validate.spec.js +0 -85
  48. package/node_modules/@contrail/loader/package.json +2 -2
  49. package/node_modules/@contrail/sdk/.github/workflows/publish-to-npm.yml +4 -1
  50. package/node_modules/@contrail/sdk/lib/auth/login.js +1 -1
  51. package/node_modules/@contrail/sdk/lib/config/config.d.ts +0 -3
  52. package/node_modules/@contrail/sdk/lib/config/config.js +7 -13
  53. package/node_modules/@contrail/sdk/lib/core/request.js +2 -6
  54. package/node_modules/@contrail/sdk/lib/entities/entities.client.d.ts +0 -2
  55. package/node_modules/@contrail/sdk/lib/entities/entities.client.js +1 -3
  56. package/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.js +0 -1
  57. package/node_modules/@contrail/sdk/package.json +1 -1
  58. package/oclif.manifest.json +75 -365
  59. package/package.json +15 -5
  60. package/dist/commands/entities/create.d.ts +0 -48
  61. package/dist/commands/entities/create.js +0 -639
  62. package/dist/commands/entities/create.spec.js +0 -541
  63. package/dist/commands/entities/delete.d.ts +0 -19
  64. package/dist/commands/entities/delete.js +0 -134
  65. package/dist/commands/entities/get.d.ts +0 -24
  66. package/dist/commands/entities/get.js +0 -273
  67. package/dist/commands/entities/grammar.spec.js +0 -80
  68. package/dist/commands/entities/output.spec.js +0 -72
  69. package/dist/commands/entities/update.d.ts +0 -31
  70. package/dist/commands/entities/update.js +0 -157
  71. package/dist/helpers/entities/assortment-items.d.ts +0 -10
  72. package/dist/helpers/entities/assortment-items.js +0 -84
  73. package/dist/helpers/entities/batchFetch.d.ts +0 -8
  74. package/dist/helpers/entities/batchFetch.js +0 -49
  75. package/dist/helpers/entities/index.d.ts +0 -3
  76. package/dist/helpers/entities/index.js +0 -6
  77. package/dist/helpers/entities/items.d.ts +0 -10
  78. package/dist/helpers/entities/items.js +0 -102
  79. package/dist/helpers/entities/project-items.d.ts +0 -3
  80. package/dist/helpers/entities/project-items.js +0 -65
  81. package/dist/helpers/propertySpecifications/dateRanges.d.ts +0 -38
  82. package/dist/helpers/propertySpecifications/dateRanges.js +0 -89
  83. package/dist/helpers/propertySpecifications/dateRanges.spec.js +0 -95
  84. package/dist/helpers/propertySpecifications/propertySpecifications.d.ts +0 -40
  85. package/dist/helpers/propertySpecifications/propertySpecifications.js +0 -109
  86. package/dist/helpers/propertySpecifications/propertySpecifications.spec.d.ts +0 -1
  87. package/dist/helpers/propertySpecifications/propertySpecifications.spec.js +0 -373
  88. package/dist/logger.spec.d.ts +0 -1
  89. package/dist/logger.spec.js +0 -12
  90. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/pull_request_template.md +0 -31
  91. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/check-code-formatting.yml +0 -34
  92. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/empty.yml +0 -10
  93. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/generate-sdk-docs.yml +0 -32
  94. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/publish-to-npm.yml +0 -117
  95. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/sdk-lib.yml +0 -27
  96. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.prettierrc.yaml +0 -2
  97. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/README.md +0 -72
  98. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/home-hero.svg +0 -11
  99. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/assets.d.ts +0 -9
  100. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/assets.js +0 -54
  101. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/index.d.ts +0 -1
  102. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/index.js +0 -17
  103. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/auth.d.ts +0 -10
  104. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/auth.js +0 -6
  105. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/index.d.ts +0 -2
  106. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/index.js +0 -18
  107. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/login.d.ts +0 -10
  108. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/login.js +0 -209
  109. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/config.d.ts +0 -48
  110. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/config.js +0 -42
  111. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/index.d.ts +0 -1
  112. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/index.js +0 -17
  113. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/content.d.ts +0 -12
  114. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/content.js +0 -70
  115. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/index.d.ts +0 -1
  116. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/index.js +0 -17
  117. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/index.d.ts +0 -1
  118. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/index.js +0 -17
  119. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/request.d.ts +0 -15
  120. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/request.js +0 -241
  121. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entities.client.d.ts +0 -101
  122. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entities.client.js +0 -306
  123. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference-expander.d.ts +0 -9
  124. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference-expander.js +0 -86
  125. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference.d.ts +0 -6
  126. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference.js +0 -19
  127. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.d.ts +0 -5
  128. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.js +0 -59
  129. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/index.d.ts +0 -3
  130. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/index.js +0 -19
  131. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/file-type-helper.d.ts +0 -3
  132. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/file-type-helper.js +0 -24
  133. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/files.d.ts +0 -19
  134. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/files.js +0 -151
  135. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/index.d.ts +0 -1
  136. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/index.js +0 -17
  137. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/index.d.ts +0 -10
  138. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/index.js +0 -26
  139. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/index.d.ts +0 -1
  140. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/index.js +0 -17
  141. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/notifications-dispatcher.d.ts +0 -16
  142. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/notifications-dispatcher.js +0 -37
  143. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/index.d.ts +0 -1
  144. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/index.js +0 -17
  145. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies-cache.d.ts +0 -12
  146. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies-cache.js +0 -55
  147. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies.client.d.ts +0 -9
  148. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies.client.js +0 -74
  149. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/index.d.ts +0 -2
  150. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/index.js +0 -18
  151. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/sub-types-helper.d.ts +0 -18
  152. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/sub-types-helper.js +0 -98
  153. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types-cache.d.ts +0 -19
  154. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types-cache.js +0 -73
  155. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types.client.d.ts +0 -42
  156. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types.client.js +0 -217
  157. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/package.json +0 -64
  158. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/scripts/replicate-bug.js +0 -69
  159. package/node_modules/@contrail/sdk/scripts/replicate-bug.js +0 -69
  160. /package/dist/{commands/entities/create.spec.d.ts → auth/sso.spec.d.ts} +0 -0
  161. /package/dist/commands/{entities/grammar.spec.d.ts → feature-flags/export.spec.d.ts} +0 -0
  162. /package/dist/commands/{entities/output.spec.d.ts → feature-flags/import.spec.d.ts} +0 -0
  163. /package/dist/{helpers/propertySpecifications/dateRanges.spec.d.ts → commands/instance/export.spec.d.ts} +0 -0
@@ -1,34 +0,0 @@
1
- name: Check Code Formatting
2
- on:
3
- pull_request:
4
- paths:
5
- - '**'
6
- workflow_dispatch: # allow running in github actions manually
7
- jobs:
8
- check-formatting:
9
- runs-on: ubuntu-24.04
10
- steps:
11
- - name: Node.js
12
- uses: actions/setup-node@v3
13
- with:
14
- node-version: 20
15
- - uses: actions/checkout@v3
16
- with:
17
- lfs: true
18
- - name: Checkout LFS objects
19
- run: git lfs checkout
20
- - name: NPM Install
21
- env:
22
- NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
23
- run: npm ci
24
- - name: Check Format
25
- working-directory: ./
26
- run: npx prettier --check .
27
- - name: Fail On Warnings
28
- run: |
29
- if [ $? -eq 0 ]; then
30
- echo "No formatting issues found"
31
- else
32
- echo "Formatting issues found. Run 'npx prettier --write .' to fix them."
33
- exit 1
34
- fi
@@ -1,10 +0,0 @@
1
- name: empty-passing-test
2
- on: pull_request
3
- jobs:
4
- test:
5
- runs-on: ubuntu-24.04
6
- strategy:
7
- matrix:
8
- node-version: [16.17.0]
9
- steps:
10
- - run: 'echo "empty test for passing status checks"'
@@ -1,32 +0,0 @@
1
- name: generate-sdk-docs
2
- on:
3
- push:
4
- branches:
5
- - master
6
- paths:
7
- - '**'
8
- workflow_dispatch: # allow running in github actions manually
9
- jobs:
10
- deploy-docs:
11
- runs-on: ubuntu-24.04
12
- steps:
13
- - name: Node.js
14
- uses: actions/setup-node@v3
15
- with:
16
- node-version: 16.17.0
17
-
18
- - uses: actions/checkout@v3
19
-
20
- - name: NPM Install
21
- env:
22
- NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
23
- run: npm ci
24
- - name: Build SDK Docs
25
- env:
26
- NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
27
- run: npm run generate-docs
28
- - name: Deploy 🚀
29
- uses: JamesIves/github-pages-deploy-action@4.1.4
30
- with:
31
- branch: gh-pages
32
- folder: docs
@@ -1,117 +0,0 @@
1
- name: Publish to NPM
2
-
3
- on:
4
- push:
5
- branches: [master]
6
- pull_request:
7
- branches: ['**']
8
-
9
- jobs:
10
- check-version:
11
- name: Verify version is available on npm
12
- if: github.event_name == 'pull_request'
13
- runs-on: ubuntu-latest
14
- steps:
15
- - uses: actions/checkout@v4
16
-
17
- - name: Check version not already published
18
- run: |
19
- PACKAGE_NAME=$(node -p "require('./package.json').name")
20
- VERSION=$(node -p "require('./package.json').version")
21
- echo "Checking if ${PACKAGE_NAME}@${VERSION} exists on npm..."
22
- if npm view "${PACKAGE_NAME}@${VERSION}" version 2>/dev/null; then
23
- echo "::error::Version ${VERSION} is already published on npm. Bump the version in package.json before merging."
24
- exit 1
25
- else
26
- echo "Version ${VERSION} is available."
27
- fi
28
-
29
- check-dependencies:
30
- name: Verify no private dependencies
31
- runs-on: ubuntu-latest
32
- steps:
33
- - uses: actions/checkout@v4
34
-
35
- - name: Verify no private dependencies
36
- run: |
37
- node -e "
38
- const deps = require('./package.json').dependencies || {};
39
- const { execSync } = require('child_process');
40
- let failed = false;
41
- for (const pkg of Object.keys(deps)) {
42
- try {
43
- execSync('npm view ' + pkg, { stdio: 'pipe' });
44
- } catch {
45
- console.error('::error::Dependency ' + pkg + ' is not publicly accessible on npm');
46
- failed = true;
47
- }
48
- }
49
- if (failed) process.exit(1);
50
- console.log('All ' + Object.keys(deps).length + ' dependencies are public.');
51
- "
52
-
53
- publish-alpha:
54
- name: Publish alpha
55
- needs: check-dependencies
56
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
57
- runs-on: ubuntu-latest
58
- permissions:
59
- id-token: write
60
- contents: read
61
- outputs:
62
- version: ${{ steps.publish.outputs.version }}
63
- steps:
64
- - uses: actions/checkout@v4
65
-
66
- - uses: actions/setup-node@v4
67
- with:
68
- node-version: '24'
69
- registry-url: 'https://registry.npmjs.org'
70
-
71
- - name: Install and build
72
- run: npm ci && npm run build
73
-
74
- - name: Publish alpha
75
- id: publish
76
- run: |
77
- SHORT_SHA=$(echo ${{ github.event.pull_request.head.sha }} | cut -c1-7)
78
- VERSION=$(node -p "require('./package.json').version")-alpha.${SHORT_SHA}
79
- npm version $VERSION --no-git-tag-version
80
- OUTPUT=$(npm publish --tag alpha 2>&1) && {
81
- echo "version=$VERSION" >> $GITHUB_OUTPUT
82
- } || {
83
- if echo "$OUTPUT" | grep -q "You cannot publish over the previously published versions"; then
84
- echo "::warning::Alpha ${VERSION} already published, skipping."
85
- else
86
- echo "::error::Failed to publish alpha ${VERSION}"
87
- echo "$OUTPUT"
88
- exit 1
89
- fi
90
- }
91
-
92
- publish-release:
93
- name: Publish release
94
- needs: check-dependencies
95
- if: github.event_name == 'push'
96
- runs-on: ubuntu-latest
97
- permissions:
98
- id-token: write
99
- contents: read
100
- outputs:
101
- version: ${{ steps.publish.outputs.version }}
102
- steps:
103
- - uses: actions/checkout@v4
104
-
105
- - uses: actions/setup-node@v4
106
- with:
107
- node-version: '24'
108
- registry-url: 'https://registry.npmjs.org'
109
-
110
- - name: Install and build
111
- run: npm ci && npm run build
112
-
113
- - name: Publish release
114
- id: publish
115
- run: |
116
- npm publish
117
- echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
@@ -1,27 +0,0 @@
1
- name: sdk-lib-tests
2
- on:
3
- pull_request:
4
- # run this workflow when files these files change
5
- paths:
6
- - '**'
7
- workflow_dispatch: # allow running in github actions manually
8
- jobs:
9
- test:
10
- runs-on: ubuntu-24.04
11
- steps:
12
- - name: Node.js
13
- uses: actions/setup-node@v3
14
- with:
15
- node-version: ${{ matrix.node-version }}
16
-
17
- - uses: actions/checkout@v3
18
-
19
- - name: NPM Install
20
- env:
21
- NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
22
- run: npm ci
23
-
24
- - name: Unit Tests -
25
- env:
26
- NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
27
- run: npm test
@@ -1,2 +0,0 @@
1
- singleQuote: true
2
- printWidth: 120
@@ -1,72 +0,0 @@
1
- # [Contrail SDK](https://archergreysorg.github.io/contrail-lib/)
2
-
3
- Functionality within the VibeIQ platform (Contrail) can be accessed and extended through a TypeScript SDK. The SDK is installable via the popular JavaScript Node Packages Manager `npm`.
4
-
5
- ```bash
6
- npm install @contrail/sdk --global
7
- ```
8
-
9
- This will install the contrail SDK globally to your system, which will enable you to use it in any script, regardless of which directory it is in.
10
-
11
- Alternatively, If you are using the SDK as part of a module you plan on packaging and sharing with other developers (or deploying to the cloud), you can add the SDK to your project:
12
-
13
- ```bash
14
- npm install @contrail/sdk
15
- ```
16
-
17
- ### Scripting vs App development
18
-
19
- In the world of Javascript, code can be written as a one-off "script", run through the `node` interpreter, or packaged as part of an application. Below are examples on how to authenticate and print your username in each of these paradigms.
20
-
21
- #### Scripting
22
-
23
- To use the Contrail SDK as part of a one-off script, you can use the `require` javascript keyword.
24
-
25
- ```js title="script.js"
26
- const contrail = require('@contrail/sdk');
27
-
28
- // define an asynchronous function
29
- const run = async () => {
30
- await contrail.login({ orgSlug: 'YOUR-ORG-HERE', email: 'myEmail@example.com', password: 'neverInPlainText' });
31
-
32
- // or using an api key like the one you can get from `contrail app getApiKey`
33
- // await contrail.login({orgSlug: 'test-zone-1', apiKey: 'app:qwerty'})
34
-
35
- const user = await contrail.getCurrentUser();
36
- console.log('USER:', JSON.stringify(user, null, 2));
37
- };
38
-
39
- // run the function
40
- run();
41
- ```
42
-
43
- You can run your script using `node` in your shell.
44
-
45
- ```shell
46
- node script.js
47
- ```
48
-
49
- #### Packaged Module
50
-
51
- If you intend on using the Contrail SDK as part of your packaging module, you may use the `import` keyword. You are more likely to use this when writing integrations as part of a web or server runtime.
52
-
53
- ```js title="someServerFile.js"
54
- import { login, getCurrentUser } from '@contrail/sdk';
55
-
56
- export async function run() {
57
- await login({ orgSlug: 'YOUR-ORG-HERE', email: 'myEmail@example.com', password: 'neverInPlainText' });
58
-
59
- // or using an api key like the one you can get from `contrail app getApiKey`
60
- // await login({orgSlug: 'test-zone-1', apiKey: 'app:qwerty'})
61
-
62
- const user = await getCurrentUser();
63
- console.log('USER:', JSON.stringify(user, null, 2));
64
- }
65
-
66
- // run the function
67
- run();
68
- ```
69
-
70
- # General Documentation
71
-
72
- Complete documentation for the VibeIQ platform lives on [https://docs.vibeiq.com/](https://docs.vibeiq.com/).
@@ -1,11 +0,0 @@
1
- <svg width="635" height="433" viewBox="0 0 635 433" fill="none" xmlns="http://www.w3.org/2000/svg">
2
- <g clip-path="url(#clip0_309_15692)">
3
- <path d="M656.604 384.076C457.662 384.076 414.538 48.9114 216.574 48.9114C172.144 48.9339 129.54 66.5999 98.1308 98.0252C66.7213 129.451 49.077 172.063 49.077 216.494" stroke="#202532" stroke-width="97.8221" stroke-miterlimit="10"/>
4
- <path d="M49.077 216.494C49.077 309.04 128.454 384.076 216.66 384.076C415.601 384.076 457.747 48.9114 656.689 48.9114C701.134 48.9114 743.76 66.5673 775.188 97.9952C806.615 129.423 824.272 172.048 824.272 216.494C824.272 260.94 806.615 303.565 775.188 334.993C743.76 366.421 701.134 384.076 656.689 384.076" stroke="#00ABE9" stroke-width="97.8221" stroke-miterlimit="10"/>
5
- </g>
6
- <defs>
7
- <clipPath id="clip0_309_15692">
8
- <rect width="873.016" height="432.987" fill="white" transform="translate(0.166809)"/>
9
- </clipPath>
10
- </defs>
11
- </svg>
@@ -1,9 +0,0 @@
1
- export interface CreateAssetOptions {
2
- file?: File;
3
- contentHolderReference?: string;
4
- fileId?: string;
5
- workspaceId?: string;
6
- }
7
- export declare class Assets {
8
- create(options: CreateAssetOptions): Promise<any>;
9
- }
@@ -1,54 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Assets = void 0;
13
- const entities_1 = require("../entities");
14
- const file_type_helper_1 = require("../files/file-type-helper");
15
- const files_1 = require("../files/files");
16
- class Assets {
17
- create(options) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- let asset = null;
20
- if (options.file) {
21
- const file = options.file;
22
- if (!file) {
23
- throw Error(`Must specify file in create.`);
24
- }
25
- const contentType = file.type || file_type_helper_1.FileTypeHelper.getContentType(file);
26
- asset = yield new entities_1.Entities().create({
27
- entityName: 'asset',
28
- object: {
29
- contentHolderReference: options.contentHolderReference,
30
- fileName: file.name,
31
- contentType,
32
- workspaceId: options.workspaceId,
33
- },
34
- });
35
- yield new files_1.Files().uploadFile(asset.content.primaryFile.uploadPost, file);
36
- }
37
- else if (options.fileId) {
38
- asset = yield new entities_1.Entities().create({
39
- entityName: 'asset',
40
- object: {
41
- contentHolderReference: options.contentHolderReference,
42
- copyFileId: options.fileId,
43
- workspaceId: options.workspaceId,
44
- },
45
- });
46
- }
47
- else {
48
- throw new Error('Must specify file or fileId');
49
- }
50
- return asset;
51
- });
52
- }
53
- }
54
- exports.Assets = Assets;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./assets"), exports);
@@ -1,10 +0,0 @@
1
- export interface AuthContext {
2
- apiUserToken: string;
3
- apiRefreshToken?: string;
4
- apiGateway?: string;
5
- orgSlug?: string;
6
- orgId?: string;
7
- }
8
- export declare class Auth {
9
- static config: AuthContext;
10
- }
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Auth = void 0;
4
- class Auth {
5
- }
6
- exports.Auth = Auth;
@@ -1,2 +0,0 @@
1
- export * from './login';
2
- export * from './auth';
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./login"), exports);
18
- __exportStar(require("./auth"), exports);
@@ -1,10 +0,0 @@
1
- import { AuthContext } from './auth';
2
- export interface LoginCredentials {
3
- orgSlug: string;
4
- email?: string;
5
- password?: string;
6
- apiKey?: string;
7
- }
8
- export declare function setAppCredentials(apiKey: string, orgSlug: string): Promise<AuthContext>;
9
- export declare function login(credentials: LoginCredentials): Promise<AuthContext>;
10
- export declare function getCurrentUser(): Promise<any>;
@@ -1,209 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getCurrentUser = exports.login = exports.setAppCredentials = void 0;
13
- const AmazonCognitoIdentity = require('amazon-cognito-identity-js');
14
- const config_1 = require("../config");
15
- const auth_1 = require("./auth");
16
- const DEV_CONFIGURATION = {
17
- userPoolId: 'us-east-1_e2cA0nJWu',
18
- clientId: '209s9c62o165cqab0fu5ihjtu9',
19
- apiGateway: 'https://api.dev.vibeiq.com/dev/api',
20
- };
21
- const PROD_CONFIGURATION = {
22
- userPoolId: 'us-east-1_qIaNZdUfm',
23
- clientId: '7knkt34gfacbgd0ghnuspefdfg',
24
- apiGateway: 'https://api.vibeiq.com/prod/api',
25
- };
26
- const NIKE_CONFIGURATION = {
27
- apiGateway: 'https://api.nike.vibeiq.com/nike/api',
28
- };
29
- let CONFIGURATION = PROD_CONFIGURATION;
30
- if ((process === null || process === void 0 ? void 0 : process.env.CONTRAIL_CLI_ENV) === 'DEV') {
31
- CONFIGURATION = DEV_CONFIGURATION;
32
- }
33
- if ((process === null || process === void 0 ? void 0 : process.env.CONTRAIL_ENV) === 'DEV') {
34
- CONFIGURATION = DEV_CONFIGURATION;
35
- }
36
- if ((process === null || process === void 0 ? void 0 : process.env.CONTRAIL_CLI_ENV) === 'NIKE') {
37
- CONFIGURATION = NIKE_CONFIGURATION;
38
- }
39
- if ((process === null || process === void 0 ? void 0 : process.env.CONTRAIL_ENV) === 'NIKE') {
40
- CONFIGURATION = NIKE_CONFIGURATION;
41
- }
42
- function setAppCredentials(apiKey, orgSlug) {
43
- return __awaiter(this, void 0, void 0, function* () {
44
- let apiGateway = CONFIGURATION.apiGateway;
45
- auth_1.Auth.config = {
46
- apiUserToken: apiKey,
47
- apiGateway,
48
- orgSlug: orgSlug,
49
- };
50
- (0, config_1.setConfig)(auth_1.Auth.config);
51
- return Object.assign({}, auth_1.Auth.config);
52
- });
53
- }
54
- exports.setAppCredentials = setAppCredentials;
55
- function login(credentials) {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- if (!credentials.orgSlug) {
58
- console.log("Missing authentication credentials. 'orgSlug' is required.");
59
- }
60
- if (!(credentials.apiKey || (credentials.email && credentials.password))) {
61
- console.log('Missing authentication credentials. Provide an orgSlug and either apiKey or username and password.');
62
- }
63
- if (credentials.apiKey) {
64
- return yield setAuthContext(credentials.apiKey, credentials.orgSlug);
65
- }
66
- else {
67
- return yield usernameAuthentication(credentials.email, credentials.password, credentials.orgSlug);
68
- }
69
- });
70
- }
71
- exports.login = login;
72
- function usernameAuthentication(email, password, orgSlug) {
73
- return __awaiter(this, void 0, void 0, function* () {
74
- if (!email || !password) {
75
- throw new Error('Email and Password required');
76
- }
77
- const poolData = {
78
- UserPoolId: CONFIGURATION === null || CONFIGURATION === void 0 ? void 0 : CONFIGURATION.userPoolId,
79
- ClientId: CONFIGURATION === null || CONFIGURATION === void 0 ? void 0 : CONFIGURATION.clientId,
80
- };
81
- const userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
82
- const authData = {
83
- Username: email,
84
- Password: password,
85
- };
86
- const authDetails = new AmazonCognitoIdentity.AuthenticationDetails(authData);
87
- const userData = {
88
- Username: email,
89
- Pool: userPool,
90
- };
91
- const cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
92
- return new Promise((resolve, reject) => {
93
- cognitoUser.authenticateUser(authDetails, {
94
- onSuccess: (result) => __awaiter(this, void 0, void 0, function* () {
95
- const user = result;
96
- const cognitoAccessToken = user.idToken.jwtToken;
97
- try {
98
- const apiTokens = yield exchangeCognitoTokensForApiTokens(cognitoAccessToken);
99
- const config = yield setAuthContext(apiTokens.accessToken, orgSlug, apiTokens.refreshToken);
100
- resolve(config);
101
- }
102
- catch (error) {
103
- console.error('Failed to process Cognito token:', error);
104
- reject(error);
105
- }
106
- }),
107
- onFailure: (err) => {
108
- reject(err);
109
- },
110
- });
111
- });
112
- });
113
- }
114
- function exchangeCognitoTokensForApiTokens(cognitoAccessToken) {
115
- return __awaiter(this, void 0, void 0, function* () {
116
- const apiGateway = CONFIGURATION.apiGateway;
117
- const url = apiGateway + '/auth/cognito/';
118
- const response = yield fetch(url, {
119
- method: 'POST',
120
- headers: {
121
- Accept: 'application/json',
122
- 'Content-Type': 'application/json',
123
- },
124
- body: JSON.stringify({
125
- accessToken: cognitoAccessToken,
126
- }),
127
- });
128
- if (!response.ok) {
129
- throw new Error(`Failed to authenticate with Cognito token: ${response.status}`);
130
- }
131
- const data = yield response.json();
132
- if (!data.accessToken) {
133
- throw new Error('Response from /auth/cognito/ missing required field: accessToken');
134
- }
135
- if (!data.refreshToken) {
136
- throw new Error('Response from /auth/cognito/ missing required field: refreshToken');
137
- }
138
- return {
139
- accessToken: data.accessToken,
140
- refreshToken: data.refreshToken,
141
- };
142
- });
143
- }
144
- function setAuthContext(bearerToken, orgSlug, apiRefreshToken) {
145
- return __awaiter(this, void 0, void 0, function* () {
146
- let apiGateway = CONFIGURATION.apiGateway;
147
- auth_1.Auth.config = {
148
- apiUserToken: bearerToken,
149
- apiRefreshToken: apiRefreshToken,
150
- apiGateway,
151
- orgSlug,
152
- };
153
- (0, config_1.setConfig)(auth_1.Auth.config);
154
- const user = yield getCurrentUser();
155
- if (!user) {
156
- throw Error('Login Error: User not found in platform.');
157
- }
158
- const org = user.orgs.find((o) => o.orgSlug === auth_1.Auth.config.orgSlug);
159
- if (!user) {
160
- throw Error('Login Error: User does not have access to specified org.');
161
- }
162
- if (org) {
163
- auth_1.Auth.config.orgId = org.orgId || org.id;
164
- }
165
- else {
166
- throw new Error(`User does not have access to ${auth_1.Auth.config.orgSlug}`);
167
- }
168
- console.log(`Login Success as ${user.email} in ${org.orgSlug} [${auth_1.Auth.config.orgId}]`);
169
- return Object.assign({}, auth_1.Auth.config);
170
- });
171
- }
172
- function getCurrentUser() {
173
- return __awaiter(this, void 0, void 0, function* () {
174
- const config = (0, config_1.getConfig)();
175
- if (!(config === null || config === void 0 ? void 0 : config.apiUserToken) || !(config === null || config === void 0 ? void 0 : config.apiGateway)) {
176
- throw new Error('The user is not authenticated');
177
- }
178
- function getApiKey() {
179
- return __awaiter(this, void 0, void 0, function* () {
180
- const config = (0, config_1.getConfig)();
181
- if (config.authTokenResolver) {
182
- return yield config.authTokenResolver.resolveAuthToken();
183
- }
184
- else if (config.apiUserToken) {
185
- return config.apiUserToken;
186
- }
187
- });
188
- }
189
- const params = { method: 'get' };
190
- const API_GATEWAY = config.apiGateway;
191
- const url = API_GATEWAY + '/users/current';
192
- const apiKey = yield getApiKey();
193
- const isAppToken = apiKey.startsWith('app:');
194
- const orgSlug = config.orgSlug;
195
- params.headers = {
196
- 'X-Api-Key': apiKey,
197
- 'X-Api-Org': isAppToken ? orgSlug : 'NONE',
198
- Accept: 'application/json',
199
- 'Content-Type': 'application/json',
200
- };
201
- const currentUserResponse = yield fetch(url, params);
202
- if (currentUserResponse.status !== 200) {
203
- const responseBody = yield currentUserResponse.json().catch(() => null);
204
- throw new Error(`Failed to fetch current user. ${(responseBody === null || responseBody === void 0 ? void 0 : responseBody.message) || ''}`);
205
- }
206
- return currentUserResponse.json();
207
- });
208
- }
209
- exports.getCurrentUser = getCurrentUser;