Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

02 support only esm at first #15

Draft
wants to merge 6 commits into
base: 01-02-use-vitest
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const utils = require('./utils.ts');
import { copyFile, rewriteFile } from './utils.js';

utils.copyFile('README.md', 'index.md');
utils.copyFile('CONTRIBUTING.md', 'CONTRIBUTING.md');
copyFile('README.md', 'index.md');
copyFile('CONTRIBUTING.md', 'CONTRIBUTING.md');

utils.rewriteFile('../apidocs/README.md', /\(CONTRIBUTING.md\)/g, '(../CONTRIBUTING.md)');
rewriteFile('../apidocs/README.md', /\(CONTRIBUTING.md\)/g, '(../CONTRIBUTING.md)');

export default {
title: 'line-bot-sdk-nodejs',
Expand Down
30 changes: 18 additions & 12 deletions docs/.vitepress/utils.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
const fs = require('fs');
const path = require('path');
import fs from 'node:fs';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import {dirname} from 'node:path';

// __dirname is not available in ESM, so we need to derive it
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

function copyFile(sourceFilename, targetFilename) {
const sourcePath = path.join(__dirname, '../../', sourceFilename);
const targetPath = path.join(__dirname, '../', targetFilename);
const md = fs.readFileSync(sourcePath, 'utf-8');
fs.writeFileSync(targetPath, md);
const sourcePath = path.join(__dirname, '../../', sourceFilename);
const targetPath = path.join(__dirname, '../', targetFilename);
const md = fs.readFileSync(sourcePath, 'utf-8');
fs.writeFileSync(targetPath, md);
}

function rewriteFile(filename, regex, replacement) {
console.log("Rewriting file: ", filename, " with regex: ", regex, " and replacement: ", replacement)
const content = fs.readFileSync(path.join(__dirname, filename), 'utf-8');
const newContent = content.replace(regex, replacement);
fs.writeFileSync(path.join(__dirname, filename), newContent);
console.log("Rewriting file: ", filename, " with regex: ", regex, " and replacement: ", replacement)
const content = fs.readFileSync(path.join(__dirname, filename), 'utf-8');
const newContent = content.replace(regex, replacement);
fs.writeFileSync(path.join(__dirname, filename), newContent);
}

export {
copyFile,
rewriteFile,
copyFile,
rewriteFile
};
2 changes: 1 addition & 1 deletion generate-code.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def generate_webhook():
run_command(f'rm -rf lib/webhook/tests/')

with open('lib/webhook/api.ts', 'w') as wfp:
wfp.write("""export * from './model/models';""")
wfp.write("""export * from './model/models.js';""")


def main():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{# @pebvariable name="apiInfo" type="org.openapitools.codegen.model.ApiInfoMap" #}
{% for api in apiInfo.apis -%}
export { {{ api.operations.classname }} } from './{{ api.get("classFilename") }}';
export { {{ api.operations.classname }} } from './{{ api.get("classFilename") }}.js';
{% endfor %}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

/* tslint:disable:no-unused-locals */
{% for import in imports -%}
import { {{import.classname}} } from '{{import.filename}}';
import { {{import.classname}} } from '{{import.filename}}.js';
{% endfor %}
import * as Types from "../../types";
import {ensureJSON} from "../../utils";
import * as Types from "../../types.js";
import {ensureJSON} from "../../utils.js";
import {Readable} from "node:stream";

import HTTPFetchClient, { convertResponseToReadable } from "../../http-fetch";
import HTTPFetchClient, { convertResponseToReadable } from "../../http-fetch.js";

// ===============================================
// This file is autogenerated - Please do not edit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This is the entrypoint for the package
export * from './api/apis';
export * from './model/models';
export * from './api/apis.js';
export * from './model/models.js';
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{# @pebvariable name="imports" type="java.util.List<java.util.Map<String, String>>" #}
{# @pebvariable name="operations" type="org.openapitools.codegen.model.OperationMap" #}
{# @pebvariable name="authMethods" type="java.util.ArrayList<org.openapitools.codegen.CodegenSecurity>" -#}
import { {{operations.classname}} } from "../../api";
import { {{operations.classname}} } from "../../api.js";

{% for import in imports -%}
import { {{import.classname}} } from '../{{import.filename}}';
import { {{import.classname}} } from '../{{import.filename}}.js';
{% endfor %}

import { createServer } from "node:http";
import { deepEqual, equal, ok } from "node:assert";

import { describe, it } from "vitest";

const channel_access_token = "test_channel_access_token";

{% macro paramDummyValue(param) %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
{% for model in models %}

{% for tsi in model.get('tsImports') -%}
import { {{ tsi.classname }} } from '{{ tsi.filename }}';
import { {{ tsi.classname }} } from '{{ tsi.filename }}.js';
{%- endfor %}

{% if model.model.discriminator != null %}
{% for model in model.model.discriminator.mappedModels -%}
import { {{model.modelName}} } from './models';
import { {{model.modelName}} } from './models.js';
{% endfor %}

export type {{classname}} =
Expand All @@ -30,7 +30,7 @@ export type Unknown{{classname}} = {{classname}}Base & {
{%- endif -%}
{% if not model.model.isEnum -%}
{% if model.model.parent != null %}
import { {{ model.model.parent }}Base } from './models';
import { {{ model.model.parent }}Base } from './models.js';

{% endif %}
export type {{classname}}{% if model.model.discriminator != null %}Base{% endif %} = {% if model.model.parent != null %}{{ model.model.parent }}Base & {% endif %} { {% if model.model.vendorExtensions.get("x-selector") != null %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{# @pebvariable name="models" type="java.util.ArrayList<org.openapitools.codegen.model.ModelMap>" #}
{% for model in models -%}
export * from '{{ model.model.classFilename }}';
export * from '{{ model.model.classFilename }}.js';
{%- endfor %}
4 changes: 2 additions & 2 deletions lib/channel-access-token/api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This is the entrypoint for the package
export * from "./api/apis";
export * from "./model/models";
export * from "./api/apis.js";
export * from "./model/models.js";
2 changes: 1 addition & 1 deletion lib/channel-access-token/api/apis.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { ChannelAccessTokenClient } from "./channelAccessTokenClient";
export { ChannelAccessTokenClient } from "./channelAccessTokenClient.js";
20 changes: 11 additions & 9 deletions lib/channel-access-token/api/channelAccessTokenClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@
*/

/* tslint:disable:no-unused-locals */
import { ChannelAccessTokenKeyIdsResponse } from "../model/channelAccessTokenKeyIdsResponse";
import { ErrorResponse } from "../model/errorResponse";
import { IssueChannelAccessTokenResponse } from "../model/issueChannelAccessTokenResponse";
import { IssueShortLivedChannelAccessTokenResponse } from "../model/issueShortLivedChannelAccessTokenResponse";
import { IssueStatelessChannelAccessTokenResponse } from "../model/issueStatelessChannelAccessTokenResponse";
import { VerifyChannelAccessTokenResponse } from "../model/verifyChannelAccessTokenResponse";
import { ChannelAccessTokenKeyIdsResponse } from "../model/channelAccessTokenKeyIdsResponse.js";
import { ErrorResponse } from "../model/errorResponse.js";
import { IssueChannelAccessTokenResponse } from "../model/issueChannelAccessTokenResponse.js";
import { IssueShortLivedChannelAccessTokenResponse } from "../model/issueShortLivedChannelAccessTokenResponse.js";
import { IssueStatelessChannelAccessTokenResponse } from "../model/issueStatelessChannelAccessTokenResponse.js";
import { VerifyChannelAccessTokenResponse } from "../model/verifyChannelAccessTokenResponse.js";

import * as Types from "../../types";
import { ensureJSON } from "../../utils";
import * as Types from "../../types.js";
import { ensureJSON } from "../../utils.js";
import { Readable } from "node:stream";

import HTTPFetchClient, { convertResponseToReadable } from "../../http-fetch";
import HTTPFetchClient, {
convertResponseToReadable,
} from "../../http-fetch.js";

// ===============================================
// This file is autogenerated - Please do not edit
Expand Down
12 changes: 6 additions & 6 deletions lib/channel-access-token/model/models.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from "./channelAccessTokenKeyIdsResponse";
export * from "./errorResponse";
export * from "./issueChannelAccessTokenResponse";
export * from "./issueShortLivedChannelAccessTokenResponse";
export * from "./issueStatelessChannelAccessTokenResponse";
export * from "./verifyChannelAccessTokenResponse";
export * from "./channelAccessTokenKeyIdsResponse.js";
export * from "./errorResponse.js";
export * from "./issueChannelAccessTokenResponse.js";
export * from "./issueShortLivedChannelAccessTokenResponse.js";
export * from "./issueStatelessChannelAccessTokenResponse.js";
export * from "./verifyChannelAccessTokenResponse.js";
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { ChannelAccessTokenClient } from "../../api";
import { ChannelAccessTokenClient } from "../../api.js";

import { ChannelAccessTokenKeyIdsResponse } from "../../model/channelAccessTokenKeyIdsResponse";
import { ErrorResponse } from "../../model/errorResponse";
import { IssueChannelAccessTokenResponse } from "../../model/issueChannelAccessTokenResponse";
import { IssueShortLivedChannelAccessTokenResponse } from "../../model/issueShortLivedChannelAccessTokenResponse";
import { IssueStatelessChannelAccessTokenResponse } from "../../model/issueStatelessChannelAccessTokenResponse";
import { VerifyChannelAccessTokenResponse } from "../../model/verifyChannelAccessTokenResponse";
import { ChannelAccessTokenKeyIdsResponse } from "../../model/channelAccessTokenKeyIdsResponse.js";
import { ErrorResponse } from "../../model/errorResponse.js";
import { IssueChannelAccessTokenResponse } from "../../model/issueChannelAccessTokenResponse.js";
import { IssueShortLivedChannelAccessTokenResponse } from "../../model/issueShortLivedChannelAccessTokenResponse.js";
import { IssueStatelessChannelAccessTokenResponse } from "../../model/issueStatelessChannelAccessTokenResponse.js";
import { VerifyChannelAccessTokenResponse } from "../../model/verifyChannelAccessTokenResponse.js";

import { createServer } from "node:http";
import { deepEqual, equal, ok } from "node:assert";

import { describe, it } from "vitest";

const channel_access_token = "test_channel_access_token";

describe("ChannelAccessTokenClient", () => {
Expand Down
8 changes: 4 additions & 4 deletions lib/client.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Readable } from "node:stream";
import HTTPClient from "./http-axios";
import * as Types from "./types";
import HTTPClient from "./http-axios.js";
import * as Types from "./types.js";
import { AxiosRequestConfig, AxiosResponse } from "axios";
import { createMultipartFormData, ensureJSON, toArray } from "./utils";
import { createMultipartFormData, ensureJSON, toArray } from "./utils.js";
import {
DATA_API_PREFIX,
MESSAGING_API_PREFIX,
OAUTH_BASE_PREFIX,
OAUTH_BASE_PREFIX_V2_1,
} from "./endpoints";
} from "./endpoints.js";

type ChatType = "group" | "room";
type RequestOption = {
Expand Down
4 changes: 2 additions & 2 deletions lib/http-axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import axios, {
AxiosRequestConfig,
} from "axios";
import { Readable } from "node:stream";
import { HTTPError, ReadError, RequestError } from "./exceptions";
import { USER_AGENT } from "./version";
import { HTTPError, ReadError, RequestError } from "./exceptions.js";
import { USER_AGENT } from "./version.js";

interface httpClientConfig extends Partial<AxiosRequestConfig> {
baseURL?: string;
Expand Down
4 changes: 2 additions & 2 deletions lib/http-fetch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Readable } from "node:stream";
import { HTTPFetchError } from "./exceptions";
import { USER_AGENT } from "./version";
import { HTTPFetchError } from "./exceptions.js";
import { USER_AGENT } from "./version.js";

export interface FetchRequestConfig {
headers?: Record<string, string>;
Expand Down
28 changes: 14 additions & 14 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import Client, { OAuth } from "./client";
import middleware from "./middleware";
import validateSignature from "./validate-signature";
import Client, { OAuth } from "./client.js";
import middleware from "./middleware.js";
import validateSignature from "./validate-signature.js";

export { Client, middleware, validateSignature, OAuth };

// re-export exceptions and types
export * from "./exceptions";
export * from "./types";
export * from "./exceptions.js";
export * from "./types.js";

import * as channelAccessToken from "./channel-access-token/api";
import * as channelAccessToken from "./channel-access-token/api.js";
export { channelAccessToken };
import * as insight from "./insight/api";
import * as insight from "./insight/api.js";
export { insight };
import * as liff from "./liff/api";
import * as liff from "./liff/api.js";
export { liff };
import * as manageAudience from "./manage-audience/api";
import * as manageAudience from "./manage-audience/api.js";
export { manageAudience };
import * as messagingApi from "./messaging-api/api";
import * as messagingApi from "./messaging-api/api.js";
export { messagingApi };
// Note: `module` is reserved word in Javascript.
import * as moduleOperation from "./module/api";
import * as moduleOperation from "./module/api.js";
export { moduleOperation };
import * as moduleAttach from "./module-attach/api";
import * as moduleAttach from "./module-attach/api.js";
export { moduleAttach };
import * as shop from "./shop/api";
import * as shop from "./shop/api.js";
export { shop };
import * as webhook from "./webhook/api";
import * as webhook from "./webhook/api.js";
export { webhook };
4 changes: 2 additions & 2 deletions lib/insight/api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This is the entrypoint for the package
export * from "./api/apis";
export * from "./model/models";
export * from "./api/apis.js";
export * from "./model/models.js";
2 changes: 1 addition & 1 deletion lib/insight/api/apis.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { InsightClient } from "./insightClient";
export { InsightClient } from "./insightClient.js";
20 changes: 11 additions & 9 deletions lib/insight/api/insightClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@
*/

/* tslint:disable:no-unused-locals */
import { GetFriendsDemographicsResponse } from "../model/getFriendsDemographicsResponse";
import { GetMessageEventResponse } from "../model/getMessageEventResponse";
import { GetNumberOfFollowersResponse } from "../model/getNumberOfFollowersResponse";
import { GetNumberOfMessageDeliveriesResponse } from "../model/getNumberOfMessageDeliveriesResponse";
import { GetStatisticsPerUnitResponse } from "../model/getStatisticsPerUnitResponse";

import * as Types from "../../types";
import { ensureJSON } from "../../utils";
import { GetFriendsDemographicsResponse } from "../model/getFriendsDemographicsResponse.js";
import { GetMessageEventResponse } from "../model/getMessageEventResponse.js";
import { GetNumberOfFollowersResponse } from "../model/getNumberOfFollowersResponse.js";
import { GetNumberOfMessageDeliveriesResponse } from "../model/getNumberOfMessageDeliveriesResponse.js";
import { GetStatisticsPerUnitResponse } from "../model/getStatisticsPerUnitResponse.js";

import * as Types from "../../types.js";
import { ensureJSON } from "../../utils.js";
import { Readable } from "node:stream";

import HTTPFetchClient, { convertResponseToReadable } from "../../http-fetch";
import HTTPFetchClient, {
convertResponseToReadable,
} from "../../http-fetch.js";

// ===============================================
// This file is autogenerated - Please do not edit
Expand Down
2 changes: 1 addition & 1 deletion lib/insight/model/errorResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Do not edit the class manually.
*/

import { ErrorDetail } from "./errorDetail";
import { ErrorDetail } from "./errorDetail.js";

export type ErrorResponse = {
/**
Expand Down
10 changes: 5 additions & 5 deletions lib/insight/model/getFriendsDemographicsResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
* Do not edit the class manually.
*/

import { AgeTile } from "./ageTile";
import { AppTypeTile } from "./appTypeTile";
import { AreaTile } from "./areaTile";
import { GenderTile } from "./genderTile";
import { SubscriptionPeriodTile } from "./subscriptionPeriodTile";
import { AgeTile } from "./ageTile.js";
import { AppTypeTile } from "./appTypeTile.js";
import { AreaTile } from "./areaTile.js";
import { GenderTile } from "./genderTile.js";
import { SubscriptionPeriodTile } from "./subscriptionPeriodTile.js";

/**
* Get friend demographics
Expand Down
6 changes: 3 additions & 3 deletions lib/insight/model/getMessageEventResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
* Do not edit the class manually.
*/

import { GetMessageEventResponseClick } from "./getMessageEventResponseClick";
import { GetMessageEventResponseMessage } from "./getMessageEventResponseMessage";
import { GetMessageEventResponseOverview } from "./getMessageEventResponseOverview";
import { GetMessageEventResponseClick } from "./getMessageEventResponseClick.js";
import { GetMessageEventResponseMessage } from "./getMessageEventResponseMessage.js";
import { GetMessageEventResponseOverview } from "./getMessageEventResponseOverview.js";

/**
* Statistics about how users interact with narrowcast messages or broadcast messages sent from your LINE Official Account.
Expand Down
6 changes: 3 additions & 3 deletions lib/insight/model/getStatisticsPerUnitResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
* Do not edit the class manually.
*/

import { GetStatisticsPerUnitResponseClick } from "./getStatisticsPerUnitResponseClick";
import { GetStatisticsPerUnitResponseMessage } from "./getStatisticsPerUnitResponseMessage";
import { GetStatisticsPerUnitResponseOverview } from "./getStatisticsPerUnitResponseOverview";
import { GetStatisticsPerUnitResponseClick } from "./getStatisticsPerUnitResponseClick.js";
import { GetStatisticsPerUnitResponseMessage } from "./getStatisticsPerUnitResponseMessage.js";
import { GetStatisticsPerUnitResponseOverview } from "./getStatisticsPerUnitResponseOverview.js";

/**
* Response object for `get statistics per unit`
Expand Down
Loading