@juzi/wechaty-puppet-service 1.0.14 → 1.0.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juzi/wechaty-puppet-service",
3
- "version": "1.0.14",
3
+ "version": "1.0.18",
4
4
  "description": "Puppet Service for Wechaty",
5
5
  "type": "module",
6
6
  "exports": {
@@ -65,10 +65,10 @@
65
65
  "why-is-node-running": "^2.2.1"
66
66
  },
67
67
  "peerDependencies": {
68
- "@juzi/wechaty-puppet": "1.0.9"
68
+ "@juzi/wechaty-puppet": "^1.0.15"
69
69
  },
70
70
  "dependencies": {
71
- "@juzi/wechaty-grpc": "1.0.9",
71
+ "@juzi/wechaty-grpc": "^1.0.12",
72
72
  "clone-class": "^1.1.1",
73
73
  "ducks": "^1.0.2",
74
74
  "file-box": "^1.5.5",
@@ -68,6 +68,7 @@ import { packageJson } from '../package-json.js'
68
68
 
69
69
  import { GrpcManager } from './grpc-manager.js'
70
70
  import { PayloadStore } from './payload-store.js'
71
+ import type { TagIdentifier } from '@juzi/wechaty-puppet/filters'
71
72
 
72
73
  export type PuppetServiceOptions = PUPPET.PuppetOptions & {
73
74
  authority? : string
@@ -1432,13 +1433,20 @@ class PuppetService extends PUPPET.Puppet {
1432
1433
 
1433
1434
  override async roomDel (
1434
1435
  roomId : string,
1435
- contactId : string,
1436
+ contactIds : string | string[],
1436
1437
  ): Promise<void> {
1437
- log.verbose('PuppetService', 'roomDel(%s, %s)', roomId, contactId)
1438
+ log.verbose('PuppetService', 'roomDel(%s, %s)', roomId, contactIds)
1438
1439
 
1439
1440
  const request = new grpcPuppet.RoomDelRequest()
1440
1441
  request.setId(roomId)
1441
- request.setContactId(contactId)
1442
+ if (Array.isArray(contactIds)) {
1443
+ request.setContactIdsList(contactIds)
1444
+ if (contactIds.length === 1) {
1445
+ request.setContactId(contactIds[0] as string)
1446
+ }
1447
+ } else {
1448
+ request.setContactId(contactIds)
1449
+ }
1442
1450
 
1443
1451
  await util.promisify(
1444
1452
  this.grpcManager.client.roomDel
@@ -1915,144 +1923,67 @@ class PuppetService extends PUPPET.Puppet {
1915
1923
  )(request)
1916
1924
  }
1917
1925
 
1918
- /**
1919
- *
1920
- * Tag
1921
- *
1922
- */
1923
- // add a tag for a Contact. Create it first if it not exist.
1924
- override async tagContactAdd (
1925
- id: string,
1926
- contactId: string,
1927
- ): Promise<void> {
1928
- log.verbose('PuppetService', 'tagContactAdd(%s, %s)', id, contactId)
1929
-
1930
- const request = new grpcPuppet.TagContactAddRequest()
1931
- request.setId(id)
1932
- request.setContactId(contactId)
1933
-
1934
- await util.promisify(
1935
- this.grpcManager.client.tagContactAdd
1936
- .bind(this.grpcManager.client),
1937
- )(request)
1938
- }
1939
-
1940
- // remove a tag from the Contact
1941
- override async tagContactRemove (
1942
- id: string,
1943
- contactId: string,
1944
- ) : Promise<void> {
1945
- log.verbose('PuppetService', 'tagContactRemove(%s, %s)', id, contactId)
1946
-
1947
- const request = new grpcPuppet.TagContactRemoveRequest()
1948
- request.setId(id)
1949
- request.setContactId(contactId)
1950
-
1951
- await util.promisify(
1952
- this.grpcManager.client.tagContactRemove
1953
- .bind(this.grpcManager.client),
1954
- )(request)
1955
- }
1956
-
1957
- // delete a tag from Wechat
1958
- override async tagContactDelete (
1959
- id: string,
1960
- ) : Promise<void> {
1961
- log.verbose('PuppetService', 'tagContactDelete(%s)', id)
1962
-
1963
- const request = new grpcPuppet.TagContactDeleteRequest()
1964
- request.setId(id)
1965
-
1966
- await util.promisify(
1967
- this.grpcManager.client.tagContactDelete
1968
- .bind(this.grpcManager.client),
1969
- )(request)
1970
- }
1971
-
1972
- // get tags from a specific Contact
1973
- override async tagContactList (
1974
- contactId?: string,
1975
- ) : Promise<string[]> {
1976
- log.verbose('PuppetService', 'tagContactList(%s)', contactId)
1977
-
1978
- const request = new grpcPuppet.TagContactListRequest()
1979
-
1980
- if (typeof contactId !== 'undefined') {
1981
- request.setContactId(contactId)
1982
- {
1983
-
1984
- /**
1985
- * Huan(202110): Deprecated: will be removed after Dec 31, 2022
1986
- */
1987
- const contactIdWrapper = new StringValue()
1988
- contactIdWrapper.setValue(contactId)
1989
- request.setContactIdStringValueDeprecated(contactIdWrapper)
1990
- }
1991
- }
1992
-
1993
- const response = await util.promisify(
1994
- this.grpcManager.client.tagContactList
1995
- .bind(this.grpcManager.client),
1996
- )(request)
1997
-
1998
- return response.getIdsList()
1999
- }
2000
-
2001
1926
  /**
2002
1927
  *
2003
1928
  * Tag
2004
1929
  *
2005
1930
  */
2006
1931
 
2007
- override async corpTagContactTagAdd (
2008
- corpTagGroupId: string,
2009
- corpTagId: string,
2010
- contactId: string,
1932
+ override async tagContactTagAdd (
1933
+ tags: TagIdentifier[],
1934
+ contactIds: string[],
2011
1935
  ): Promise<void> {
2012
- log.verbose('PuppetService', 'corpTagContactTagAdd(%s, %s, %s)', corpTagGroupId, corpTagId, contactId)
1936
+ log.verbose('PuppetService', 'tagContactTagAdd(%s, %s)', JSON.stringify(tags), contactIds)
2013
1937
 
2014
- const request = new grpcPuppet.CorpTagContactTagAddRequest()
1938
+ const request = new grpcPuppet.TagContactTagAddRequest()
2015
1939
 
2016
- request.setCorpTagGroupId(corpTagGroupId)
2017
- request.setCorpTagId(corpTagId)
2018
- request.setContactId(contactId)
1940
+ request.setTagsList(tags.map(t => {
1941
+ const tag = new grpcPuppet.TagIdentifier()
1942
+ t.groupId && tag.setGroupId(t.groupId)
1943
+ tag.setId(t.id)
1944
+ return tag
1945
+ }))
1946
+ request.setContactIdsList(contactIds)
2019
1947
 
2020
1948
  await util.promisify(
2021
- this.grpcManager.client.corpTagContactTagAdd
1949
+ this.grpcManager.client.tagContactTagAdd
2022
1950
  .bind(this.grpcManager.client),
2023
1951
  )(request)
2024
1952
  }
2025
1953
 
2026
- override async corpTagContactTagRemove (
2027
- corpTagGroupId: string,
2028
- corpTagId: string,
2029
- contactId: string,
1954
+ override async tagContactTagRemove (
1955
+ tags: TagIdentifier[],
1956
+ contactIds: string[],
2030
1957
  ): Promise<void> {
2031
- log.verbose('PuppetService', 'corpTagContactRemoveAdd(%s, %s, %s)', corpTagGroupId, corpTagId, contactId)
1958
+ log.verbose('PuppetService', 'tagContactTagRemove(%s, %s)', JSON.stringify(tags), contactIds)
2032
1959
 
2033
- const request = new grpcPuppet.CorpTagContactTagRemoveRequest()
1960
+ const request = new grpcPuppet.TagContactTagRemoveRequest()
2034
1961
 
2035
- request.setCorpTagGroupId(corpTagGroupId)
2036
- request.setCorpTagId(corpTagId)
2037
- request.setContactId(contactId)
1962
+ request.setTagsList(tags.map(t => {
1963
+ const tag = new grpcPuppet.TagIdentifier()
1964
+ t.groupId && tag.setGroupId(t.groupId)
1965
+ tag.setId(t.id)
1966
+ return tag
1967
+ }))
1968
+ request.setContactIdsList(contactIds)
2038
1969
 
2039
1970
  await util.promisify(
2040
- this.grpcManager.client.corpTagContactTagRemove
1971
+ this.grpcManager.client.tagContactTagRemove
2041
1972
  .bind(this.grpcManager.client),
2042
1973
  )(request)
2043
1974
  }
2044
1975
 
2045
- override async corpTagGroupAdd (
2046
- corpTagGroupName: string,
2047
- ): Promise<PUPPET.payloads.CorpTagGroup | void> {
2048
- log.verbose('PuppetService', 'corpTagGroupAdd(%s)', corpTagGroupName)
1976
+ override async tagGroupAdd (
1977
+ tagGroupName: string,
1978
+ ): Promise<PUPPET.payloads.TagGroup | void> {
1979
+ log.verbose('PuppetService', 'tagGroupAdd(%s)', tagGroupName)
2049
1980
 
2050
- const request = new grpcPuppet.CorpTagGroupAddRequest()
1981
+ const request = new grpcPuppet.TagGroupAddRequest()
2051
1982
 
2052
- request.setCorpTagGroupName(corpTagGroupName)
1983
+ request.setTagGroupName(tagGroupName)
2053
1984
 
2054
1985
  const result = await util.promisify(
2055
- this.grpcManager.client.corpTagGroupAdd
1986
+ this.grpcManager.client.tagGroupAdd
2056
1987
  .bind(this.grpcManager.client),
2057
1988
  )(request)
2058
1989
 
@@ -2061,7 +1992,7 @@ class PuppetService extends PUPPET.Puppet {
2061
1992
  const name = grpcPayload?.getName()
2062
1993
 
2063
1994
  if (id && name) {
2064
- const payload: PUPPET.payloads.CorpTagGroup = {
1995
+ const payload: PUPPET.payloads.TagGroup = {
2065
1996
  id,
2066
1997
  name,
2067
1998
  }
@@ -2070,35 +2001,37 @@ class PuppetService extends PUPPET.Puppet {
2070
2001
 
2071
2002
  }
2072
2003
 
2073
- override async corpTagGroupDelete (
2074
- corpTagGroupId: string,
2004
+ override async tagGroupDelete (
2005
+ tagGroupId: string,
2075
2006
  ): Promise<void> {
2076
- log.verbose('PuppetService', 'corpTagGroupDelete(%s)', corpTagGroupId)
2007
+ log.verbose('PuppetService', 'tagGroupDelete(%s)', tagGroupId)
2077
2008
 
2078
- const request = new grpcPuppet.CorpTagGroupDeleteRequest()
2009
+ const request = new grpcPuppet.TagGroupDeleteRequest()
2079
2010
 
2080
- request.setCorpTagGroupId(corpTagGroupId)
2011
+ request.setTagGroupId(tagGroupId)
2081
2012
 
2082
2013
  await util.promisify(
2083
- this.grpcManager.client.corpTagGroupDelete
2014
+ this.grpcManager.client.tagGroupDelete
2084
2015
  .bind(this.grpcManager.client),
2085
2016
  )(request)
2086
2017
 
2087
2018
  }
2088
2019
 
2089
- override async corpTagTagAdd (
2090
- corpTagGroupId: string,
2091
- corpTagName: string,
2092
- ): Promise<PUPPET.payloads.CorpTag | void> {
2093
- log.verbose('PuppetService', 'corpTagTagAdd(%s, %s)', corpTagGroupId, corpTagName)
2020
+ override async tagTagAdd (
2021
+ tagName: string,
2022
+ tagGroupId?: string,
2023
+ ): Promise<PUPPET.payloads.Tag | void> {
2024
+ log.verbose('PuppetService', 'tagTagAdd(%s, %s)', tagName, tagGroupId)
2094
2025
 
2095
- const request = new grpcPuppet.CorpTagTagAddRequest()
2026
+ const request = new grpcPuppet.TagTagAddRequest()
2096
2027
 
2097
- request.setCorpTagGroupId(corpTagGroupId)
2098
- request.setCorpTagName(corpTagName)
2028
+ if (typeof tagGroupId !== 'undefined') {
2029
+ request.setTagGroupId(tagGroupId)
2030
+ }
2031
+ request.setTagName(tagName)
2099
2032
 
2100
2033
  const result = await util.promisify(
2101
- this.grpcManager.client.corpTagTagAdd
2034
+ this.grpcManager.client.tagTagAdd
2102
2035
  .bind(this.grpcManager.client),
2103
2036
  )(request)
2104
2037
 
@@ -2106,104 +2039,157 @@ class PuppetService extends PUPPET.Puppet {
2106
2039
  const id = grpcPayload?.getId()
2107
2040
  const name = grpcPayload?.getName()
2108
2041
  const groupId = grpcPayload?.getGroupId()
2042
+ const type = grpcPayload?.getType()
2109
2043
 
2110
- if (id && name && groupId) {
2111
- const payload: PUPPET.payloads.CorpTag = {
2044
+ if (id && name && (typeof type !== 'undefined')) {
2045
+ const payload: PUPPET.payloads.Tag = {
2112
2046
  id,
2113
2047
  name,
2114
2048
  groupId,
2049
+ type,
2115
2050
  }
2116
2051
  return payload
2117
2052
  }
2118
2053
 
2119
2054
  }
2120
2055
 
2121
- override async corpTagTagDelete (
2122
- corpTagGroupId: string,
2123
- corpTagId: string,
2056
+ override async tagTagDelete (
2057
+ tag: TagIdentifier,
2124
2058
  ): Promise<void> {
2125
- log.verbose('PuppetService', 'corpTagTagDelete(%s, %s)', corpTagGroupId, corpTagId)
2059
+ log.verbose('PuppetService', 'tagTagDelete(%s)', JSON.stringify(tag))
2060
+
2061
+ const request = new grpcPuppet.TagTagDeleteRequest()
2062
+ const tagProb = new grpcPuppet.TagIdentifier()
2126
2063
 
2127
- const request = new grpcPuppet.CorpTagTagDeleteRequest()
2064
+ tag.groupId && tagProb.setGroupId(tag.groupId)
2065
+ tagProb.setId(tag.id)
2066
+ request.setTag(tagProb)
2128
2067
 
2129
- request.setCorpTagGroupId(corpTagGroupId)
2130
- request.setCorpTagId(corpTagId)
2068
+ request.setTag(tagProb)
2131
2069
 
2132
2070
  await util.promisify(
2133
- this.grpcManager.client.corpTagTagDelete
2071
+ this.grpcManager.client.tagTagDelete
2134
2072
  .bind(this.grpcManager.client),
2135
2073
  )(request)
2136
2074
 
2137
2075
  }
2138
2076
 
2139
- override async corpTagGroupList (): Promise<PUPPET.payloads.CorpTagGroup[]> {
2140
- log.verbose('PuppetService', 'corpTagGroupList()')
2077
+ override async tagGroupList (): Promise<PUPPET.payloads.TagGroup[]> {
2078
+ log.verbose('PuppetService', 'tagGroupList()')
2141
2079
 
2142
- const request = new grpcPuppet.CorpTagGroupListRequest()
2080
+ const request = new grpcPuppet.TagGroupListRequest()
2143
2081
 
2144
2082
  const result = await util.promisify(
2145
- this.grpcManager.client.corpTagGroupList
2083
+ this.grpcManager.client.tagGroupList
2146
2084
  .bind(this.grpcManager.client),
2147
2085
  )(request)
2148
2086
 
2149
2087
  const grpcPayloads = result.getPayloadsList()
2150
- const payloads: PUPPET.payloads.CorpTagGroup[] = grpcPayloads.map(payload => {
2088
+ const payloads: PUPPET.payloads.TagGroup[] = grpcPayloads.map(payload => {
2151
2089
  return {
2152
2090
  id: payload.getId(),
2153
2091
  name: payload.getName(),
2154
- } as PUPPET.payloads.CorpTagGroup
2092
+ } as PUPPET.payloads.TagGroup
2155
2093
  })
2156
2094
  return payloads
2157
2095
  }
2158
2096
 
2159
- override async corpTagTagList (
2160
- corpTagGroupId: string,
2161
- ): Promise<PUPPET.payloads.CorpTag[]> {
2162
- log.verbose('PuppetService', 'corpTagTagList(%s)', corpTagGroupId)
2097
+ override async tagGroupTagList (
2098
+ tagGroupId?: string,
2099
+ ): Promise<PUPPET.payloads.Tag[]> {
2100
+ log.verbose('PuppetService', 'tagGroupTagList(%s)', tagGroupId)
2163
2101
 
2164
- const request = new grpcPuppet.CorpTagTagListRequest()
2165
- request.setCorpTagGroupId(corpTagGroupId)
2102
+ const request = new grpcPuppet.TagGroupTagListRequest()
2103
+ if (typeof tagGroupId !== 'undefined') {
2104
+ request.setTagGroupId(tagGroupId)
2105
+ }
2166
2106
 
2167
2107
  const result = await util.promisify(
2168
- this.grpcManager.client.corpTagTagList
2108
+ this.grpcManager.client.tagGroupTagList
2169
2109
  .bind(this.grpcManager.client),
2170
2110
  )(request)
2171
2111
 
2172
2112
  const grpcPayloads = result.getPayloadsList()
2173
- const payloads: PUPPET.payloads.CorpTag[] = grpcPayloads.map(payload => {
2113
+ const payloads: PUPPET.payloads.Tag[] = grpcPayloads.map(payload => {
2174
2114
  return {
2175
2115
  id: payload.getId(),
2176
2116
  name: payload.getName(),
2177
2117
  groupId: payload.getGroupId(),
2178
- } as PUPPET.payloads.CorpTag
2118
+ type: payload.getType(),
2119
+ } as PUPPET.payloads.Tag
2179
2120
  })
2180
2121
  return payloads
2181
2122
  }
2182
2123
 
2183
- override async corpTagContactTagList (
2124
+ override async tagTagList (
2125
+ ): Promise<PUPPET.payloads.Tag[]> {
2126
+ log.verbose('PuppetService', 'tagTagList()')
2127
+
2128
+ const request = new grpcPuppet.TagTagListRequest()
2129
+
2130
+ const result = await util.promisify(
2131
+ this.grpcManager.client.tagTagList
2132
+ .bind(this.grpcManager.client),
2133
+ )(request)
2134
+
2135
+ const grpcPayloads = result.getPayloadsList()
2136
+ const payloads: PUPPET.payloads.Tag[] = grpcPayloads.map(payload => {
2137
+ return {
2138
+ id: payload.getId(),
2139
+ name: payload.getName(),
2140
+ groupId: payload.getGroupId(),
2141
+ type: payload.getType(),
2142
+ } as PUPPET.payloads.Tag
2143
+ })
2144
+ return payloads
2145
+ }
2146
+
2147
+ override async tagContactTagList (
2184
2148
  contactId: string,
2185
- ): Promise<PUPPET.payloads.CorpTag[]> {
2186
- log.verbose('PuppetService', 'corpTagContactTagList(%s)', contactId)
2149
+ ): Promise<PUPPET.payloads.Tag[]> {
2150
+ log.verbose('PuppetService', 'tagContactTagList(%s)', contactId)
2187
2151
 
2188
- const request = new grpcPuppet.CorpTagContactTagListRequest()
2152
+ const request = new grpcPuppet.TagContactTagListRequest()
2189
2153
  request.setContactId(contactId)
2190
2154
 
2191
2155
  const result = await util.promisify(
2192
- this.grpcManager.client.corpTagContactTagList
2156
+ this.grpcManager.client.tagContactTagList
2193
2157
  .bind(this.grpcManager.client),
2194
2158
  )(request)
2195
2159
 
2196
2160
  const grpcPayloads = result.getPayloadsList()
2197
- const payloads: PUPPET.payloads.CorpTag[] = grpcPayloads.map(payload => {
2161
+ const payloads: PUPPET.payloads.Tag[] = grpcPayloads.map(payload => {
2198
2162
  return {
2199
2163
  id: payload.getId(),
2200
2164
  name: payload.getName(),
2201
2165
  groupId: payload.getGroupId(),
2202
- } as PUPPET.payloads.CorpTag
2166
+ type: payload.getType(),
2167
+ } as PUPPET.payloads.Tag
2203
2168
  })
2204
2169
  return payloads
2205
2170
  }
2206
2171
 
2172
+ override async tagTagContactList (
2173
+ tag: TagIdentifier,
2174
+ ): Promise<string[]> {
2175
+ log.verbose('PuppetService', 'tagTagContactList(%s)', JSON.stringify(tag))
2176
+
2177
+ const request = new grpcPuppet.TagTagContactListRequest()
2178
+ const tagProb = new grpcPuppet.TagIdentifier()
2179
+
2180
+ tag.groupId && tagProb.setGroupId(tag.groupId)
2181
+ tagProb.setId(tag.id)
2182
+ request.setTag(tagProb)
2183
+
2184
+ const result = await util.promisify(
2185
+ this.grpcManager.client.tagTagContactList
2186
+ .bind(this.grpcManager.client),
2187
+ )(request)
2188
+
2189
+ const payloads = result.getPayloadsList()
2190
+ return payloads
2191
+ }
2192
+
2207
2193
  /**
2208
2194
  * @deprecated Will be removed in v2.0
2209
2195
  */
@@ -4,7 +4,7 @@
4
4
  import type { PackageJson } from 'type-fest'
5
5
  export const packageJson: PackageJson = {
6
6
  "name": "@juzi/wechaty-puppet-service",
7
- "version": "1.0.14",
7
+ "version": "1.0.18",
8
8
  "description": "Puppet Service for Wechaty",
9
9
  "type": "module",
10
10
  "exports": {
@@ -69,10 +69,10 @@ export const packageJson: PackageJson = {
69
69
  "why-is-node-running": "^2.2.1"
70
70
  },
71
71
  "peerDependencies": {
72
- "@juzi/wechaty-puppet": "1.0.9"
72
+ "@juzi/wechaty-puppet": "^1.0.15"
73
73
  },
74
74
  "dependencies": {
75
- "@juzi/wechaty-grpc": "1.0.9",
75
+ "@juzi/wechaty-grpc": "^1.0.12",
76
76
  "clone-class": "^1.1.1",
77
77
  "ducks": "^1.0.2",
78
78
  "file-box": "^1.5.5",