@doist/comms-sdk 0.6.0 → 0.7.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/cjs/index.js +1 -0
- package/dist/cjs/migration.js +96 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/migration.js +92 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/migration.d.ts +78 -0
- package/package.json +20 -24
package/dist/cjs/index.js
CHANGED
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.closeDefaultDispatcher = exports.CommsApi = exports.WorkspacesClient = exports.WorkspaceUsersClient = exports.UsersClient = exports.ThreadsClient = exports.SearchClient = exports.ReactionsClient = exports.InboxClient = exports.HooksClient = exports.GroupsClient = exports.ConversationsClient = exports.ConversationMessagesClient = exports.CommentsClient = exports.ChannelsClient = exports.AttachmentsClient = void 0;
|
|
18
18
|
__exportStar(require("./authentication"), exports);
|
|
19
|
+
__exportStar(require("./migration"), exports);
|
|
19
20
|
var attachments_client_1 = require("./clients/attachments-client");
|
|
20
21
|
Object.defineProperty(exports, "AttachmentsClient", { enumerable: true, get: function () { return attachments_client_1.AttachmentsClient; } });
|
|
21
22
|
var channels_client_1 = require("./clients/channels-client");
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchNewCommsUrl = fetchNewCommsUrl;
|
|
4
|
+
exports.fetchNewCommsUrls = fetchNewCommsUrls;
|
|
5
|
+
const http_client_1 = require("./transport/http-client");
|
|
6
|
+
const errors_1 = require("./types/errors");
|
|
7
|
+
/**
|
|
8
|
+
* Default origin of the Twist migration backend.
|
|
9
|
+
*
|
|
10
|
+
* The `fetch_new_url` endpoint lives on Twist (`twist.com`) and authenticates
|
|
11
|
+
* with a **Twist** token, not a Comms one. This is why the migration helpers are
|
|
12
|
+
* standalone functions rather than methods on {@link CommsApi} (which is
|
|
13
|
+
* constructed with a Comms token).
|
|
14
|
+
*/
|
|
15
|
+
const DEFAULT_TWIST_BASE_URL = 'https://twist.com';
|
|
16
|
+
function getTwistMigrationUrl(baseUrl) {
|
|
17
|
+
const base = baseUrl ?? DEFAULT_TWIST_BASE_URL;
|
|
18
|
+
const trimmed = base.endsWith('/') ? base.slice(0, -1) : base;
|
|
19
|
+
return `${trimmed}/api/comms_migration/fetch_new_url`;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Translates a Twist URL to its equivalent Comms URL using Twist's
|
|
23
|
+
* `comms_migration/fetch_new_url` endpoint.
|
|
24
|
+
*
|
|
25
|
+
* Authenticates with a **Twist** token (external to the Comms SDK), so this is a
|
|
26
|
+
* standalone helper rather than a method on {@link CommsApi}.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const newUrl = await fetchNewCommsUrl({
|
|
31
|
+
* oldUrl: 'https://twist.com/a/123/ch/456/t/789',
|
|
32
|
+
* twistToken: process.env.TWIST_AUTH_TOKEN,
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @returns The equivalent Comms URL.
|
|
37
|
+
* @throws {@link CommsRequestError} If the request fails. URLs that cannot be
|
|
38
|
+
* migrated surface as a thrown error too: `400` with `responseData.error.code`
|
|
39
|
+
* of `'invalid_url'`, or `404` with `'not_imported'`.
|
|
40
|
+
*/
|
|
41
|
+
async function fetchNewCommsUrl(args, options) {
|
|
42
|
+
const response = await (0, http_client_1.request)({
|
|
43
|
+
httpMethod: 'POST',
|
|
44
|
+
baseUri: getTwistMigrationUrl(options?.baseUrl),
|
|
45
|
+
relativePath: '',
|
|
46
|
+
apiToken: args.twistToken,
|
|
47
|
+
payload: { oldUrl: args.oldUrl },
|
|
48
|
+
customFetch: options?.customFetch,
|
|
49
|
+
});
|
|
50
|
+
const newUrl = response.data?.newUrl;
|
|
51
|
+
if (!newUrl) {
|
|
52
|
+
throw new errors_1.CommsRequestError('Migration response did not contain a new URL.', response.status, response.data);
|
|
53
|
+
}
|
|
54
|
+
return newUrl;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Translates multiple Twist URLs to their equivalent Comms URLs.
|
|
58
|
+
*
|
|
59
|
+
* URLs are processed **sequentially** to stay friendly to the rate-sensitive
|
|
60
|
+
* migration endpoint. A failure on one URL does not abort the run: each result
|
|
61
|
+
* carries either a `newUrl` (success) or a `CommsRequestError` (failure), in the
|
|
62
|
+
* same order as the input.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const results = await fetchNewCommsUrls({
|
|
67
|
+
* oldUrls: ['https://twist.com/a/1/ch/2/t/3', 'https://twist.com/bad'],
|
|
68
|
+
* twistToken: process.env.TWIST_AUTH_TOKEN,
|
|
69
|
+
* })
|
|
70
|
+
* for (const result of results) {
|
|
71
|
+
* if (result.newUrl) console.log(`${result.oldUrl} -> ${result.newUrl}`)
|
|
72
|
+
* else console.warn(`${result.oldUrl} failed`, result.error)
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @returns One {@link MigrationResult} per input URL, in input order.
|
|
77
|
+
* @throws Re-throws any error that is not a {@link CommsRequestError}.
|
|
78
|
+
*/
|
|
79
|
+
async function fetchNewCommsUrls(args, options) {
|
|
80
|
+
const results = [];
|
|
81
|
+
for (const oldUrl of args.oldUrls) {
|
|
82
|
+
try {
|
|
83
|
+
const newUrl = await fetchNewCommsUrl({ oldUrl, twistToken: args.twistToken }, options);
|
|
84
|
+
results.push({ oldUrl, newUrl });
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
if (error instanceof errors_1.CommsRequestError) {
|
|
88
|
+
results.push({ oldUrl, error });
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return results;
|
|
96
|
+
}
|
package/dist/esm/index.js
CHANGED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { request } from './transport/http-client.js';
|
|
2
|
+
import { CommsRequestError } from './types/errors.js';
|
|
3
|
+
/**
|
|
4
|
+
* Default origin of the Twist migration backend.
|
|
5
|
+
*
|
|
6
|
+
* The `fetch_new_url` endpoint lives on Twist (`twist.com`) and authenticates
|
|
7
|
+
* with a **Twist** token, not a Comms one. This is why the migration helpers are
|
|
8
|
+
* standalone functions rather than methods on {@link CommsApi} (which is
|
|
9
|
+
* constructed with a Comms token).
|
|
10
|
+
*/
|
|
11
|
+
const DEFAULT_TWIST_BASE_URL = 'https://twist.com';
|
|
12
|
+
function getTwistMigrationUrl(baseUrl) {
|
|
13
|
+
const base = baseUrl ?? DEFAULT_TWIST_BASE_URL;
|
|
14
|
+
const trimmed = base.endsWith('/') ? base.slice(0, -1) : base;
|
|
15
|
+
return `${trimmed}/api/comms_migration/fetch_new_url`;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Translates a Twist URL to its equivalent Comms URL using Twist's
|
|
19
|
+
* `comms_migration/fetch_new_url` endpoint.
|
|
20
|
+
*
|
|
21
|
+
* Authenticates with a **Twist** token (external to the Comms SDK), so this is a
|
|
22
|
+
* standalone helper rather than a method on {@link CommsApi}.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const newUrl = await fetchNewCommsUrl({
|
|
27
|
+
* oldUrl: 'https://twist.com/a/123/ch/456/t/789',
|
|
28
|
+
* twistToken: process.env.TWIST_AUTH_TOKEN,
|
|
29
|
+
* })
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @returns The equivalent Comms URL.
|
|
33
|
+
* @throws {@link CommsRequestError} If the request fails. URLs that cannot be
|
|
34
|
+
* migrated surface as a thrown error too: `400` with `responseData.error.code`
|
|
35
|
+
* of `'invalid_url'`, or `404` with `'not_imported'`.
|
|
36
|
+
*/
|
|
37
|
+
export async function fetchNewCommsUrl(args, options) {
|
|
38
|
+
const response = await request({
|
|
39
|
+
httpMethod: 'POST',
|
|
40
|
+
baseUri: getTwistMigrationUrl(options?.baseUrl),
|
|
41
|
+
relativePath: '',
|
|
42
|
+
apiToken: args.twistToken,
|
|
43
|
+
payload: { oldUrl: args.oldUrl },
|
|
44
|
+
customFetch: options?.customFetch,
|
|
45
|
+
});
|
|
46
|
+
const newUrl = response.data?.newUrl;
|
|
47
|
+
if (!newUrl) {
|
|
48
|
+
throw new CommsRequestError('Migration response did not contain a new URL.', response.status, response.data);
|
|
49
|
+
}
|
|
50
|
+
return newUrl;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Translates multiple Twist URLs to their equivalent Comms URLs.
|
|
54
|
+
*
|
|
55
|
+
* URLs are processed **sequentially** to stay friendly to the rate-sensitive
|
|
56
|
+
* migration endpoint. A failure on one URL does not abort the run: each result
|
|
57
|
+
* carries either a `newUrl` (success) or a `CommsRequestError` (failure), in the
|
|
58
|
+
* same order as the input.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const results = await fetchNewCommsUrls({
|
|
63
|
+
* oldUrls: ['https://twist.com/a/1/ch/2/t/3', 'https://twist.com/bad'],
|
|
64
|
+
* twistToken: process.env.TWIST_AUTH_TOKEN,
|
|
65
|
+
* })
|
|
66
|
+
* for (const result of results) {
|
|
67
|
+
* if (result.newUrl) console.log(`${result.oldUrl} -> ${result.newUrl}`)
|
|
68
|
+
* else console.warn(`${result.oldUrl} failed`, result.error)
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @returns One {@link MigrationResult} per input URL, in input order.
|
|
73
|
+
* @throws Re-throws any error that is not a {@link CommsRequestError}.
|
|
74
|
+
*/
|
|
75
|
+
export async function fetchNewCommsUrls(args, options) {
|
|
76
|
+
const results = [];
|
|
77
|
+
for (const oldUrl of args.oldUrls) {
|
|
78
|
+
try {
|
|
79
|
+
const newUrl = await fetchNewCommsUrl({ oldUrl, twistToken: args.twistToken }, options);
|
|
80
|
+
results.push({ oldUrl, newUrl });
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
if (error instanceof CommsRequestError) {
|
|
84
|
+
results.push({ oldUrl, error });
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return results;
|
|
92
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { CommsRequestError } from './types/errors.js';
|
|
2
|
+
import type { CustomFetch } from './types/http.js';
|
|
3
|
+
export type MigrationOptions = {
|
|
4
|
+
/** Optional custom base URL for the Twist migration endpoint (testing/self-host). */
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
/** Optional custom fetch implementation for cross-platform compatibility. */
|
|
7
|
+
customFetch?: CustomFetch;
|
|
8
|
+
};
|
|
9
|
+
export type FetchNewCommsUrlArgs = {
|
|
10
|
+
/** A `twist.com` URL to translate to its Comms equivalent. */
|
|
11
|
+
oldUrl: string;
|
|
12
|
+
/** A Twist (not Comms) auth token. */
|
|
13
|
+
twistToken: string;
|
|
14
|
+
};
|
|
15
|
+
export type FetchNewCommsUrlsArgs = {
|
|
16
|
+
/** The `twist.com` URLs to translate to their Comms equivalents. */
|
|
17
|
+
oldUrls: string[];
|
|
18
|
+
/** A Twist (not Comms) auth token. */
|
|
19
|
+
twistToken: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Result of translating a single URL in a batch migration. Discriminated by the
|
|
23
|
+
* presence of `newUrl` (success) or `error` (failure).
|
|
24
|
+
*/
|
|
25
|
+
export type MigrationResult = {
|
|
26
|
+
oldUrl: string;
|
|
27
|
+
newUrl: string;
|
|
28
|
+
error?: undefined;
|
|
29
|
+
} | {
|
|
30
|
+
oldUrl: string;
|
|
31
|
+
newUrl?: undefined;
|
|
32
|
+
error: CommsRequestError;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Translates a Twist URL to its equivalent Comms URL using Twist's
|
|
36
|
+
* `comms_migration/fetch_new_url` endpoint.
|
|
37
|
+
*
|
|
38
|
+
* Authenticates with a **Twist** token (external to the Comms SDK), so this is a
|
|
39
|
+
* standalone helper rather than a method on {@link CommsApi}.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const newUrl = await fetchNewCommsUrl({
|
|
44
|
+
* oldUrl: 'https://twist.com/a/123/ch/456/t/789',
|
|
45
|
+
* twistToken: process.env.TWIST_AUTH_TOKEN,
|
|
46
|
+
* })
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @returns The equivalent Comms URL.
|
|
50
|
+
* @throws {@link CommsRequestError} If the request fails. URLs that cannot be
|
|
51
|
+
* migrated surface as a thrown error too: `400` with `responseData.error.code`
|
|
52
|
+
* of `'invalid_url'`, or `404` with `'not_imported'`.
|
|
53
|
+
*/
|
|
54
|
+
export declare function fetchNewCommsUrl(args: FetchNewCommsUrlArgs, options?: MigrationOptions): Promise<string>;
|
|
55
|
+
/**
|
|
56
|
+
* Translates multiple Twist URLs to their equivalent Comms URLs.
|
|
57
|
+
*
|
|
58
|
+
* URLs are processed **sequentially** to stay friendly to the rate-sensitive
|
|
59
|
+
* migration endpoint. A failure on one URL does not abort the run: each result
|
|
60
|
+
* carries either a `newUrl` (success) or a `CommsRequestError` (failure), in the
|
|
61
|
+
* same order as the input.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const results = await fetchNewCommsUrls({
|
|
66
|
+
* oldUrls: ['https://twist.com/a/1/ch/2/t/3', 'https://twist.com/bad'],
|
|
67
|
+
* twistToken: process.env.TWIST_AUTH_TOKEN,
|
|
68
|
+
* })
|
|
69
|
+
* for (const result of results) {
|
|
70
|
+
* if (result.newUrl) console.log(`${result.oldUrl} -> ${result.newUrl}`)
|
|
71
|
+
* else console.warn(`${result.oldUrl} failed`, result.error)
|
|
72
|
+
* }
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @returns One {@link MigrationResult} per input URL, in input order.
|
|
76
|
+
* @throws Re-throws any error that is not a {@link CommsRequestError}.
|
|
77
|
+
*/
|
|
78
|
+
export declare function fetchNewCommsUrls(args: FetchNewCommsUrlsArgs, options?: MigrationOptions): Promise<MigrationResult[]>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@doist/comms-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "A TypeScript wrapper for the Comms REST API.",
|
|
5
5
|
"author": "Doist developers",
|
|
6
6
|
"homepage": "https://doist.github.io/comms-sdk-typescript/",
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
},
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"type": "module",
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=20.18.1"
|
|
16
|
+
},
|
|
14
17
|
"main": "dist/cjs/index.js",
|
|
15
18
|
"module": "dist/esm/index.js",
|
|
16
19
|
"types": "dist/types/index.d.ts",
|
|
@@ -43,36 +46,29 @@
|
|
|
43
46
|
"prepare": "npm run build"
|
|
44
47
|
},
|
|
45
48
|
"dependencies": {
|
|
46
|
-
"camelcase": "
|
|
47
|
-
"ts-custom-error": "
|
|
48
|
-
"undici": "7.
|
|
49
|
-
"uuid": "
|
|
50
|
-
"zod": "4.
|
|
49
|
+
"camelcase": "9.0.0",
|
|
50
|
+
"ts-custom-error": "3.3.1",
|
|
51
|
+
"undici": "7.28.0",
|
|
52
|
+
"uuid": "11.1.1",
|
|
53
|
+
"zod": "4.4.3"
|
|
51
54
|
},
|
|
52
55
|
"devDependencies": {
|
|
53
|
-
"@arethetypeswrong/cli": "0.18.
|
|
56
|
+
"@arethetypeswrong/cli": "0.18.4",
|
|
54
57
|
"@semantic-release/changelog": "6.0.3",
|
|
55
58
|
"@semantic-release/git": "10.0.1",
|
|
56
|
-
"conventional-changelog-conventionalcommits": "9.3.
|
|
59
|
+
"conventional-changelog-conventionalcommits": "9.3.1",
|
|
57
60
|
"husky": "9.1.7",
|
|
58
|
-
"lint-staged": "
|
|
59
|
-
"msw": "
|
|
60
|
-
"npm-run-all2": "
|
|
61
|
-
"obsidian": "
|
|
62
|
-
"oxfmt": "0.
|
|
63
|
-
"oxlint": "1.
|
|
64
|
-
"rimraf": "6.1.
|
|
65
|
-
"semantic-release": "25.0.
|
|
61
|
+
"lint-staged": "17.0.8",
|
|
62
|
+
"msw": "2.14.6",
|
|
63
|
+
"npm-run-all2": "9.0.2",
|
|
64
|
+
"obsidian": "1.13.1",
|
|
65
|
+
"oxfmt": "0.56.0",
|
|
66
|
+
"oxlint": "1.71.0",
|
|
67
|
+
"rimraf": "6.1.3",
|
|
68
|
+
"semantic-release": "25.0.5",
|
|
66
69
|
"ts-node": "10.9.2",
|
|
67
|
-
"type-fest": "^5.0.0",
|
|
68
70
|
"typescript": "5.9.3",
|
|
69
|
-
"vitest": "4.
|
|
70
|
-
},
|
|
71
|
-
"peerDependencies": {
|
|
72
|
-
"type-fest": "^4.12.0 || ^5.1.0"
|
|
73
|
-
},
|
|
74
|
-
"overrides": {
|
|
75
|
-
"fflate": "0.8.2"
|
|
71
|
+
"vitest": "4.1.9"
|
|
76
72
|
},
|
|
77
73
|
"husky": {
|
|
78
74
|
"hooks": {
|