@de./sdk 1.0.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/allend/Access.d.ts +39 -3
- package/dist/allend/Access.js +147 -114
- package/dist/allend/Access.js.map +1 -1
- package/dist/allend/Agent/consolidation.d.ts +16 -0
- package/dist/allend/Agent/consolidation.js +38 -0
- package/dist/allend/Agent/consolidation.js.map +1 -0
- package/dist/allend/Agent/delivery.d.ts +11 -0
- package/dist/allend/Agent/delivery.js +43 -0
- package/dist/allend/Agent/delivery.js.map +1 -0
- package/dist/allend/Agent/dispatch.d.ts +8 -0
- package/dist/allend/Agent/dispatch.js +24 -0
- package/dist/allend/Agent/dispatch.js.map +1 -0
- package/dist/allend/Agent/index.d.ts +49 -0
- package/dist/allend/Agent/index.js +74 -0
- package/dist/allend/Agent/index.js.map +1 -0
- package/dist/allend/Agent/navigation.d.ts +8 -0
- package/dist/allend/Agent/navigation.js +25 -0
- package/dist/allend/Agent/navigation.js.map +1 -0
- package/dist/allend/Agent/origin.d.ts +9 -0
- package/dist/allend/Agent/origin.js +31 -0
- package/dist/allend/Agent/origin.js.map +1 -0
- package/dist/allend/Agent/reallocation.d.ts +7 -0
- package/dist/allend/Agent/reallocation.js +17 -0
- package/dist/allend/Agent/reallocation.js.map +1 -0
- package/dist/allend/Agent/realtime.d.ts +36 -0
- package/dist/allend/Agent/realtime.js +111 -0
- package/dist/allend/Agent/realtime.js.map +1 -0
- package/dist/allend/Agent/rides.d.ts +12 -0
- package/dist/allend/Agent/rides.js +51 -0
- package/dist/allend/Agent/rides.js.map +1 -0
- package/dist/allend/Agent/shipping.d.ts +11 -0
- package/dist/allend/Agent/shipping.js +43 -0
- package/dist/allend/Agent/shipping.js.map +1 -0
- package/dist/allend/CSP/analytics.d.ts +12 -0
- package/dist/allend/CSP/analytics.js +51 -0
- package/dist/allend/CSP/analytics.js.map +1 -0
- package/dist/allend/CSP/index.d.ts +25 -0
- package/dist/allend/CSP/index.js +43 -0
- package/dist/allend/CSP/index.js.map +1 -0
- package/dist/allend/CSP/inventory.d.ts +16 -0
- package/dist/allend/CSP/inventory.js +78 -0
- package/dist/allend/CSP/inventory.js.map +1 -0
- package/dist/allend/CSP/orders.d.ts +19 -0
- package/dist/allend/CSP/orders.js +97 -0
- package/dist/allend/CSP/orders.js.map +1 -0
- package/dist/allend/CSP/webhooks.d.ts +13 -0
- package/dist/allend/CSP/webhooks.js +56 -0
- package/dist/allend/CSP/webhooks.js.map +1 -0
- package/dist/allend/Customer/index.d.ts +27 -0
- package/dist/allend/Customer/index.js +39 -0
- package/dist/allend/Customer/index.js.map +1 -0
- package/dist/allend/Customer/intents.d.ts +12 -0
- package/dist/allend/Customer/intents.js +55 -0
- package/dist/allend/Customer/intents.js.map +1 -0
- package/dist/allend/Customer/orders.d.ts +11 -0
- package/dist/allend/Customer/orders.js +43 -0
- package/dist/allend/Customer/orders.js.map +1 -0
- package/dist/allend/Customer/rides.d.ts +12 -0
- package/dist/allend/Customer/rides.js +50 -0
- package/dist/allend/Customer/rides.js.map +1 -0
- package/dist/allend/DEV/developers.d.ts +11 -0
- package/dist/allend/DEV/developers.js +35 -0
- package/dist/allend/DEV/developers.js.map +1 -0
- package/dist/allend/DEV/index.d.ts +19 -0
- package/dist/allend/DEV/index.js +37 -0
- package/dist/allend/DEV/index.js.map +1 -0
- package/dist/allend/IoTClient.js +29 -35
- package/dist/allend/IoTClient.js.map +1 -1
- package/dist/allend/IoTSP/backend.d.ts +29 -0
- package/dist/allend/IoTSP/backend.js +75 -0
- package/dist/allend/IoTSP/backend.js.map +1 -0
- package/dist/allend/IoTSP/devices.d.ts +14 -0
- package/dist/allend/IoTSP/devices.js +61 -0
- package/dist/allend/IoTSP/devices.js.map +1 -0
- package/dist/allend/IoTSP/index.d.ts +28 -0
- package/dist/allend/IoTSP/index.js +84 -0
- package/dist/allend/IoTSP/index.js.map +1 -0
- package/dist/allend/IoTSP/rules.d.ts +17 -0
- package/dist/allend/IoTSP/rules.js +81 -0
- package/dist/allend/IoTSP/rules.js.map +1 -0
- package/dist/allend/IoTSP/topics.d.ts +17 -0
- package/dist/allend/IoTSP/topics.js +81 -0
- package/dist/allend/IoTSP/topics.js.map +1 -0
- package/dist/allend/LSP/agents.d.ts +20 -0
- package/dist/allend/LSP/agents.js +89 -0
- package/dist/allend/LSP/agents.js.map +1 -0
- package/dist/allend/LSP/carriers.d.ts +54 -0
- package/dist/allend/LSP/carriers.js +315 -0
- package/dist/allend/LSP/carriers.js.map +1 -0
- package/dist/allend/LSP/coverage.d.ts +44 -0
- package/dist/allend/LSP/coverage.js +135 -0
- package/dist/allend/LSP/coverage.js.map +1 -0
- package/dist/allend/LSP/fleets.d.ts +66 -0
- package/dist/allend/LSP/fleets.js +381 -0
- package/dist/allend/LSP/fleets.js.map +1 -0
- package/dist/allend/LSP/hubs.d.ts +39 -0
- package/dist/allend/LSP/hubs.js +186 -0
- package/dist/allend/LSP/hubs.js.map +1 -0
- package/dist/allend/LSP/index.d.ts +37 -0
- package/dist/allend/LSP/index.js +55 -0
- package/dist/allend/LSP/index.js.map +1 -0
- package/dist/allend/LSP/inventory.d.ts +13 -0
- package/dist/allend/LSP/inventory.js +56 -0
- package/dist/allend/LSP/inventory.js.map +1 -0
- package/dist/allend/LSP/operations.d.ts +47 -0
- package/dist/allend/LSP/operations.js +156 -0
- package/dist/allend/LSP/operations.js.map +1 -0
- package/dist/allend/LSP/orders.d.ts +69 -0
- package/dist/allend/LSP/orders.js +303 -0
- package/dist/allend/LSP/orders.js.map +1 -0
- package/dist/allend/LSP/pods.d.ts +26 -0
- package/dist/allend/LSP/pods.js +137 -0
- package/dist/allend/LSP/pods.js.map +1 -0
- package/dist/allend/LSP/pricing.d.ts +35 -0
- package/dist/allend/LSP/pricing.js +151 -0
- package/dist/allend/LSP/pricing.js.map +1 -0
- package/dist/allend/LSP/psl.d.ts +15 -0
- package/dist/allend/LSP/psl.js +68 -0
- package/dist/allend/LSP/psl.js.map +1 -0
- package/dist/allend/LSP/warehouses.d.ts +23 -0
- package/dist/allend/LSP/warehouses.js +94 -0
- package/dist/allend/LSP/warehouses.js.map +1 -0
- package/dist/allend/MSI/Controls.d.ts +9 -5
- package/dist/allend/MSI/Controls.js +269 -297
- package/dist/allend/MSI/Controls.js.map +1 -1
- package/dist/allend/MSI/Handles.d.ts +5 -4
- package/dist/allend/MSI/Handles.js +136 -233
- package/dist/allend/MSI/Handles.js.map +1 -1
- package/dist/allend/MSI/Plugins.d.ts +2 -2
- package/dist/allend/MSI/Plugins.js +12 -15
- package/dist/allend/MSI/Plugins.js.map +1 -1
- package/dist/allend/MSI/index.d.ts +4 -3
- package/dist/allend/MSI/index.js +123 -87
- package/dist/allend/MSI/index.js.map +1 -1
- package/dist/allend/MSI/native.d.ts +32 -0
- package/dist/allend/MSI/native.js +246 -0
- package/dist/allend/MSI/native.js.map +1 -0
- package/dist/allend/MSI/token.d.ts +12 -0
- package/dist/allend/MSI/token.js +21 -0
- package/dist/allend/MSI/token.js.map +1 -0
- package/dist/allend/OTPAuth/index.d.ts +77 -0
- package/dist/allend/OTPAuth/index.js +69 -0
- package/dist/allend/OTPAuth/index.js.map +1 -0
- package/dist/allend/Pipelines/analytics.d.ts +8 -0
- package/dist/allend/Pipelines/analytics.js +24 -0
- package/dist/allend/Pipelines/analytics.js.map +1 -0
- package/dist/allend/Pipelines/escalations.d.ts +8 -0
- package/dist/allend/Pipelines/escalations.js +25 -0
- package/dist/allend/Pipelines/escalations.js.map +1 -0
- package/dist/allend/Pipelines/executions.d.ts +11 -0
- package/dist/allend/Pipelines/executions.js +44 -0
- package/dist/allend/Pipelines/executions.js.map +1 -0
- package/dist/allend/Pipelines/index.d.ts +42 -0
- package/dist/allend/Pipelines/index.js +88 -0
- package/dist/allend/Pipelines/index.js.map +1 -0
- package/dist/allend/Pipelines/interventions.d.ts +8 -0
- package/dist/allend/Pipelines/interventions.js +25 -0
- package/dist/allend/Pipelines/interventions.js.map +1 -0
- package/dist/allend/Pipelines/monitor.d.ts +9 -0
- package/dist/allend/Pipelines/monitor.js +30 -0
- package/dist/allend/Pipelines/monitor.js.map +1 -0
- package/dist/allend/Pipelines/queries.d.ts +8 -0
- package/dist/allend/Pipelines/queries.js +25 -0
- package/dist/allend/Pipelines/queries.js.map +1 -0
- package/dist/allend/Pipelines/templates.d.ts +11 -0
- package/dist/allend/Pipelines/templates.js +46 -0
- package/dist/allend/Pipelines/templates.js.map +1 -0
- package/dist/allend/Pipelines/utils.d.ts +0 -0
- package/dist/allend/Pipelines/utils.js +2 -0
- package/dist/allend/Pipelines/utils.js.map +1 -0
- package/dist/allend/Pipelines/webhooks.d.ts +9 -0
- package/dist/allend/Pipelines/webhooks.js +35 -0
- package/dist/allend/Pipelines/webhooks.js.map +1 -0
- package/dist/allend/Pipelines/workers.d.ts +11 -0
- package/dist/allend/Pipelines/workers.js +45 -0
- package/dist/allend/Pipelines/workers.js.map +1 -0
- package/dist/allend/Queries/capacity.d.ts +11 -0
- package/dist/allend/Queries/capacity.js +44 -0
- package/dist/allend/Queries/capacity.js.map +1 -0
- package/dist/allend/Queries/discovery.d.ts +11 -0
- package/dist/allend/Queries/discovery.js +45 -0
- package/dist/allend/Queries/discovery.js.map +1 -0
- package/dist/allend/Queries/index.d.ts +27 -0
- package/dist/allend/Queries/index.js +40 -0
- package/dist/allend/Queries/index.js.map +1 -0
- package/dist/allend/Queries/matching.d.ts +7 -0
- package/dist/allend/Queries/matching.js +18 -0
- package/dist/allend/Queries/matching.js.map +1 -0
- package/dist/allend/Queries/performance.d.ts +9 -0
- package/dist/allend/Queries/performance.js +31 -0
- package/dist/allend/Queries/performance.js.map +1 -0
- package/dist/allend/Queries/pricing.d.ts +11 -0
- package/dist/allend/Queries/pricing.js +43 -0
- package/dist/allend/Queries/pricing.js.map +1 -0
- package/dist/allend/{DClient/Event.d.ts → Realtime/index.d.ts} +2 -6
- package/dist/allend/Realtime/index.js +62 -0
- package/dist/allend/Realtime/index.js.map +1 -0
- package/dist/allend/Shared/account.d.ts +10 -0
- package/dist/allend/Shared/account.js +22 -0
- package/dist/allend/Shared/account.js.map +1 -0
- package/dist/allend/Shared/buckets.d.ts +21 -0
- package/dist/allend/Shared/buckets.js +95 -0
- package/dist/allend/Shared/buckets.js.map +1 -0
- package/dist/allend/Shared/context.d.ts +14 -0
- package/dist/allend/Shared/context.js +33 -0
- package/dist/allend/Shared/context.js.map +1 -0
- package/dist/allend/Shared/faqs.d.ts +20 -0
- package/dist/allend/Shared/faqs.js +87 -0
- package/dist/allend/Shared/faqs.js.map +1 -0
- package/dist/allend/Shared/invitation.d.ts +42 -0
- package/dist/allend/Shared/invitation.js +40 -0
- package/dist/allend/Shared/invitation.js.map +1 -0
- package/dist/allend/Shared/operators.d.ts +39 -0
- package/dist/allend/Shared/operators.js +37 -0
- package/dist/allend/Shared/operators.js.map +1 -0
- package/dist/allend/Shared/users.d.ts +11 -0
- package/dist/allend/Shared/users.js +29 -0
- package/dist/allend/Shared/users.js.map +1 -0
- package/dist/allend/Tracking/index.d.ts +17 -0
- package/dist/allend/Tracking/index.js +39 -0
- package/dist/allend/Tracking/index.js.map +1 -0
- package/dist/allend/Utilities/common.d.ts +12 -0
- package/dist/allend/Utilities/common.js +53 -0
- package/dist/allend/Utilities/common.js.map +1 -0
- package/dist/allend/Utilities/fares.d.ts +10 -0
- package/dist/allend/Utilities/fares.js +39 -0
- package/dist/allend/Utilities/fares.js.map +1 -0
- package/dist/allend/Utilities/index.d.ts +23 -0
- package/dist/allend/Utilities/index.js +36 -0
- package/dist/allend/Utilities/index.js.map +1 -0
- package/dist/allend/Utilities/nearby.d.ts +9 -0
- package/dist/allend/Utilities/nearby.js +32 -0
- package/dist/allend/Utilities/nearby.js.map +1 -0
- package/dist/allend/Workflows/Client.d.ts +17 -0
- package/dist/allend/Workflows/Client.js +50 -0
- package/dist/allend/Workflows/Client.js.map +1 -0
- package/dist/allend/Workflows/Delivery.d.ts +36 -0
- package/dist/allend/Workflows/Delivery.js +16 -0
- package/dist/allend/Workflows/Delivery.js.map +1 -0
- package/dist/allend/Workflows/index.d.ts +11 -0
- package/dist/allend/Workflows/index.js +25 -0
- package/dist/allend/Workflows/index.js.map +1 -0
- package/dist/allend/Workspace/index.d.ts +162 -0
- package/dist/allend/Workspace/index.js +220 -0
- package/dist/allend/Workspace/index.js.map +1 -0
- package/dist/allend/index.d.ts +8 -5
- package/dist/allend/index.js +15 -8
- package/dist/allend/index.js.map +1 -1
- package/dist/backend/Auth.d.ts +28 -4
- package/dist/backend/Auth.js +125 -245
- package/dist/backend/Auth.js.map +1 -1
- package/dist/baseUrl.d.ts +56 -0
- package/dist/baseUrl.js +72 -4
- package/dist/baseUrl.js.map +1 -1
- package/dist/core.d.ts +88 -0
- package/dist/core.js +121 -0
- package/dist/core.js.map +1 -0
- package/dist/error.d.ts +17 -0
- package/dist/error.js +26 -0
- package/dist/error.js.map +1 -0
- package/dist/index.d.ts +30 -12
- package/dist/index.js +38 -14
- package/dist/index.js.map +1 -1
- package/dist/react-native.d.ts +30 -0
- package/dist/react-native.js +55 -0
- package/dist/react-native.js.map +1 -0
- package/dist/types/access.d.ts +64 -7
- package/dist/types/auth.d.ts +17 -17
- package/dist/types/channel.d.ts +45 -0
- package/dist/types/index.d.ts +379 -237
- package/dist/utils/index.d.ts +25 -0
- package/dist/utils/index.js +11 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/stream.js +25 -26
- package/dist/utils/stream.js.map +1 -1
- package/package.json +38 -18
- package/src/allend/Access.ts +143 -13
- package/src/allend/Agent/consolidation.ts +43 -0
- package/src/allend/Agent/delivery.ts +51 -0
- package/src/allend/Agent/dispatch.ts +27 -0
- package/src/allend/Agent/index.ts +113 -0
- package/src/allend/Agent/navigation.ts +27 -0
- package/src/allend/Agent/origin.ts +36 -0
- package/src/allend/Agent/reallocation.ts +16 -0
- package/src/allend/Agent/realtime.ts +140 -0
- package/src/allend/Agent/rides.ts +61 -0
- package/src/allend/Agent/shipping.ts +51 -0
- package/src/allend/CSP/analytics.ts +61 -0
- package/src/allend/CSP/index.ts +57 -0
- package/src/allend/CSP/inventory.ts +96 -0
- package/src/allend/CSP/orders.ts +121 -0
- package/src/allend/CSP/webhooks.ts +68 -0
- package/src/allend/Customer/index.ts +56 -0
- package/src/allend/Customer/intents.ts +66 -0
- package/src/allend/Customer/orders.ts +51 -0
- package/src/allend/Customer/rides.ts +60 -0
- package/src/allend/DEV/developers.ts +42 -0
- package/src/allend/DEV/index.ts +48 -0
- package/src/allend/IoTSP/backend.ts +103 -0
- package/src/allend/IoTSP/devices.ts +74 -0
- package/src/allend/IoTSP/index.ts +69 -0
- package/src/allend/IoTSP/rules.ts +99 -0
- package/src/allend/IoTSP/topics.ts +99 -0
- package/src/allend/LSP/agents.ts +115 -0
- package/src/allend/LSP/carriers.ts +408 -0
- package/src/allend/LSP/coverage.ts +212 -0
- package/src/allend/LSP/fleets.ts +505 -0
- package/src/allend/LSP/hubs.ts +245 -0
- package/src/allend/LSP/index.ts +75 -0
- package/src/allend/LSP/inventory.ts +65 -0
- package/src/allend/LSP/operations.ts +202 -0
- package/src/allend/LSP/orders.ts +397 -0
- package/src/allend/LSP/pods.ts +176 -0
- package/src/allend/LSP/pricing.ts +192 -0
- package/src/allend/LSP/psl.ts +81 -0
- package/src/allend/LSP/warehouses.ts +118 -0
- package/src/allend/MSI/Controls.ts +109 -90
- package/src/allend/MSI/Handles.ts +24 -15
- package/src/allend/MSI/Plugins.ts +3 -3
- package/src/allend/MSI/index.ts +85 -16
- package/src/allend/MSI/native.tsx +314 -0
- package/src/allend/MSI/token.ts +20 -0
- package/src/allend/OTPAuth/index.ts +130 -0
- package/src/allend/Pipelines/analytics.ts +25 -0
- package/src/allend/Pipelines/escalations.ts +26 -0
- package/src/allend/Pipelines/executions.ts +51 -0
- package/src/allend/Pipelines/index.ts +125 -0
- package/src/allend/Pipelines/interventions.ts +27 -0
- package/src/allend/Pipelines/monitor.ts +33 -0
- package/src/allend/Pipelines/queries.ts +27 -0
- package/src/allend/Pipelines/templates.ts +51 -0
- package/src/allend/Pipelines/utils.ts +0 -0
- package/src/allend/Pipelines/webhooks.ts +36 -0
- package/src/allend/Pipelines/workers.ts +49 -0
- package/src/allend/Queries/capacity.ts +51 -0
- package/src/allend/Queries/discovery.ts +53 -0
- package/src/allend/Queries/index.ts +58 -0
- package/src/allend/Queries/matching.ts +16 -0
- package/src/allend/Queries/performance.ts +35 -0
- package/src/allend/Queries/pricing.ts +51 -0
- package/src/allend/{DClient/Event.ts → Realtime/index.ts} +23 -22
- package/src/allend/Shared/account.ts +24 -0
- package/src/allend/Shared/buckets.ts +117 -0
- package/src/allend/Shared/context.ts +36 -0
- package/src/allend/Shared/faqs.ts +106 -0
- package/src/allend/Shared/invitation.ts +77 -0
- package/src/allend/Shared/operators.ts +84 -0
- package/src/allend/Shared/users.ts +32 -0
- package/src/allend/Tracking/index.ts +48 -0
- package/src/allend/Utilities/common.ts +63 -0
- package/src/allend/Utilities/fares.ts +45 -0
- package/src/allend/Utilities/index.ts +52 -0
- package/src/allend/Utilities/nearby.ts +36 -0
- package/src/allend/{DClient → Workflows}/Client.ts +12 -22
- package/src/allend/Workflows/Delivery.ts +94 -0
- package/src/allend/Workflows/index.ts +31 -0
- package/src/allend/Workspace/index.ts +302 -0
- package/src/allend/index.ts +23 -10
- package/src/backend/Auth.ts +68 -35
- package/src/baseUrl.ts +81 -7
- package/src/core.ts +145 -0
- package/src/error.ts +27 -0
- package/src/index.ts +25 -17
- package/src/react-native.ts +43 -0
- package/src/types/access.d.ts +64 -7
- package/src/types/auth.d.ts +17 -17
- package/src/types/channel.d.ts +45 -0
- package/src/types/index.d.ts +379 -237
- package/src/utils/index.ts +33 -1
- package/dist/allend/DAuth/index.d.ts +0 -20
- package/dist/allend/DAuth/index.js +0 -92
- package/dist/allend/DAuth/index.js.map +0 -1
- package/dist/allend/DClient/Client.d.ts +0 -10
- package/dist/allend/DClient/Client.js +0 -144
- package/dist/allend/DClient/Client.js.map +0 -1
- package/dist/allend/DClient/Event.js +0 -100
- package/dist/allend/DClient/Event.js.map +0 -1
- package/dist/allend/DClient/Order.d.ts +0 -49
- package/dist/allend/DClient/Order.js +0 -601
- package/dist/allend/DClient/Order.js.map +0 -1
- package/dist/bundle.js +0 -1
- package/src/allend/DAuth/index.ts +0 -39
- package/src/allend/DClient/Order.ts +0 -452
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import type { AccessOptions, UserSession } from '../../types/access'
|
|
2
|
+
import type { Workspace as WorkspaceRecord } from '@de./types/workspace'
|
|
3
|
+
import type { Admin, AdminUpdate } from '@de./types/workspace/admin'
|
|
4
|
+
import type { Connector, ConnectorType } from '@de./types/workspace/connector'
|
|
5
|
+
import AccessManager from '../Access'
|
|
6
|
+
import { qs, type Res } from '../../utils'
|
|
7
|
+
|
|
8
|
+
export type WorkspaceConfig = {
|
|
9
|
+
context: string
|
|
10
|
+
accessToken: string
|
|
11
|
+
env?: 'dev' | 'staging' | 'prod'
|
|
12
|
+
platform?: 'web' | 'mobile' | 'server' | 'proxy'
|
|
13
|
+
remoteOrigin?: string
|
|
14
|
+
/** Per-request deadline in ms. See `AccessOptions.timeout`. */
|
|
15
|
+
timeout?: number
|
|
16
|
+
/** Explicit service origin, overriding the env table. See `AccessOptions.baseUrl`. */
|
|
17
|
+
baseUrl?: string
|
|
18
|
+
/**
|
|
19
|
+
* The signed-in operator.
|
|
20
|
+
*
|
|
21
|
+
* Required in practice. de.workspace authenticates a *person*, not an
|
|
22
|
+
* integration — its routes read `de-auth-token` / `de-auth-device` — so a
|
|
23
|
+
* client carrying only a bearer token cannot reach any of them.
|
|
24
|
+
*/
|
|
25
|
+
session?: UserSession
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The four provider kinds a workspace can register, as they appear in a path. */
|
|
29
|
+
export type ProviderKind = 'lsp' | 'csp' | 'dev' | 'iotsp'
|
|
30
|
+
|
|
31
|
+
/** Context type as the connector routes spell it. */
|
|
32
|
+
export type ContextType = 'LSP' | 'CSP' | 'DEV' | 'IoTSP'
|
|
33
|
+
|
|
34
|
+
export type ProviderRecord = { xcode: string, name: string, type: string }
|
|
35
|
+
|
|
36
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
37
|
+
//
|
|
38
|
+
// Workspace: the control plane — de.workspace routes.
|
|
39
|
+
//
|
|
40
|
+
// A separate service from de.arch, which serves no `/workspace` routes at all.
|
|
41
|
+
// This client previously addressed `/workspace/admins`, `/workspace/connectors`
|
|
42
|
+
// and `/workspace/providers/lsps` against the API host; none of those exist
|
|
43
|
+
// anywhere, so every method 404'd. The real surface is workspace-id scoped:
|
|
44
|
+
// `/v1/:wid/admins`, `/v1/:wid/:ctype/:xcode/connectors`, `/v1/:wid/lsps`.
|
|
45
|
+
//
|
|
46
|
+
// Route shapes are taken from de.workspace/src/api/index.ts.
|
|
47
|
+
//
|
|
48
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
49
|
+
|
|
50
|
+
export default class Workspace extends AccessManager {
|
|
51
|
+
constructor( config: WorkspaceConfig ){
|
|
52
|
+
if( !config.context ) throw new Error('Undefined context. See https://doc.dedot.io/sdk/workspace')
|
|
53
|
+
if( !config.accessToken ) throw new Error('Undefined accessToken. See https://doc.dedot.io/sdk/auth')
|
|
54
|
+
|
|
55
|
+
const access: AccessOptions = {
|
|
56
|
+
context: config.context,
|
|
57
|
+
accessToken: config.accessToken,
|
|
58
|
+
env: config.env || 'dev',
|
|
59
|
+
platform: config.platform || 'proxy',
|
|
60
|
+
remoteOrigin: config.remoteOrigin,
|
|
61
|
+
timeout: config.timeout,
|
|
62
|
+
baseUrl: config.baseUrl,
|
|
63
|
+
session: config.session
|
|
64
|
+
}
|
|
65
|
+
super( access, 'WSP' )
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Returns the envelope, like every other client here.
|
|
70
|
+
*
|
|
71
|
+
* de.workspace answers `{ error, status, message, data }` too, and its
|
|
72
|
+
* `status` names a refusal precisely — WORKSPACE::EXISTS on a second
|
|
73
|
+
* setup, "already enabled" on a redundant enable. Both are outcomes a
|
|
74
|
+
* caller acts on rather than failures.
|
|
75
|
+
*/
|
|
76
|
+
private call<T>( method: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE', url: string, body?: any ): Promise<Res<T>> {
|
|
77
|
+
return this.request<Res<T>>({ url, method, ...( body !== undefined ? { body } : {}) })
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// ── Workspace ─────────────────────────────────────────────────────────────
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* A person may own exactly one workspace; a second call answers
|
|
84
|
+
* WORKSPACE::EXISTS rather than creating another.
|
|
85
|
+
*/
|
|
86
|
+
async create( body: { settings?: { theme?: string } } = {} ): Promise<Res<{ wid: string }>> {
|
|
87
|
+
return this.call('POST', '/workspace/setup', body )
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async retrieve( wid: string ): Promise<Res<WorkspaceRecord>> {
|
|
91
|
+
return this.call('GET', `/workspace/${wid}`)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async update( wid: string, body: Partial<Pick<WorkspaceRecord, 'settings'>> ): Promise<Res<WorkspaceRecord>> {
|
|
95
|
+
return this.call('PATCH', `/workspace/${wid}`, body )
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Deletion is two-step: an intent, then the delete that quotes it. */
|
|
99
|
+
async requestDeletion( wid: string ): Promise<Res<{ intent: string }>> {
|
|
100
|
+
return this.call('POST', `/workspace/${wid}/deletion/intent`, {})
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async remove( wid: string, querystring?: { intent?: string } ): Promise<Res<void>> {
|
|
104
|
+
return this.call('DELETE', `/workspace/${wid}${qs( querystring )}`)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ── Providers ─────────────────────────────────────────────────────────────
|
|
108
|
+
|
|
109
|
+
async createProvider( wid: string, kind: ProviderKind, body: Record<string, any> ): Promise<Res<{ xcode: string, context: string }>> {
|
|
110
|
+
return this.call('POST', `/${wid}/${kind}/setup`, body )
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async listProviders( wid: string, kind: ProviderKind ): Promise<Res<Record<string, ProviderRecord[]>>> {
|
|
114
|
+
return this.call('GET', `/${wid}/${kind}s`)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async retrieveProvider( wid: string, kind: ProviderKind, xcode: string ): Promise<Res<ProviderRecord>> {
|
|
118
|
+
return this.call('GET', `/${wid}/${kind}/${xcode}`)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async updateProvider( wid: string, kind: ProviderKind, xcode: string, body: Record<string, any> ): Promise<Res<ProviderRecord>> {
|
|
122
|
+
return this.call('PATCH', `/${wid}/${kind}/${xcode}`, body )
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Base64 of `wid:TYPE:xcode` — the context string every other client in
|
|
127
|
+
* this SDK is constructed with.
|
|
128
|
+
*/
|
|
129
|
+
async getProviderContext( wid: string, kind: ProviderKind, xcode: string ): Promise<Res<{ context: string }>> {
|
|
130
|
+
return this.call('GET', `/${wid}/${kind}/${xcode}/context`)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async requestProviderDeletion( wid: string, kind: ProviderKind, xcode: string ): Promise<Res<{ intent: string }>> {
|
|
134
|
+
return this.call('POST', `/${wid}/${kind}/${xcode}/deletion/intent`, {})
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async removeProvider( wid: string, kind: ProviderKind, xcode: string, querystring?: { intent?: string } ): Promise<Res<void>> {
|
|
138
|
+
return this.call('DELETE', `/${wid}/${kind}/${xcode}${qs( querystring )}`)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// ── Connectors ────────────────────────────────────────────────────────────
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Created disabled, and the reply carries only the id — the secret has to
|
|
145
|
+
* be read back with `getConnector`.
|
|
146
|
+
*/
|
|
147
|
+
async createConnector(
|
|
148
|
+
wid: string, ctype: ContextType, xcode: string,
|
|
149
|
+
body: { name: string, type: ConnectorType, description?: string, config?: Record<string, any> }
|
|
150
|
+
): Promise<Res<{ connectorId: string }>> {
|
|
151
|
+
return this.call('POST', `/${wid}/${ctype}/${xcode}/connectors`, body )
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async listConnectors( wid: string, ctype: ContextType, xcode: string, querystring?: Record<string, any> ): Promise<Res<{ connectors?: Connector[] }>> {
|
|
155
|
+
return this.call('GET', `/${wid}/${ctype}/${xcode}/connectors${qs( querystring )}`)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async getConnector( wid: string, ctype: ContextType, xcode: string, id: string ): Promise<Res<{ connector: Connector }>> {
|
|
159
|
+
return this.call('GET', `/${wid}/${ctype}/${xcode}/connectors/${id}`)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async updateConnector( wid: string, ctype: ContextType, xcode: string, id: string, body: Record<string, any> ): Promise<Res<Connector>> {
|
|
163
|
+
return this.call('PATCH', `/${wid}/${ctype}/${xcode}/connectors/${id}`, body )
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Enable or disable. Both are bodiless — Fastify rejects a JSON
|
|
168
|
+
* content-type with no body, and the transport sends one only when there
|
|
169
|
+
* is a body to send.
|
|
170
|
+
*/
|
|
171
|
+
async setConnectorEnabled( wid: string, ctype: ContextType, xcode: string, id: string, enabled: boolean ): Promise<Res<void>> {
|
|
172
|
+
return this.call('PATCH', `/${wid}/${ctype}/${xcode}/connectors/${id}/${enabled ? 'enable' : 'disable'}`)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Replaces the config wholesale; `patchConnectorConfig` merges instead. */
|
|
176
|
+
async setConnectorConfig( wid: string, ctype: ContextType, xcode: string, id: string, config: Record<string, any> ): Promise<Res<void>> {
|
|
177
|
+
return this.call('PUT', `/${wid}/${ctype}/${xcode}/connectors/${id}/config`, config )
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async patchConnectorConfig( wid: string, ctype: ContextType, xcode: string, id: string, config: Record<string, any> ): Promise<Res<void>> {
|
|
181
|
+
return this.call('PATCH', `/${wid}/${ctype}/${xcode}/connectors/${id}/config`, config )
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Origin allow-list and maintainers.
|
|
186
|
+
*
|
|
187
|
+
* An empty `origins` means no origin check at all, which is what a client
|
|
188
|
+
* that must not pin itself to one hostname wants.
|
|
189
|
+
*/
|
|
190
|
+
async setConnectorAccess( wid: string, ctype: ContextType, xcode: string, id: string, body: { origins?: string[], maintainers?: string[] }): Promise<Res<void>> {
|
|
191
|
+
return this.call('PATCH', `/${wid}/${ctype}/${xcode}/connectors/${id}/access`, body )
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
async rotateConnectorSecret( wid: string, ctype: ContextType, xcode: string, id: string ): Promise<Res<{ secret: string }>> {
|
|
195
|
+
return this.call('PATCH', `/${wid}/${ctype}/${xcode}/connectors/${id}/secret/rotate`)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async requestConnectorDeletion( wid: string, ctype: ContextType, xcode: string, id: string ): Promise<Res<{ intent: string }>> {
|
|
199
|
+
return this.call('POST', `/${wid}/${ctype}/${xcode}/connectors/${id}/deletion/intent`, {})
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
async removeConnector( wid: string, ctype: ContextType, xcode: string, id: string, querystring?: { intent?: string } ): Promise<Res<void>> {
|
|
203
|
+
return this.call('DELETE', `/${wid}/${ctype}/${xcode}/connectors/${id}${qs( querystring )}`)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// ── Admins ────────────────────────────────────────────────────────────────
|
|
207
|
+
|
|
208
|
+
async listAdmins( wid: string, querystring?: Record<string, any> ): Promise<Res<{ admins?: Admin[] }>> {
|
|
209
|
+
return this.call('GET', `/${wid}/admins${qs( querystring )}`)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async getAdmin( wid: string, id: string ): Promise<Res<Admin>> {
|
|
213
|
+
return this.call('GET', `/${wid}/admins/${id}`)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
async updateAdmin( wid: string, id: string, body: AdminUpdate ): Promise<Res<Admin>> {
|
|
217
|
+
return this.call('PATCH', `/${wid}/admins/${id}`, body )
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
async removeAdmin( wid: string, id: string ): Promise<Res<void>> {
|
|
221
|
+
return this.call('DELETE', `/${wid}/admins/${id}`)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// ── Billing ───────────────────────────────────────────────────────────────
|
|
225
|
+
|
|
226
|
+
async getBilling( wid: string, querystring?: Record<string, any> ): Promise<Res<any>> {
|
|
227
|
+
return this.call('GET', `/${wid}/billings${qs( querystring )}`)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
async getBillingUsage( wid: string, querystring?: Record<string, any> ): Promise<Res<any>> {
|
|
231
|
+
return this.call('GET', `/${wid}/billings/usage${qs( querystring )}`)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async listBillingNotifications( wid: string, querystring?: Record<string, any> ): Promise<Res<any>> {
|
|
235
|
+
return this.call('GET', `/${wid}/billings/notifications${qs( querystring )}`)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
async acknowledgeBillingNotification( wid: string, id: string ): Promise<Res<void>> {
|
|
239
|
+
return this.call('POST', `/${wid}/billings/notifications/${id}/acknowledge`, {})
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
async listInvoices( wid: string, querystring?: Record<string, any> ): Promise<Res<any>> {
|
|
243
|
+
return this.call('GET', `/${wid}/billings/invoices${qs( querystring )}`)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
async listConnectorBilling( wid: string, querystring?: Record<string, any> ): Promise<Res<any>> {
|
|
247
|
+
return this.call('GET', `/${wid}/billings/connectors${qs( querystring )}`)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
async getConnectorBilling( wid: string, cid: string ): Promise<Res<any>> {
|
|
251
|
+
return this.call('GET', `/${wid}/billings/connectors/${cid}`)
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
async getConnectorBillingHistory( wid: string, cid: string, querystring?: Record<string, any> ): Promise<Res<any>> {
|
|
255
|
+
return this.call('GET', `/${wid}/billings/connectors/${cid}/history${qs( querystring )}`)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
async estimateConnectorBilling( wid: string, cid: string, body: Record<string, any> ): Promise<Res<any>> {
|
|
259
|
+
return this.call('POST', `/${wid}/billings/connectors/${cid}/estimate`, body )
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
async changeConnectorTier( wid: string, cid: string, body: Record<string, any> ): Promise<Res<any>> {
|
|
263
|
+
return this.call('POST', `/${wid}/billings/connectors/${cid}/tier/change`, body )
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// ── Users & account ───────────────────────────────────────────────────────
|
|
267
|
+
|
|
268
|
+
async listUsers( wid: string, querystring?: Record<string, any> ): Promise<Res<any>> {
|
|
269
|
+
return this.call('GET', `/${wid}/users${qs( querystring )}`)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
async getUser( wid: string, uid: string ): Promise<Res<any>> {
|
|
273
|
+
return this.call('GET', `/${wid}/users/${uid}`)
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
async removeUser( wid: string, uid: string ): Promise<Res<void>> {
|
|
277
|
+
return this.call('DELETE', `/${wid}/users/${uid}`)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
async getAccount( wid: string ): Promise<Res<any>> {
|
|
281
|
+
return this.call('GET', `/${wid}/account`)
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** Who this account already knows in the workspace. */
|
|
285
|
+
async getAccountKnows( wid: string, querystring?: Record<string, any> ): Promise<Res<any>> {
|
|
286
|
+
return this.call('GET', `/${wid}/account/knows${qs( querystring )}`)
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// ── Invitation ────────────────────────────────────────────────────────────
|
|
290
|
+
|
|
291
|
+
async invite( wid: string, as: string, body: Record<string, any> ): Promise<Res<{ vcode: string }>> {
|
|
292
|
+
return this.call('POST', `/${wid}/invitation/${as}`, body )
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
async cancelInvitation( wid: string, body: Record<string, any> ): Promise<Res<void>> {
|
|
296
|
+
return this.call('DELETE', `/${wid}/invitation`, body )
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
async acceptInvitation( wid: string, body: { vcode: string } ): Promise<Res<any>> {
|
|
300
|
+
return this.call('POST', `/${wid}/invitation/accept`, body )
|
|
301
|
+
}
|
|
302
|
+
}
|
package/src/allend/index.ts
CHANGED
|
@@ -2,17 +2,30 @@ import MSI, { type MSIInterface } from './MSI'
|
|
|
2
2
|
import Utils from '../utils'
|
|
3
3
|
|
|
4
4
|
import IoTClient, { type IoTClientOptions } from './IoTClient'
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
5
|
+
import Event from './Realtime'
|
|
6
|
+
import Client from './Workflows/Client'
|
|
7
|
+
import Customer, { type CustomerConfig } from './Customer'
|
|
8
|
+
import Agent, { type AgentConfig } from './Agent'
|
|
9
|
+
import { type AgentRealtimeContext } from './Agent/realtime'
|
|
10
|
+
import Queries, { type QueriesConfig } from './Queries'
|
|
11
|
+
import Utilities, { type UtilitiesConfig } from './Utilities'
|
|
8
12
|
|
|
9
|
-
const DClient = { Client,
|
|
13
|
+
const DClient = { Client, Event }
|
|
10
14
|
|
|
11
15
|
export {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
type MSIInterface,
|
|
17
|
+
MSI,
|
|
18
|
+
Utils,
|
|
19
|
+
DClient,
|
|
20
|
+
IoTClient,
|
|
21
|
+
type IoTClientOptions,
|
|
22
|
+
Customer,
|
|
23
|
+
type CustomerConfig,
|
|
24
|
+
Agent,
|
|
25
|
+
type AgentConfig,
|
|
26
|
+
type AgentRealtimeContext,
|
|
27
|
+
Queries,
|
|
28
|
+
type QueriesConfig,
|
|
29
|
+
Utilities,
|
|
30
|
+
type UtilitiesConfig
|
|
18
31
|
}
|
package/src/backend/Auth.ts
CHANGED
|
@@ -1,18 +1,54 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
1
|
+
import { baseURL } from '../baseUrl'
|
|
2
|
+
import type { AuthRequestOptions } from '../types/auth'
|
|
3
3
|
|
|
4
4
|
const ACCESS_TOKEN_EXPIRY = 3.75 // in 3 minutes 45 seconds
|
|
5
5
|
|
|
6
|
+
// ─── Config ───────────────────────────────────────────────────────────────────
|
|
7
|
+
//
|
|
8
|
+
// Server-side Auth — connector credentials (cid + secret) → access token.
|
|
9
|
+
// Use on the backend; never expose cid/secret to the client.
|
|
10
|
+
//
|
|
11
|
+
// const auth = new Auth({ context, cid, secret, env })
|
|
12
|
+
// const token = await auth.getToken()
|
|
13
|
+
|
|
14
|
+
export type AuthConfig = {
|
|
15
|
+
context: string
|
|
16
|
+
cid: string
|
|
17
|
+
secret: string
|
|
18
|
+
remoteOrigin?: string
|
|
19
|
+
env?: 'dev' | 'staging' | 'prod'
|
|
20
|
+
version?: number
|
|
21
|
+
/**
|
|
22
|
+
* Operator uid to embed in the minted token's scope.
|
|
23
|
+
*
|
|
24
|
+
* Routes behind `isAllowed` look the caller up in the `operators`
|
|
25
|
+
* collection by uid, so a token minted without one is rejected with
|
|
26
|
+
* "Require <uid> generated accessToken" no matter how valid the connector
|
|
27
|
+
* credentials are. Omit it for pure machine-to-machine access.
|
|
28
|
+
*/
|
|
29
|
+
uid?: string
|
|
30
|
+
autorefresh?: boolean
|
|
31
|
+
onNewToken?: ( token: string ) => void
|
|
32
|
+
/** Host to substitute for `localhost` in `dev` (Eg. a native emulator) */
|
|
33
|
+
devHostname?: string
|
|
34
|
+
}
|
|
35
|
+
|
|
6
36
|
type AuthResponse = {
|
|
7
37
|
error: boolean
|
|
8
38
|
message: string
|
|
9
|
-
|
|
39
|
+
data: {
|
|
40
|
+
token: string
|
|
41
|
+
}
|
|
10
42
|
}
|
|
11
43
|
|
|
12
44
|
export default class Auth {
|
|
13
45
|
private version: number
|
|
14
|
-
private
|
|
15
|
-
|
|
46
|
+
private env: AuthConfig['env']
|
|
47
|
+
private cid: string
|
|
48
|
+
private secret: string
|
|
49
|
+
private context: string
|
|
50
|
+
private uid?: string
|
|
51
|
+
private remoteOrigin?: string
|
|
16
52
|
private refreshTimer?: NodeJS.Timeout
|
|
17
53
|
private autorefresh?: boolean
|
|
18
54
|
private onNewToken?: (token: string) => void
|
|
@@ -20,32 +56,29 @@ export default class Auth {
|
|
|
20
56
|
private isRotating: boolean = false
|
|
21
57
|
public accessToken?: string
|
|
22
58
|
|
|
23
|
-
constructor(
|
|
24
|
-
if( !
|
|
25
|
-
if( !
|
|
26
|
-
if( !
|
|
27
|
-
if( !
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
this.
|
|
31
|
-
this.
|
|
32
|
-
|
|
33
|
-
this.
|
|
34
|
-
this.
|
|
35
|
-
this.
|
|
36
|
-
this.
|
|
59
|
+
constructor( config: AuthConfig ){
|
|
60
|
+
if( !config ) throw new Error('Undefined config. Check https://doc.dedot.io/sdk/auth')
|
|
61
|
+
if( !config.context ) throw new Error('Undefined context. Check https://doc.dedot.io/sdk/auth')
|
|
62
|
+
if( !config.cid ) throw new Error('Undefined cid. Check https://doc.dedot.io/sdk/auth')
|
|
63
|
+
if( !config.secret ) throw new Error('Undefined secret. Check https://doc.dedot.io/sdk/auth')
|
|
64
|
+
|
|
65
|
+
this.context = config.context
|
|
66
|
+
this.uid = config.uid
|
|
67
|
+
this.cid = config.cid
|
|
68
|
+
this.secret = config.secret
|
|
69
|
+
this.remoteOrigin = config.remoteOrigin
|
|
70
|
+
this.env = config.env || 'dev'
|
|
71
|
+
this.version = config.version || 1
|
|
72
|
+
this.baseURL = baseURL('API', this.env, config.devHostname )
|
|
73
|
+
this.autorefresh = config.autorefresh || false
|
|
74
|
+
this.onNewToken = config.onNewToken
|
|
37
75
|
}
|
|
38
76
|
|
|
39
77
|
private async request<T>({ url, ...options }: AuthRequestOptions ): Promise<T> {
|
|
40
78
|
const rawOptions: any = {
|
|
41
79
|
method: 'GET',
|
|
42
80
|
headers: {
|
|
43
|
-
|
|
44
|
-
* Default User agent for SDK request calls
|
|
45
|
-
*
|
|
46
|
-
* NOTE: Later replace by latest SDK version
|
|
47
|
-
*/
|
|
48
|
-
'origin': this.creds.remoteOrigin,
|
|
81
|
+
'origin': this.remoteOrigin,
|
|
49
82
|
'de-user-agent': `De.remote/${this.version}.0`
|
|
50
83
|
}
|
|
51
84
|
}
|
|
@@ -68,7 +101,7 @@ export default class Auth {
|
|
|
68
101
|
}
|
|
69
102
|
|
|
70
103
|
private debug( ...args: any[] ){
|
|
71
|
-
this.
|
|
104
|
+
this.env === 'dev' && console.debug('[Auth]', ...args )
|
|
72
105
|
}
|
|
73
106
|
private error( ...args: any[] ){
|
|
74
107
|
console.error('[Auth]', ...args )
|
|
@@ -99,15 +132,15 @@ export default class Auth {
|
|
|
99
132
|
options: AuthRequestOptions = {
|
|
100
133
|
url: '/access/token',
|
|
101
134
|
method: 'POST',
|
|
102
|
-
body: this.
|
|
135
|
+
body: { context: this.context, cid: this.cid, secret: this.secret, remoteOrigin: this.remoteOrigin, ...( this.uid ? { uid: this.uid } : {} ) }
|
|
103
136
|
},
|
|
104
|
-
{ error, message,
|
|
137
|
+
{ error, message, data } = await this.request<AuthResponse>( options )
|
|
105
138
|
if( error ) throw new Error( message )
|
|
106
139
|
|
|
107
|
-
this.accessToken = token
|
|
140
|
+
this.accessToken = data.token
|
|
108
141
|
this.scheduleRotation() // Schedule auto-refresh
|
|
109
142
|
|
|
110
|
-
return token
|
|
143
|
+
return data.token
|
|
111
144
|
}
|
|
112
145
|
|
|
113
146
|
async rotateToken(): Promise<string> {
|
|
@@ -127,23 +160,23 @@ export default class Auth {
|
|
|
127
160
|
options: AuthRequestOptions = {
|
|
128
161
|
url: '/access/token/rotate',
|
|
129
162
|
method: 'PATCH',
|
|
130
|
-
body: { secret: this.
|
|
163
|
+
body: { secret: this.secret }
|
|
131
164
|
},
|
|
132
|
-
{ error, message,
|
|
165
|
+
{ error, message, data } = await this.request<AuthResponse>( options )
|
|
133
166
|
if( error ) throw new Error( message )
|
|
134
167
|
|
|
135
|
-
this.accessToken = token
|
|
168
|
+
this.accessToken = data.token
|
|
136
169
|
|
|
137
170
|
// Notify callback listener
|
|
138
171
|
if( typeof this.onNewToken === 'function' )
|
|
139
|
-
try { this.onNewToken( token ) }
|
|
172
|
+
try { this.onNewToken( data.token ) }
|
|
140
173
|
catch( callbackError ){ this.error('[Auth] Error in onNewToken callback:', callbackError) }
|
|
141
174
|
|
|
142
175
|
// Schedule next rotation
|
|
143
176
|
this.scheduleRotation()
|
|
144
177
|
|
|
145
178
|
this.debug('Token rotated successfully')
|
|
146
|
-
return token
|
|
179
|
+
return data.token
|
|
147
180
|
}
|
|
148
181
|
catch( error: any ){
|
|
149
182
|
this.debug('Refresh access token failed:', error.message)
|
package/src/baseUrl.ts
CHANGED
|
@@ -1,13 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service base URLs per environment.
|
|
3
|
+
*
|
|
4
|
+
* Only the `dev` hosts are overridable. A React Native app cannot reach the
|
|
5
|
+
* host machine on `localhost` -- the Android emulator maps it to 10.0.2.2, and
|
|
6
|
+
* a physical device needs the machine's LAN address -- so the platform entry
|
|
7
|
+
* resolves an appropriate host and passes it down as `devHostname`.
|
|
8
|
+
*
|
|
9
|
+
* The resolution deliberately lives in the caller rather than here: importing
|
|
10
|
+
* react-native's `Platform` at this level would drag the whole framework into
|
|
11
|
+
* the Node and browser builds.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const DEV_PORTS = {
|
|
15
|
+
ASI: 44000,
|
|
16
|
+
RTS: 24800,
|
|
17
|
+
API: 24800,
|
|
18
|
+
IOT: 11011,
|
|
19
|
+
WSP: 22200
|
|
20
|
+
}
|
|
1
21
|
|
|
2
22
|
export const ASI_SERVER_BASEURL = {
|
|
3
|
-
|
|
4
|
-
|
|
23
|
+
dev: `http://localhost:${DEV_PORTS.ASI}`,
|
|
24
|
+
staging: 'https://auth.staging.dedot.io',
|
|
25
|
+
prod: 'https://auth.dedot.io'
|
|
26
|
+
}
|
|
27
|
+
// Realtime Socket
|
|
28
|
+
export const RTS_SERVER_BASEURL = {
|
|
29
|
+
dev: `http://localhost:${DEV_PORTS.RTS}`,
|
|
30
|
+
staging: 'https://api.staging.dedot.io',
|
|
31
|
+
prod: 'https://api.dedot.io'
|
|
5
32
|
}
|
|
6
33
|
export const API_SERVER_BASEURL = {
|
|
7
|
-
|
|
8
|
-
|
|
34
|
+
dev: `http://localhost:${DEV_PORTS.API}`,
|
|
35
|
+
staging: 'https://api.staging.dedot.io',
|
|
36
|
+
prod: 'https://api.dedot.io'
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* de.workspace — the control plane, a separate service from de.arch.
|
|
40
|
+
*
|
|
41
|
+
* It is not reachable through the API host: de.arch serves no `/workspace`
|
|
42
|
+
* routes, so a client pointed there gets 404 for the whole surface.
|
|
43
|
+
*
|
|
44
|
+
* The staging and production hosts follow the naming of the other services
|
|
45
|
+
* (auth.dedot.io, iot.dedot.io). Confirm them against the deployment before
|
|
46
|
+
* relying on them, and pass `baseUrl` to address a host that differs — which
|
|
47
|
+
* is also what a self-hosted De. needs, and what a dev machine running
|
|
48
|
+
* de.workspace on a port other than 22200 needs.
|
|
49
|
+
*/
|
|
50
|
+
export const WSP_SERVER_BASEURL = {
|
|
51
|
+
dev: `http://localhost:${DEV_PORTS.WSP}`,
|
|
52
|
+
staging: 'https://workspace.staging.dedot.io',
|
|
53
|
+
prod: 'https://workspace.dedot.io'
|
|
9
54
|
}
|
|
10
55
|
export const IOT_SERVER_BASEURL = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
56
|
+
dev: `http://localhost:${DEV_PORTS.IOT}`,
|
|
57
|
+
staging: 'https://iot.staging.dedot.io',
|
|
58
|
+
prod: 'https://iot.dedot.io'
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type ServerEnv = 'dev' | 'staging' | 'prod'
|
|
62
|
+
export type ServerName = keyof typeof DEV_PORTS
|
|
63
|
+
|
|
64
|
+
const BASEURLS = {
|
|
65
|
+
ASI: ASI_SERVER_BASEURL,
|
|
66
|
+
RTS: RTS_SERVER_BASEURL,
|
|
67
|
+
API: API_SERVER_BASEURL,
|
|
68
|
+
IOT: IOT_SERVER_BASEURL,
|
|
69
|
+
WSP: WSP_SERVER_BASEURL
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Resolve a service's base URL for an environment.
|
|
74
|
+
*
|
|
75
|
+
* @param server - Which service to address
|
|
76
|
+
* @param env - (Default: `dev`) Target environment
|
|
77
|
+
* @param devHostname - (Optional) Host to substitute for `localhost` in `dev`
|
|
78
|
+
* @return - Base URL
|
|
79
|
+
*/
|
|
80
|
+
export function baseURL( server: ServerName, env: ServerEnv = 'dev', devHostname?: string ): string {
|
|
81
|
+
const url = BASEURLS[ server ][ env ]
|
|
82
|
+
|
|
83
|
+
// Staging and production are fixed hosts -- an override there is meaningless
|
|
84
|
+
return env === 'dev' && devHostname
|
|
85
|
+
? `http://${devHostname}:${DEV_PORTS[ server ]}`
|
|
86
|
+
: url
|
|
87
|
+
}
|