line-ts 0.2.0 → 1.0.1

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.
@@ -23,7 +23,7 @@ function randomString(length = 20) {
23
23
  function getLineLoginUrl(params) {
24
24
  const { response_type = 'code', state = randomString(), scope = 'openid', redirect_uri: _redirect_uri, } = params;
25
25
  const redirect_uri = _redirect_uri.replace(/:/g, '%3A').replace(/\//g, '%2F');
26
- const paramsObject = Object.assign(Object.assign({}, params), { response_type, redirect_uri, state, scope });
26
+ const paramsObject = { ...params, response_type, redirect_uri, state, scope };
27
27
  const query = Object.entries(paramsObject)
28
28
  .map((entry) => entry.join('='))
29
29
  .join('&');
@@ -19,7 +19,7 @@ function randomString(length = 20) {
19
19
  function getLineLoginUrl(params) {
20
20
  const { response_type = 'code', state = randomString(), scope = 'openid', redirect_uri: _redirect_uri, } = params;
21
21
  const redirect_uri = _redirect_uri.replace(/:/g, '%3A').replace(/\//g, '%2F');
22
- const paramsObject = Object.assign(Object.assign({}, params), { response_type, redirect_uri, state, scope });
22
+ const paramsObject = { ...params, response_type, redirect_uri, state, scope };
23
23
  const query = Object.entries(paramsObject)
24
24
  .map((entry) => entry.join('='))
25
25
  .join('&');
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,32 +1,45 @@
1
1
  {
2
2
  "name": "line-ts",
3
3
  "sideEffects": false,
4
- "version": "0.2.0",
4
+ "type": "module",
5
+ "version": "1.0.1",
5
6
  "description": "LINE SDK for TypeScript",
6
- "main": "dist/index.cjs.js",
7
- "module": "dist/index.esm.js",
8
- "typings": "types/index.d.ts",
7
+ "module": "./dist/index.es.js",
8
+ "main": "./dist/index.cjs",
9
+ "types": "./dist/types/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/index.es.js",
13
+ "require": "./dist/index.cjs",
14
+ "types": "./dist/types/index.d.ts"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "engines": {
21
+ "node": ">=12.13"
22
+ },
9
23
  "scripts": {
10
- "test": "ava",
11
- "lint": "eslint . --ext .js,.jsx,.ts,.tsx",
12
- "rollup": "rollup -c build.js",
13
- "build": "npm run lint && npm run rollup"
24
+ "test": "echo na",
25
+ "lint": "tsc --noEmit && eslint ./src --ext .ts",
26
+ "build": "rollup -c ./scripts/build.js",
27
+ "release": "npm run lint && del dist && npm run build && np"
14
28
  },
15
- "dependencies": {},
16
29
  "devDependencies": {
17
- "@types/jsonwebtoken": "^8.5.0",
18
- "@typescript-eslint/eslint-plugin": "^2.34.0",
19
- "@typescript-eslint/parser": "^2.34.0",
20
- "ava": "^3.10.1",
21
- "eslint": "^6.8.0",
22
- "eslint-config-prettier": "^6.11.0",
23
- "eslint-plugin-tree-shaking": "^1.8.0",
24
- "prettier": "^2.0.5",
25
- "rollup": "^1.32.1",
26
- "rollup-plugin-typescript2": "^0.27.1",
27
- "ts-node": "^8.10.2",
28
- "tsconfig-paths": "^3.9.0",
29
- "typescript": "^3.9.7"
30
+ "@types/jsonwebtoken": "^8.5.8",
31
+ "@typescript-eslint/eslint-plugin": "^5.10.1",
32
+ "@typescript-eslint/parser": "^5.10.1",
33
+ "del-cli": "^4.0.1",
34
+ "eslint": "^8.7.0",
35
+ "eslint-config-prettier": "^8.3.0",
36
+ "eslint-plugin-tree-shaking": "^1.10.0",
37
+ "np": "^7.6.0",
38
+ "prettier": "^2.5.1",
39
+ "rollup": "^2.66.0",
40
+ "rollup-plugin-typescript2": "^0.31.1",
41
+ "typescript": "^4.5.5",
42
+ "vitest": "^0.2.1"
30
43
  },
31
44
  "keywords": [
32
45
  "line",
@@ -35,6 +48,7 @@
35
48
  "line-sdk"
36
49
  ],
37
50
  "author": "Luca Ban - Mesqueeb",
51
+ "funding": "https://github.com/sponsors/mesqueeb",
38
52
  "license": "MIT",
39
53
  "bugs": {
40
54
  "url": "https://github.com/mesqueeb/line-ts/issues"
@@ -44,13 +58,35 @@
44
58
  "type": "git",
45
59
  "url": "git+https://github.com/mesqueeb/line-ts.git"
46
60
  },
47
- "ava": {
48
- "extensions": [
49
- "ts"
61
+ "np": {
62
+ "yarn": false,
63
+ "branch": "production"
64
+ },
65
+ "eslintConfig": {
66
+ "ignorePatterns": [
67
+ "node_modules",
68
+ "dist",
69
+ "scripts",
70
+ "test"
71
+ ],
72
+ "root": true,
73
+ "parser": "@typescript-eslint/parser",
74
+ "plugins": [
75
+ "@typescript-eslint",
76
+ "tree-shaking"
77
+ ],
78
+ "extends": [
79
+ "eslint:recommended",
80
+ "plugin:@typescript-eslint/eslint-recommended",
81
+ "plugin:@typescript-eslint/recommended",
82
+ "prettier"
50
83
  ],
51
- "require": [
52
- "tsconfig-paths/register",
53
- "ts-node/register"
54
- ]
84
+ "rules": {
85
+ "@typescript-eslint/no-empty-function": "off",
86
+ "@typescript-eslint/no-explicit-any": "off",
87
+ "@typescript-eslint/ban-ts-ignore": "off",
88
+ "tree-shaking/no-side-effects-in-initialization": "error",
89
+ "@typescript-eslint/ban-ts-comment": "off"
90
+ }
55
91
  }
56
92
  }
package/.eslintignore DELETED
@@ -1,8 +0,0 @@
1
- # don't ever lint node_modules
2
- node_modules
3
- # don't lint build output (make sure it's set to your correct build folder name)
4
- dist
5
- # don't lint nyc coverage output
6
- coverage
7
-
8
- test
package/.eslintrc.js DELETED
@@ -1,18 +0,0 @@
1
- // npm i -D @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint eslint-config-prettier eslint-plugin-tree-shaking
2
- module.exports = {
3
- root: true,
4
- parser: '@typescript-eslint/parser',
5
- plugins: ['@typescript-eslint', 'tree-shaking'],
6
- extends: [
7
- 'eslint:recommended',
8
- 'plugin:@typescript-eslint/eslint-recommended',
9
- 'plugin:@typescript-eslint/recommended',
10
- 'prettier/@typescript-eslint',
11
- ],
12
- rules: {
13
- '@typescript-eslint/no-explicit-any': 'off',
14
- '@typescript-eslint/ban-ts-ignore': 'off',
15
- 'tree-shaking/no-side-effects-in-initialization': 'error',
16
- '@typescript-eslint/camelcase': 'off'
17
- },
18
- }
@@ -1,12 +0,0 @@
1
- # These are supported funding model platforms
2
-
3
- github: mesqueeb
4
- patreon: # Replace with a single Patreon username
5
- open_collective: # Replace with a single Open Collective username
6
- ko_fi: # Replace with a single Ko-fi username
7
- tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8
- community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9
- liberapay: # Replace with a single Liberapay username
10
- issuehunt: # Replace with a single IssueHunt username
11
- otechie: # Replace with a single Otechie username
12
- custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
package/.prettierrc DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "printWidth": 100,
3
- "tabWidth": 2,
4
- "singleQuote": true,
5
- "trailingComma": "all",
6
- "semi": false,
7
- "bracketSpacing": true,
8
- "quoteProps": "consistent"
9
- }
@@ -1,47 +0,0 @@
1
- {
2
- "editor.formatOnSave": true,
3
- "editor.defaultFormatter": "esbenp.prettier-vscode",
4
- "[javascript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
5
- "[typescript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
6
- "[vue]": {
7
- // octref.vetur is to be enabled after this is released:
8
- // https://github.com/vuejs/vetur/issues/1925
9
- // "editor.defaultFormatter": "octref.vetur"
10
- "editor.defaultFormatter": "esbenp.prettier-vscode"
11
- },
12
- "[sass]": { "editor.defaultFormatter": "syler.sass-indented" },
13
- // make sure vetur is enabled
14
- "eslint.validate": ["javascript", "javascriptreact", "typescript", "vue"],
15
- "vetur.experimental.templateInterpolationService": true,
16
- "vetur.format.enable": true,
17
- "vetur.validation.style": true,
18
- "vetur.validation.template": true,
19
- "vetur.validation.script": true,
20
- // disable conflicting formatting
21
- "javascript.validate.enable": true,
22
- "typescript.format.enable": true,
23
- "standard.enable": false,
24
- // global important defaults
25
- "editor.tabSize": 2, // make sure this is the same as .prettierrc
26
- "editor.insertSpaces": true,
27
- "files.trimFinalNewlines": true,
28
- "files.trimTrailingWhitespace": true,
29
- // script
30
- "vetur.format.defaultFormatter.ts": "prettier",
31
- "vetur.format.defaultFormatter.js": "prettier",
32
- // stylus
33
- "vetur.format.defaultFormatter.stylus": "stylus-supremacy",
34
- "stylusSupremacy.insertColons": true,
35
- "stylusSupremacy.insertBraces": false,
36
- "stylusSupremacy.insertSemicolons": false,
37
- "languageStylus.useSeparator": true,
38
- // sass
39
- "vetur.format.defaultFormatter.sass": "sass-formatter",
40
- "sass.format.debug": false,
41
- "sass.format.deleteEmptyRows": true,
42
- "sass.format.deleteWhitespace": true,
43
- "sass.format.convert": true,
44
- "sass.format.setPropertySpace": true,
45
- // typescript
46
- "typescript.tsdk": "node_modules/typescript/lib"
47
- }
package/build.js DELETED
@@ -1,57 +0,0 @@
1
- /* eslint-disable */
2
-
3
- // npm install rollup-plugin-typescript2 typescript --save-dev
4
- import typescript from 'rollup-plugin-typescript2'
5
-
6
- // ------------------------------------------------------------------------------------------
7
- // formats
8
- // ------------------------------------------------------------------------------------------
9
- // amd – Asynchronous Module Definition, used with module loaders like RequireJS
10
- // cjs – CommonJS, suitable for Node and Browserify/Webpack
11
- // esm – Keep the bundle as an ES module file
12
- // iife – A self-executing function, suitable for inclusion as a <script> tag. (If you want to create a bundle for your application, you probably want to use this, because it leads to smaller file sizes.)
13
- // umd – Universal Module Definition, works as amd, cjs and iife all in one
14
- // system – Native format of the SystemJS loader
15
-
16
- // ------------------------------------------------------------------------------------------
17
- // setup
18
- // ------------------------------------------------------------------------------------------
19
- const pkg = require('./package.json')
20
- const name = pkg.name
21
- const className = name.replace(/(^\w|-\w)/g, c => c.replace('-', '').toUpperCase())
22
- const external = Object.keys(pkg.dependencies || [])
23
- const plugins = [
24
- typescript({ useTsconfigDeclarationDir: true, tsconfigOverride: { exclude: ['test/**/*'] } }),
25
- ]
26
-
27
- // ------------------------------------------------------------------------------------------
28
- // Builds
29
- // ------------------------------------------------------------------------------------------
30
- function defaults (config) {
31
- // defaults
32
- const defaults = {
33
- plugins,
34
- external,
35
- }
36
- // defaults.output
37
- config.output = config.output.map(output => {
38
- return Object.assign(
39
- {
40
- sourcemap: false,
41
- name: className,
42
- },
43
- output
44
- )
45
- })
46
- return Object.assign(defaults, config)
47
- }
48
-
49
- export default [
50
- defaults({
51
- input: 'src/index.ts',
52
- output: [
53
- { file: 'dist/index.cjs.js', format: 'cjs' },
54
- { file: 'dist/index.esm.js', format: 'esm' },
55
- ],
56
- }),
57
- ]
@@ -1,9 +0,0 @@
1
- /**
2
- * Generates a non-safe random string which can have duplicates around 7 million generations.
3
- */
4
- export function randomString(length = 20): string {
5
- return Array(length)
6
- .fill(0)
7
- .map(() => Math.random().toString(36).charAt(2))
8
- .join('')
9
- }
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './lib/getLineLogin'
2
- export * from './lib/getParamsFromLoginCallback'
@@ -1,72 +0,0 @@
1
- import { randomString } from '../helpers/randomString'
2
-
3
- /**
4
- * https://developers.line.biz/en/docs/line-login/integrate-line-login/#making-an-authorization-request
5
- */
6
- export type LineLoginUrlParams = {
7
- /**
8
- * (Optional - default 'code') code. This tells the LINE Platform to return an authorization code.
9
- */
10
- response_type?: string
11
- /**
12
- * (Required) Channel ID. Unique identifier for your channel issued by LINE.
13
- */
14
- client_id: string
15
- /**
16
- * (Required) Callback URL. URL that users are redirected to after authentication and authorization. Must match one of the the callback URLs registered for your channel in the console.
17
- */
18
- redirect_uri: string
19
- /**
20
- * (Optional - default to a random string) A unique alphanumeric string used to prevent cross-site request forgery. This value should be randomly generated by your application. Cannot be a URL-encoded string.
21
- */
22
- state?: string
23
- /**
24
- * (Optional - default 'openid') Permissions requested to the user. For more information, see scopes.
25
- * To obtain the email address of a user, you must first apply for permission.
26
- * An access token with the profile scope is required to get the friendship status between a user and a LINE Official Account.
27
- */
28
- scope?: 'profile' | 'profile%20openid' | 'profile%20openid%20email' | 'openid' | 'openid%20email'
29
- /**
30
- * (Optional) A string used to prevent replay attacks. This value is returned in an ID token.
31
- */
32
- nonce?: string
33
- /**
34
- * (Optional) consent. Used to force the consent screen to be displayed even if the user has already granted all requested permissions.
35
- */
36
- prompt?: string
37
- /**
38
- * (Optional) The allowable elapsed time in seconds since the last time the user was authenticated. Corresponds to the max_age parameter defined in the "Authentication Request" section of OpenID Connect Core 1.0.
39
- */
40
- max_age?: number
41
- /**
42
- * (Optional) Display language for LINE Login screens. Specify as one or more RFC 5646 (BCP 47) language tags, separated by spaces, in order of preference. Corresponds to the ui_locales parameter defined in the "Authentication Request" section of OpenID Connect Core 1.0.
43
- */
44
- ui_locales?: string
45
- /**
46
- * (Optional) Displays an option to add a LINE Official Account as a friend during login. Set to either normal or aggressive. For more information, see Add a LINE Official Account as a friend when logged in (bot link).
47
- */
48
- bot_prompt?: string
49
- }
50
-
51
- /**
52
- * Get a URL that users can access to login with LINE and be redirected to your app again.
53
- *
54
- * LINE documentation: https://developers.line.biz/en/docs/line-login/integrate-line-login/#making-an-authorization-request
55
- *
56
- * @param {LineLoginUrlParams} params Only client_id & redirect_uri are required props.
57
- * @returns {string} the `https://access.line.me/oauth2/v2.1/authorize${query}` URL with correct query
58
- */
59
- export function getLineLoginUrl(params: LineLoginUrlParams): string {
60
- const {
61
- response_type = 'code',
62
- state = randomString(),
63
- scope = 'openid',
64
- redirect_uri: _redirect_uri,
65
- } = params
66
- const redirect_uri = _redirect_uri.replace(/:/g, '%3A').replace(/\//g, '%2F')
67
- const paramsObject = { ...params, response_type, redirect_uri, state, scope }
68
- const query = Object.entries(paramsObject)
69
- .map((entry) => entry.join('='))
70
- .join('&')
71
- return `https://access.line.me/oauth2/v2.1/authorize?${query}`
72
- }
@@ -1,49 +0,0 @@
1
- export type LoginCallbackParamsSuccess = {
2
- /**
3
- * Authorization code used to get an access token. Valid for 10 minutes. This authorization code can only be used once.
4
- */
5
- code: string
6
- /**
7
- * state parameter included in the authorization URL of original request. Your application should verify that this value matches the one in the original request.
8
- */
9
- state: string
10
- /**
11
- * true if the friendship status between the user and the LINE Official Account changes during login. Otherwise, the value is false. This parameter is only returned if the bot_prompt query parameter is specified when making an authorization request and the option to add your LINE Official Account as a friend when the user logged in is displayed. For more information, see Add a LINE Official Account as a friend when logged in (bot link).
12
- */
13
- friendship_status_changed?: boolean
14
- }
15
-
16
- export type LoginCallbackParamsError = {
17
- /**
18
- * (Optional) Error code.
19
- */
20
- error: 'access_denied' | string
21
- /**
22
- * (Optional) Details of the error.
23
- */
24
- error_description?: string
25
- /**
26
- * (Optional) OAuth 2.0 state value. Required if the authorization Request included the state parameter.
27
- */
28
- state?: string
29
- }
30
-
31
- /**
32
- * Once the user is authenticated and authorization is complete, the HTTP status code 302 and query parameters are returned in the callback URL. This function converts the callback URL to an object with the query parameters.
33
- *
34
- * @param {string} callbackUrlTriggered eg. https://client.example.org/cb?code=abcd1234&state=0987poi&friendship_status_changed=true
35
- * @returns {LoginCallbackParamsSuccess | LoginCallbackParamsError}
36
- * @example // Success example:
37
- HTTP/1.1 302 Found
38
- Location: https://client.example.org/cb?code=abcd1234&state=0987poi&friendship_status_changed=true
39
- * @example // Error example:
40
- Location: https://example.com/callback?error=access_denied&error_description=The+resource+owner+denied+the+request.&state=0987poi
41
- */
42
- export function getParamsFromLoginCallback(
43
- callbackUrlTriggered: string,
44
- ): LoginCallbackParamsSuccess | LoginCallbackParamsError {
45
- const query = callbackUrlTriggered.split('?')[1]
46
- const queryEntries = query.split('&').map((q) => q.split('='))
47
- const queryObject = Object.fromEntries(queryEntries)
48
- return queryObject
49
- }
package/tsconfig.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "baseUrl": ".",
4
- "outDir": "./dist",
5
- "declaration": true,
6
- "declarationDir": "./types/",
7
- "target": "ES2015",
8
- "lib": ["ES2015", "ES2016", "ES2017", "ES2018", "ES2019", "ES2020"]
9
- },
10
- "include": ["src/**/*", "test/**/*"]
11
- }
@@ -1,2 +0,0 @@
1
- export * from './getLineLogin';
2
- export * from './getParamsFromLoginCallback';
@@ -1,63 +0,0 @@
1
- export declare type DecodedIdToken = {
2
- header: {
3
- typ: 'JWT';
4
- alg: 'HS256';
5
- };
6
- payload: {
7
- /**
8
- * https://access.line.me. URL where the ID token is generated.
9
- */
10
- iss: 'https://access.line.me' | string;
11
- /**
12
- * User ID for which the ID token is generated
13
- */
14
- sub: string;
15
- /**
16
- * Channel ID
17
- */
18
- aud: string;
19
- /**
20
- * The expiry date of the token in UNIX time.
21
- */
22
- exp: number;
23
- /**
24
- * Time when the ID token was generated in UNIX time.
25
- */
26
- iat: number;
27
- /**
28
- * (Optional) Time when the user was authenticated in UNIX time. Not included if the max_age parameter wasn't specified in the authorization request.
29
- */
30
- auth_time?: number;
31
- /**
32
- * (Optional) The nonce value specified in the authorization URL. Not included if the nonce value was not specified in the authorization request.
33
- */
34
- nonce?: string;
35
- /**
36
- * List of authentication methods used by the user. For each authentication method, see Authentication process. One of:
37
- * pwd: Log in with email and password
38
- * lineautologin: LINE automatic login (including through LINE SDK)
39
- * lineqr: Log in with QR code
40
- * linesso: Log in with single sign-on
41
- */
42
- amr: ('pwd' | 'lineautologin' | 'lineqr' | 'linesso' | 'name')[];
43
- /**
44
- * User's display name. Not included if the profile scope was not specified in the authorization request.
45
- */
46
- name: string;
47
- /**
48
- * (Optional) User's profile image URL. Not included if the profile scope was not specified in the authorization request.
49
- */
50
- picture?: string;
51
- /**
52
- * (Optional) User's email address. Not included if the email scope was not specified in the authorization request.
53
- */
54
- email?: string;
55
- };
56
- signature: string;
57
- };
58
- /**
59
- * (Node only) Returns a decoded LINE id token. Uses the nodeJS 'jsonwebtoken' dependency.
60
- * This id Token should be validated!
61
- * LINE documentation: https://developers.line.biz/en/docs/line-login/integrate-line-login/#decode-and-validate-id-token
62
- */
63
- export declare function decodeIdToken(idToken: string): DecodedIdToken;
@@ -1,2 +0,0 @@
1
- export * from './issueAccessToken';
2
- export * from './decodeIdToken';
@@ -1,65 +0,0 @@
1
- export declare type IssueAccessTokenParams = {
2
- /**
3
- * (Optional - default: 'authorization_code') authorization_code. Specifies the grant type.
4
- */
5
- grant_type?: string;
6
- /**
7
- * (Required) Authorization code. Code returned in the authorization request.
8
- */
9
- code: string;
10
- /**
11
- * (Required) Callback URL. Must match one of the the callback URLs registered for your channel in the console.
12
- */
13
- redirect_uri: string;
14
- /**
15
- * (Required) Channel ID. Found in the console.
16
- */
17
- client_id: string;
18
- /**
19
- * (Required) Channel secret. Found in the console.
20
- */
21
- client_secret: string;
22
- };
23
- /**
24
- * The LINE Platform validates the request and returns an access token and other data as shown in the table below.
25
- *
26
- * New or changed LINE Login functions may cause changes in the structure of the payload JSON object. These changes may include added properties, variations in property order, and added/removed white space and line breaks. Design your backend so that it can handle payload data objects with unexpected structures.
27
- *
28
- * Returns status code 200 and a JSON object with the following information.
29
- */
30
- export declare type IssueAccessTokenResponse = {
31
- /**
32
- * Access token. Valid for 30 days.
33
- */
34
- access_token: string;
35
- /**
36
- * Amount of time in seconds until the access token expires.
37
- */
38
- expires_in: number;
39
- /**
40
- * JSON Web Token (JWT) that includes information about the user. This field is returned only if openid is specified in the scope. For more information, see Verify ID token.
41
- */
42
- id_token: string;
43
- /**
44
- * Token used to get a new access token. Valid up until 90 days after the access token issued.
45
- */
46
- refresh_token: string;
47
- /**
48
- * Permissions granted by the user. However, the email scope is not returned as a value of the scope property even if the permission has been granted.
49
- */
50
- scope: string;
51
- /**
52
- * Bearer
53
- */
54
- token_type: string;
55
- };
56
- /**
57
- * (Node only) Makes a POST request to retrieve an access token from LINE. This uses GOT as a dependency to make the request.
58
- * Can throw errors.
59
- *
60
- * LINE documentation: https://developers.line.biz/en/docs/line-login/integrate-line-login/#get-access-token
61
- *
62
- * @param {IssueAccessTokenParams} params
63
- * @returns {Promise<IssueAccessTokenResponse>}
64
- */
65
- export declare function issueAccessToken(params: IssueAccessTokenParams): Promise<IssueAccessTokenResponse>;
package/types/types.d.ts DELETED
File without changes