Edits history of script submission #20966 for ' Get Technologies (their_stack)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type TheirStack = {
    	apiKey: string
    }
    /**
     * Get Technologies
     * This endpoint lets you:
    - List all the technologies we track
    - Search for any given technology. Pass a `name_pattern` parameter (case-insensitive, can be a regex pattern)
    - List the technologies within one or several categories. Pass a `category_pattern` parameter (case-insensitive, can be a regex pattern)
    
    Calls to this endpoint don't cost you credits.
     */
    export async function main(
    	auth: TheirStack,
    	name_pattern: string | undefined,
    	slug: string | undefined,
    	slugs: string | undefined,
    	category_pattern: string | undefined,
    	category_slug: string | undefined,
    	parent_category_slug: string | undefined,
    	parent_category_pattern: string | undefined,
    	page: string | undefined,
    	limit: string | undefined
    ) {
    	const url = new URL(`https://api.theirstack.com/v0/catalog/technologies`)
    	for (const [k, v] of [
    		['name_pattern', name_pattern],
    		['slug', slug],
    		['slugs', slugs],
    		['category_pattern', category_pattern],
    		['category_slug', category_slug],
    		['parent_category_slug', parent_category_slug],
    		['parent_category_pattern', parent_category_pattern],
    		['page', page],
    		['limit', limit]
    	]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			Authorization: 'Bearer ' + auth.apiKey
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 235 days ago