dingtalk-stream 2.1.0 → 2.1.2

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/client.cjs CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ var constants = require('./constants.cjs');
3
4
  var WebSocket = require('ws');
4
5
  var axios = require('axios');
5
6
  var EventEmitter = require('events');
@@ -88,12 +89,12 @@ class DWClient extends EventEmitter {
88
89
  this.printDebug("get connect endpoint by config");
89
90
  this.printDebug(this.config);
90
91
  const result = await axios.get(
91
- `https://oapi.dingtalk.com/gettoken?appkey=${this.config.clientId}&appsecret=${this.config.clientSecret}`
92
+ `${constants.GET_TOKEN_URL}?appkey=${this.config.clientId}&appsecret=${this.config.clientSecret}`
92
93
  );
93
94
  if (result.status === 200 && result.data.access_token) {
94
95
  this.config.access_token = result.data.access_token;
95
96
  const res = await axios({
96
- url: "https://pre-api.dingtalk.com/v1.0/gateway/connections/open",
97
+ url: constants.GATEWAY_URL,
97
98
  method: "POST",
98
99
  responseType: "json",
99
100
  data: {
@@ -133,7 +134,7 @@ class DWClient extends EventEmitter {
133
134
  this.socket = new WebSocket(this.dw_url, this.sslopts);
134
135
  this.socket.on("open", () => {
135
136
  this.connected = true;
136
- this.printDebug("Socket open");
137
+ console.info("[" + (/* @__PURE__ */ new Date()).toISOString() + "] connect success");
137
138
  if (this.config.keepAlive) {
138
139
  this.isAlive = true;
139
140
  this.heartbeatIntervallId = setInterval(() => {
package/dist/client.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { GET_TOKEN_URL, GATEWAY_URL } from './constants.mjs';
1
2
  import WebSocket from 'ws';
2
3
  import axios from 'axios';
3
4
  import EventEmitter from 'events';
@@ -86,12 +87,12 @@ class DWClient extends EventEmitter {
86
87
  this.printDebug("get connect endpoint by config");
87
88
  this.printDebug(this.config);
88
89
  const result = await axios.get(
89
- `https://oapi.dingtalk.com/gettoken?appkey=${this.config.clientId}&appsecret=${this.config.clientSecret}`
90
+ `${GET_TOKEN_URL}?appkey=${this.config.clientId}&appsecret=${this.config.clientSecret}`
90
91
  );
91
92
  if (result.status === 200 && result.data.access_token) {
92
93
  this.config.access_token = result.data.access_token;
93
94
  const res = await axios({
94
- url: "https://pre-api.dingtalk.com/v1.0/gateway/connections/open",
95
+ url: GATEWAY_URL,
95
96
  method: "POST",
96
97
  responseType: "json",
97
98
  data: {
@@ -131,7 +132,7 @@ class DWClient extends EventEmitter {
131
132
  this.socket = new WebSocket(this.dw_url, this.sslopts);
132
133
  this.socket.on("open", () => {
133
134
  this.connected = true;
134
- this.printDebug("Socket open");
135
+ console.info("[" + (/* @__PURE__ */ new Date()).toISOString() + "] connect success");
135
136
  if (this.config.keepAlive) {
136
137
  this.isAlive = true;
137
138
  this.heartbeatIntervallId = setInterval(() => {
@@ -1,9 +1,13 @@
1
1
  'use strict';
2
2
 
3
+ const GATEWAY_URL = "https://api.dingtalk.com/v1.0/gateway/connections/open";
4
+ const GET_TOKEN_URL = "https://oapi.dingtalk.com/gettoken";
3
5
  const TOPIC_ROBOT = "/v1.0/im/bot/messages/get";
4
6
  const TOPIC_CARD = "/v1.0/card/instances/callback";
5
7
  const TOPIC_AI_GRAPH_API = "/v1.0/graph/api/invoke";
6
8
 
9
+ exports.GATEWAY_URL = GATEWAY_URL;
10
+ exports.GET_TOKEN_URL = GET_TOKEN_URL;
7
11
  exports.TOPIC_AI_GRAPH_API = TOPIC_AI_GRAPH_API;
8
12
  exports.TOPIC_CARD = TOPIC_CARD;
9
13
  exports.TOPIC_ROBOT = TOPIC_ROBOT;
@@ -1,3 +1,5 @@
1
+ declare const GATEWAY_URL = "https://api.dingtalk.com/v1.0/gateway/connections/open";
2
+ declare const GET_TOKEN_URL = "https://oapi.dingtalk.com/gettoken";
1
3
  /** 机器人消息回调 */
2
4
  declare const TOPIC_ROBOT = "/v1.0/im/bot/messages/get";
3
5
  /** 卡片回调 */
@@ -41,4 +43,4 @@ interface GraphAPIResponse {
41
43
  }
42
44
  type RobotMessage = RobotTextMessage;
43
45
 
44
- export { type GraphAPIResponse, type RobotMessage, type RobotTextMessage, TOPIC_AI_GRAPH_API, TOPIC_CARD, TOPIC_ROBOT };
46
+ export { GATEWAY_URL, GET_TOKEN_URL, type GraphAPIResponse, type RobotMessage, type RobotTextMessage, TOPIC_AI_GRAPH_API, TOPIC_CARD, TOPIC_ROBOT };
@@ -1,5 +1,7 @@
1
+ const GATEWAY_URL = "https://api.dingtalk.com/v1.0/gateway/connections/open";
2
+ const GET_TOKEN_URL = "https://oapi.dingtalk.com/gettoken";
1
3
  const TOPIC_ROBOT = "/v1.0/im/bot/messages/get";
2
4
  const TOPIC_CARD = "/v1.0/card/instances/callback";
3
5
  const TOPIC_AI_GRAPH_API = "/v1.0/graph/api/invoke";
4
6
 
5
- export { TOPIC_AI_GRAPH_API, TOPIC_CARD, TOPIC_ROBOT };
7
+ export { GATEWAY_URL, GET_TOKEN_URL, TOPIC_AI_GRAPH_API, TOPIC_CARD, TOPIC_ROBOT };
package/dist/index.cjs CHANGED
@@ -8,6 +8,8 @@ require('events');
8
8
 
9
9
 
10
10
 
11
+ exports.GATEWAY_URL = constants.GATEWAY_URL;
12
+ exports.GET_TOKEN_URL = constants.GET_TOKEN_URL;
11
13
  exports.TOPIC_AI_GRAPH_API = constants.TOPIC_AI_GRAPH_API;
12
14
  exports.TOPIC_CARD = constants.TOPIC_CARD;
13
15
  exports.TOPIC_ROBOT = constants.TOPIC_ROBOT;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { GraphAPIResponse, RobotMessage, RobotTextMessage, TOPIC_AI_GRAPH_API, TOPIC_CARD, TOPIC_ROBOT } from './constants.js';
1
+ export { GATEWAY_URL, GET_TOKEN_URL, GraphAPIResponse, RobotMessage, RobotTextMessage, TOPIC_AI_GRAPH_API, TOPIC_CARD, TOPIC_ROBOT } from './constants.js';
2
2
  export { DWClient, DWClientConfig, DWClientDownStream, EventAck, EventAckData, OnEventReceived } from './client.js';
3
3
  import 'events';
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { TOPIC_AI_GRAPH_API, TOPIC_CARD, TOPIC_ROBOT } from './constants.mjs';
1
+ export { GATEWAY_URL, GET_TOKEN_URL, TOPIC_AI_GRAPH_API, TOPIC_CARD, TOPIC_ROBOT } from './constants.mjs';
2
2
  export { DWClient, EventAck } from './client.mjs';
3
3
  import 'ws';
4
4
  import 'axios';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dingtalk-stream",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "Nodejs SDK for DingTalk Stream Mode API, Compared with the webhook mode, it is easier to access the DingTalk",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",